|
|
|
|
|
|
|
|
public function toggle(Request $request) |
|
|
public function toggle(Request $request) |
|
|
{ |
|
|
{ |
|
|
$user = $this->getUserCurrent(); |
|
|
$user = $this->getUserCurrent(); |
|
|
if($user) { |
|
|
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
|
|
|
|
if($user && $productFamily) { |
|
|
if ($user->getFavoriteProductFamilies()->contains($productFamily)) { |
|
|
if ($user->getFavoriteProductFamilies()->contains($productFamily)) { |
|
|
$user->removeFavoriteProductFamily($productFamily); |
|
|
$user->removeFavoriteProductFamily($productFamily); |
|
|
$isFavorite = false; |
|
|
$isFavorite = false; |
|
|
|
|
|
|
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return $this->_errorUserNotConnected(); |
|
|
|
|
|
|
|
|
return $this->_errorResponse(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function add(Request $request) |
|
|
public function add(Request $request) |
|
|
{ |
|
|
{ |
|
|
$user = $this->getUserCurrent(); |
|
|
$user = $this->getUserCurrent(); |
|
|
if($user) { |
|
|
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
|
|
|
|
if($user && $productFamily) { |
|
|
$user->addFavoriteProductFamily($productFamily); |
|
|
$user->addFavoriteProductFamily($productFamily); |
|
|
$this->_saveUser($user); |
|
|
$this->_saveUser($user); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return $this->_errorUserNotConnected(); |
|
|
|
|
|
|
|
|
return $this->_errorResponse(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function delete(Request $request) |
|
|
public function delete(Request $request) |
|
|
{ |
|
|
{ |
|
|
$user = $this->getUserCurrent(); |
|
|
$user = $this->getUserCurrent(); |
|
|
if($user) { |
|
|
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
|
$productFamily = $this->_getProductFamily($request); |
|
|
|
|
|
|
|
|
|
|
|
if($user && $productFamily) { |
|
|
$user->removeFavoriteProductFamily($productFamily); |
|
|
$user->removeFavoriteProductFamily($productFamily); |
|
|
$this->_saveUser($user); |
|
|
$this->_saveUser($user); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return $this->_errorUserNotConnected(); |
|
|
|
|
|
|
|
|
return $this->_errorResponse(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private function _errorUserNotConnected() |
|
|
|
|
|
|
|
|
private function _errorResponse() |
|
|
{ |
|
|
{ |
|
|
return new JsonResponse([ |
|
|
return new JsonResponse([ |
|
|
'return' => 'error', |
|
|
'return' => 'error', |
|
|
'message' => 'Vous devez être connecté pour gérer vos favoris.' |
|
|
|
|
|
|
|
|
'message' => 'Une erreur est survenue.' |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |