MynetworkController.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Muzich\MynetworkBundle\Controller;
  3. use Muzich\CoreBundle\lib\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  5. use Muzich\CoreBundle\Searcher\UserAndGroupSearcher;
  6. class MynetworkController extends Controller
  7. {
  8. /**
  9. * Page listant les personnes et groupes que l'on suit, ainsi que les
  10. * personnes qui nous duivent.
  11. *
  12. * @Template()
  13. */
  14. public function indexAction($event_id)
  15. {
  16. $user = $this->getUser(true, array('join' => array(
  17. 'followers_users'//, 'followeds_users', 'followeds_groups'
  18. )));
  19. //$followeds_users = $user->getFollowedsUsers();
  20. //$followeds_groups = $user->getFollowedGroups();
  21. $followers_users = $user->getFollowersUsers();
  22. if ($event_id)
  23. {
  24. if (!($event = $this->getDoctrine()->getRepository('MuzichCoreBundle:Event')
  25. ->findOneById($event_id)))
  26. {
  27. return $this->redirect($this->generateUrl('mynetwork_index'));
  28. }
  29. if ($event->getUser()->getId() != $this->getUserId())
  30. {
  31. throw $this->createNotFoundException();
  32. }
  33. $followers_users = $this->proceedForEvent($event, $followers_users, $event_id);
  34. }
  35. return array(
  36. //'followeds_users' => $followeds_users,
  37. //'followeds_groups' => $followeds_groups,
  38. 'followers_users' => $followers_users
  39. );
  40. }
  41. private function proceedForEvent($event, $followers_users, $event_id)
  42. {
  43. $ids = $event->getIds();
  44. $this->getDoctrine()->getManager()->remove($event);
  45. $this->getDoctrine()->getManager()->flush();
  46. $followers_users_new = array();
  47. foreach ($followers_users as $user)
  48. {
  49. if (in_array($user->getId(), $ids))
  50. {
  51. $followers_users_new[] = $user;
  52. }
  53. }
  54. return $followers_users_new;
  55. }
  56. }