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.        
  40.         foreach ($times as $time) {
  41.             $info = [];
  42.             $info['courseId'] = $time->getOccurrence()->getCourse()->getId();
  43.             $info['title'] = $time->getOccurrence()->getCourse()->getTitle();
  44.             $info['occurrenceId'] = $time->getOccurrence()->getId();
  45.             $info['venue'] = ($time->getOccurrence()->getVenue() !== null) ? $time->getOccurrence()->getVenue()->getName() : null;
  46.             $info['venueId'] = ($time->getOccurrence()->getVenue() !== null) ? $time->getOccurrence()->getVenue()->getId() : null;
  47.             $info['room'] = ($time->getOccurrence()->getVenueRoom() !== null) ? $time->getOccurrence()->getVenueRoom()->getName() : null;
  48.             $info['speakers'] = [];
  49.         $info['slots'] = $time->getOccurrence()->getSlots();
  50.             $info['bookedSlots'] = $time->getOccurrence()->getBookedSlots();
  51.             $foundSpeaker false;
  52.             foreach ($time->getOccurrence()->getSpeakers() as $speaker) {
  53.                 if ($seekSpeaker and !$foundSpeaker and $speaker->getPerson()->getUser()->getId() == $seekSpeaker) {
  54.                     $foundSpeaker true;
  55.                 }
  56.                 $arrElem = [];
  57.                 $arrElem['id'] = $speaker->getId();
  58.                 $arrElem['name'] = 'Referent: ' .$speaker->getFullname() ;
  59.                 $info['speakers'][] = $arrElem;
  60.             }
  61.             $info['participants'] = [];
  62.             if (in_array('ROLE_ADMIN'$roles) or (in_array('ROLE_SPEAKER'$roles) and $_ENV['SPEAKER_CALENDAR']  == '1') ) { 
  63.                 
  64.                 foreach ($time->getOccurrence()->getOrderItems() as $orderItem) {
  65.                     foreach ($orderItem->getParticipants() as $participant) {
  66.                         $arrElem = [];
  67.                         if ($participant->isCancelled()) {
  68.                             continue;
  69.                         }
  70.                         if ($participant->getOrderItem()->getOrder()->getStatus() == 'cancelled') {
  71.                             continue;
  72.                         }
  73.                         if ($participant->getOrderItem()->getOrder()->getCustomer()) {
  74.                         $arrElem['customerId'] =  $participant->getOrderItem()->getOrder()->getCustomer()->getId();
  75.                         $arrElem['name'] = $participant->getFullname();
  76.                         $info['participants'][] = $arrElem;
  77.                         }
  78.                     }
  79.                 }
  80.             }
  81.             $options = [];
  82.             $options['extendedProps'] = $info;
  83.             $calendar->addEvent(new Event(
  84.                 $time->getOccurrence()->getCourse()->getTitle(),
  85.                 $time->getStart(),
  86.                 $time->getEnd(),
  87.                 null,
  88.                 $options
  89.             ));
  90.         }
  91.     }
  92. }