|
|
@@ -4,6 +4,7 @@ namespace Muzich\FavoriteBundle\Controller;
|
|
4
|
4
|
|
|
5
|
5
|
use Muzich\CoreBundle\lib\Controller;
|
|
6
|
6
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
|
|
7
|
+use Muzich\CoreBundle\Entity\UsersElementsFavorites;
|
|
7
|
8
|
//use Muzich\CoreBundle\Entity\Group;
|
|
8
|
9
|
//use Muzich\CoreBundle\Form\Group\GroupForm;
|
|
9
|
10
|
//use Symfony\Component\HttpFoundation\Request;
|
|
|
@@ -12,6 +13,45 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
|
12
|
13
|
class FavoriteController extends Controller
|
|
13
|
14
|
{
|
|
14
|
15
|
|
|
15
|
|
-
|
|
|
16
|
+ /**
|
|
|
17
|
+ * Ajoute comme favoris l'element en id
|
|
|
18
|
+ *
|
|
|
19
|
+ * @param int $id
|
|
|
20
|
+ * @param string $token
|
|
|
21
|
+ */
|
|
|
22
|
+ public function addAction($id, $token)
|
|
|
23
|
+ {
|
|
|
24
|
+ $user = $this->getUser();
|
|
|
25
|
+ $em = $this->getDoctrine()->getEntityManager();
|
|
|
26
|
+
|
|
|
27
|
+ if ($user->getPersonalHash() != $token || !is_numeric($id)
|
|
|
28
|
+ || !($element = $em->getRepository('MuzichCoreBundle:Element')->findOneById($id))
|
|
|
29
|
+ )
|
|
|
30
|
+ {
|
|
|
31
|
+ throw $this->createNotFoundException();
|
|
|
32
|
+ }
|
|
|
33
|
+
|
|
|
34
|
+ if (!$em->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
|
|
35
|
+ ->findOneBy(array(
|
|
|
36
|
+ 'user' => $user->getId(),
|
|
|
37
|
+ 'element' => $id
|
|
|
38
|
+ )))
|
|
|
39
|
+ {
|
|
|
40
|
+ $favorite = new UsersElementsFavorites();
|
|
|
41
|
+ $favorite->setUser($user);
|
|
|
42
|
+ $favorite->setElement($element);
|
|
|
43
|
+ $em->persist($favorite);
|
|
|
44
|
+ $em->flush();
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ if ($this->getRequest()->isXmlHttpRequest())
|
|
|
48
|
+ {
|
|
|
49
|
+
|
|
|
50
|
+ }
|
|
|
51
|
+ else
|
|
|
52
|
+ {
|
|
|
53
|
+ return $this->redirect($this->container->get('request')->headers->get('referer'));
|
|
|
54
|
+ }
|
|
|
55
|
+ }
|
|
16
|
56
|
|
|
17
|
57
|
}
|