src/EventListener/CalendarSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Repository\CourseOccurrenceTimeRepository;
  4. use CalendarBundle\CalendarEvents;
  5. use CalendarBundle\Entity\Event;
  6. use CalendarBundle\Event\CalendarEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. class CalendarSubscriber implements EventSubscriberInterface
  10. {
  11.     private $cotRepo;
  12.     private $security;
  13.     public function __construct(CourseOccurrenceTimeRepository $cotRepoSecurity $security)
  14.     {
  15.         $this->cotRepo $cotRepo;
  16.         $this->security $security;
  17.     }
  18.     /**
  19.      * @return array
  20.      */
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return [
  24.             CalendarEvents::SET_DATA => 'onCalendarSetData',
  25.         ];
  26.     }
  27.     /**
  28.      * @return void
  29.      */
  30.     public function onCalendarSetData(CalendarEvent $calendar)
  31.     {
  32.         $filters $calendar->getFilters();
  33.         $filters['start'] = $calendar->getStart();
  34.         $filters['end'] = $calendar->getEnd();
  35.         $times $this->cotRepo->getTimesByFilter($filters);
  36.         $roles $this->security->getUser()->getRoles();
  37.         $seekSpeaker = (in_array('ROLE_SPEAKER'$roles)) ? $this->security->getUser()->getId() : null;
  38.         //  $speakerid = $this->security->getUser()->getId();
  39.         foreach ($times as $time) {
  40.             $info = [];
  41.             $info['courseId'] = $time->getOccurrence()->getCourse()->getId();
  42.             $info['title'] = $time->getOccurrence()->getCourse()->getTitle();
  43.             $info['occurrenceId'] = $time->getOccurrence()->getId();
  44.             $info['venue'] = (null !== $time->getOccurrence()->getVenue()) ? $time->getOccurrence()->getVenue()->getName() : null;
  45.             $info['venueId'] = (null !== $time->getOccurrence()->getVenue()) ? $time->getOccurrence()->getVenue()->getId() : null;
  46.             $info['room'] = (null !== $time->getOccurrence()->getVenueRoom()) ? $time->getOccurrence()->getVenueRoom()->getName() : null;
  47.             $info['speakers'] = [];
  48.             $info['slots'] = $time->getOccurrence()->getSlots();
  49.             $info['bookedSlots'] = $time->getOccurrence()->getBookedSlots();
  50.             $foundSpeaker false;
  51.             foreach ($time->getOccurrence()->getSpeakers() as $speaker) {
  52.                 if ($seekSpeaker and !$foundSpeaker and $speaker->getPerson()->getUser()->getId() == $seekSpeaker) {
  53.                     $foundSpeaker true;
  54.                 }
  55.                 $arrElem = [];
  56.                 $arrElem['id'] = $speaker->getId();
  57.                 $arrElem['name'] = 'Referent: '.$speaker->getFullname();
  58.                 $arrElem['personId'] = $speaker->getPerson()->getId();
  59.                 $arrElem['userId'] = $speaker->getPerson()->getUser()->getId();
  60.                 $info['speakers'][] = $arrElem;
  61.             }
  62.             $info['participants'] = [];
  63.             if (in_array('ROLE_ADMIN'$roles) or in_array('ROLE_SUPER_USER'$roles) or (in_array('ROLE_SPEAKER'$roles) and '1' == $_ENV['SPEAKER_CALENDAR'])) {
  64.                 foreach ($time->getOccurrence()->getOrderItems() as $orderItem) {
  65.                     foreach ($orderItem->getParticipants() as $participant) {
  66.                         $arrElem = [];
  67.                         if ($participant->isCancelled()) {
  68.                             continue;
  69.                         }
  70.                         if (null != $participant->getOrderItem()->getOrder()) {
  71.                             if ('cancelled' == $participant->getOrderItem()->getOrder()->getStatus()) {
  72.                                 continue;
  73.                             }
  74.                             if ($participant->getOrderItem()->getOrder()->getCustomer()) {
  75.                                 $arrElem['customerId'] = $participant->getOrderItem()->getOrder()->getCustomer()->getId();
  76.                                 $arrElem['name'] = $participant->getFullname();
  77.                                 $info['participants'][] = $arrElem;
  78.                             }
  79.                         }
  80.                     }
  81.                 }
  82.             }
  83.             $options = [];
  84.             $options['extendedProps'] = $info;
  85.             $calendar->addEvent(new Event(
  86.                 $time->getOccurrence()->getCourse()->getTitle(),
  87.                 $time->getStart(),
  88.                 $time->getEnd(),
  89.                 null,
  90.                 $options
  91.             ));
  92.         }
  93.     }
  94. }