|
@@ -3,9 +3,10 @@
|
3
|
3
|
namespace Muzich\CoreBundle\Controller;
|
4
|
4
|
|
5
|
5
|
use Muzich\CoreBundle\lib\Controller;
|
6
|
|
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
|
6
|
+//use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
7
|
7
|
use Muzich\CoreBundle\Entity\FollowUser;
|
8
|
|
-use Doctrine\ORM\Query;
|
|
8
|
+use Muzich\CoreBundle\Entity\FollowGroup;
|
|
9
|
+//use Doctrine\ORM\Query;
|
9
|
10
|
|
10
|
11
|
class CoreController extends Controller
|
11
|
12
|
{
|
|
@@ -26,7 +27,7 @@ class CoreController extends Controller
|
26
|
27
|
}
|
27
|
28
|
|
28
|
29
|
$em = $this->getDoctrine()->getEntityManager();
|
29
|
|
- $FollowUser = $em
|
|
30
|
+ $Follow = $em
|
30
|
31
|
->getRepository('MuzichCoreBundle:Follow' . ucfirst($type))
|
31
|
32
|
->findOneBy(
|
32
|
33
|
array(
|
|
@@ -36,25 +37,29 @@ class CoreController extends Controller
|
36
|
37
|
)
|
37
|
38
|
;
|
38
|
39
|
|
39
|
|
- if ($FollowUser)
|
|
40
|
+ if ($Follow)
|
40
|
41
|
{
|
41
|
42
|
// L'utilisateur suis déjà, on doit détruire l'entité
|
42
|
|
- $em->remove($FollowUser);
|
|
43
|
+ $em->remove($Follow);
|
43
|
44
|
$em->flush();
|
44
|
45
|
}
|
45
|
46
|
else
|
46
|
47
|
{
|
47
|
|
- $followed_user = $em->getRepository('MuzichCoreBundle:User')->find($id);
|
|
48
|
+ $followed = $em->getRepository('MuzichCoreBundle:'.ucfirst($type))->find($id);
|
48
|
49
|
|
49
|
|
- if (!$followed_user) {
|
50
|
|
- throw $this->createNotFoundException('No user found for id '.$id);
|
|
50
|
+ if (!$followed) {
|
|
51
|
+ throw $this->createNotFoundException('No '.$type.' found for id '.$id);
|
51
|
52
|
}
|
52
|
53
|
|
53
|
|
- $FollowUser = new FollowUser();
|
54
|
|
- $FollowUser->setFollowed($followed_user);
|
55
|
|
- $FollowUser->setFollower($user);
|
56
|
54
|
|
57
|
|
- $em->persist($FollowUser);
|
|
55
|
+ if ($type == 'user') { $Follow = new FollowUser(); }
|
|
56
|
+ else { $Follow = new FollowGroup(); }
|
|
57
|
+ $Follow->setFollower($user);
|
|
58
|
+ if ($type == 'user') { $Follow->setFollowed($followed); }
|
|
59
|
+ else { $Follow->setGroup($followed); }
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+ $em->persist($Follow);
|
58
|
63
|
$em->flush();
|
59
|
64
|
}
|
60
|
65
|
|