EventController.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Muzich\UserBundle\Controller;
  3. use Muzich\CoreBundle\lib\Controller;
  4. class EventController extends Controller
  5. {
  6. public function infoBarAction()
  7. {
  8. $events = $this->getDoctrine()->getRepository('MuzichCoreBundle:Event')
  9. ->getEvents($this->getUserId())
  10. ;
  11. return $this->render('MuzichUserBundle:Info:bar.html.twig', array(
  12. 'events' => $events
  13. ));
  14. }
  15. public function viewElementsAction($event_id)
  16. {
  17. if (($response = $this->mustBeConnected()))
  18. {
  19. return $response;
  20. }
  21. if (!($event = $this->getDoctrine()->getRepository('MuzichCoreBundle:Event')
  22. ->findOneById($event_id)))
  23. {
  24. if ($this->getRequest()->isXmlHttpRequest())
  25. {
  26. return $this->jsonResponse(array(
  27. 'status' => 'error',
  28. 'errors' => array('NotFound')
  29. ));
  30. }
  31. throw $this->createNotFoundException('Ressource ajax uniquement.');
  32. }
  33. if ($event->getUser()->getId() != $this->getUserId())
  34. {
  35. if ($this->getRequest()->isXmlHttpRequest())
  36. {
  37. return $this->jsonResponse(array(
  38. 'status' => 'error',
  39. 'errors' => array('NotAllowed')
  40. ));
  41. }
  42. throw $this->createNotFoundException('Ressource ajax uniquement.');
  43. }
  44. // A partir d'ici on a ce qu'il faut.
  45. // On modifie l'Element Searcher en lui donnat les ids correspondant a l'event
  46. $es = $this->getElementSearcher();
  47. $es->setIds($event->getIds());
  48. $es->setIdsDisplay($event->getType());
  49. $this->setElementSearcherParams($es->getParams());
  50. $this->getDoctrine()->getEntityManager()->remove($event);
  51. $this->getDoctrine()->getEntityManager()->flush();
  52. // Si ajax
  53. if ($this->getRequest()->isXmlHttpRequest())
  54. {
  55. $html = $this->render('MuzichCoreBundle:SearchElement:default.html.twig', array(
  56. 'user' => $this->getUser(),
  57. 'elements' => $es->getElements($this->getDoctrine(), $this->getUserId()),
  58. 'invertcolor' => false
  59. ))->getContent();
  60. return $this->jsonResponse(array(
  61. 'status' => 'success',
  62. 'html' => $html
  63. ));
  64. }
  65. // Sinon on redirige vers home
  66. return $this->redirect($this->generateUrl('home'));
  67. }
  68. }