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.                 $arrElem['personId'] = $speaker->getPerson()->getId();
  60.                 $arrElem['userId'] = $speaker->getPerson()->getUser()->getId();
  61.                 $info['speakers'][] = $arrElem;
  62.             }
  63.             $info['participants'] = [];
  64.             if (in_array('ROLE_ADMIN'$roles) or (in_array('ROLE_SPEAKER'$roles) and $_ENV['SPEAKER_CALENDAR']  == '1') ) { 
  65.                 
  66.                 foreach ($time->getOccurrence()->getOrderItems() as $orderItem) {
  67.                     foreach ($orderItem->getParticipants() as $participant) {
  68.                         $arrElem = [];
  69.                         if ($participant->isCancelled()) {
  70.                             continue;
  71.                         }
  72.                         if ($participant->getOrderItem()->getOrder() != null){
  73.                             if ($participant->getOrderItem()->getOrder()->getStatus() == 'cancelled') {
  74.                                 continue;
  75.                             }
  76.                             if ($participant->getOrderItem()->getOrder()->getCustomer()) {
  77.                             $arrElem['customerId'] =  $participant->getOrderItem()->getOrder()->getCustomer()->getId();
  78.                             $arrElem['name'] = $participant->getFullname();
  79.                             $info['participants'][] = $arrElem;
  80.                             }
  81.                         }
  82.                     }
  83.                 }
  84.             }
  85.             $options = [];
  86.             $options['extendedProps'] = $info;
  87.             $calendar->addEvent(new Event(
  88.                 $time->getOccurrence()->getCourse()->getTitle(),
  89.                 $time->getStart(),
  90.                 $time->getEnd(),
  91.                 null,
  92.                 $options
  93.             ));
  94.         }
  95.     }
  96. }