|
@@ -71,6 +71,45 @@ class FavoriteController extends Controller
|
71
|
71
|
}
|
72
|
72
|
|
73
|
73
|
/**
|
|
74
|
+ * Retire comme favoris l'element en id
|
|
75
|
+ *
|
|
76
|
+ * @param int $id
|
|
77
|
+ * @param string $token
|
|
78
|
+ */
|
|
79
|
+ public function removeAction($id, $token)
|
|
80
|
+ {
|
|
81
|
+ $user = $this->getUser();
|
|
82
|
+ $em = $this->getDoctrine()->getEntityManager();
|
|
83
|
+
|
|
84
|
+ if ($user->getPersonalHash() != $token || !is_numeric($id)
|
|
85
|
+ || !($element = $em->getRepository('MuzichCoreBundle:Element')->findOneById($id))
|
|
86
|
+ )
|
|
87
|
+ {
|
|
88
|
+ throw $this->createNotFoundException();
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ // Si l'élément est déjà en favoris, ce qui est cencé être le cas
|
|
92
|
+ if (($fav = $em->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
|
93
|
+ ->findOneBy(array(
|
|
94
|
+ 'user' => $user->getId(),
|
|
95
|
+ 'element' => $id
|
|
96
|
+ ))))
|
|
97
|
+ {
|
|
98
|
+ $em->remove($fav);
|
|
99
|
+ $em->flush();
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
103
|
+ {
|
|
104
|
+
|
|
105
|
+ }
|
|
106
|
+ else
|
|
107
|
+ {
|
|
108
|
+ return $this->redirect($this->container->get('request')->headers->get('referer'));
|
|
109
|
+ }
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ /**
|
74
|
113
|
* Page affichant les elements favoris de l'utilisateur
|
75
|
114
|
*
|
76
|
115
|
* @Template()
|