Пример #1
0
 /**
  * Add an event to the DiaryView. Works out the week(s) to which the event should be added. Multi-day events
  * may need to be added to multiple weeks if they cross a week boundary.
  *
  * @param EventInterface $event
  */
 public function addEvent(EventInterface $event)
 {
     if ($event instanceof MultiDayEventInterface) {
         //If it's a multi-day event, we may well need to display it in multiple weeks
         $week_start = Week::getWeekStart($event->getStartDate());
         do {
             $week = $this->getWeekForDate($week_start);
             if ($week) {
                 $week->addEvent($event);
             }
             $week_start->modify('+7 days');
         } while ($week_start < $event->getEndDate());
     } elseif ($event instanceof SingleDayEventInterface) {
         $this->getWeekForDate($event->getDate())->addEvent($event);
         //If its end time is before its start time, we assume this means it continues until that time the next day
         if ($event->getEndTime() < $event->getStartTime() && $event->getDate()->format('N') == 6) {
             $tomorrow = $event->getDate()->modify('+1 day');
             $week = $this->getWeekForDate($tomorrow);
             if ($week) {
                 $week->addEvent($event);
             }
         }
     }
 }
Пример #2
0
 /**
  * @param EventInterface $event
  *
  * @return bool
  */
 public function canAccept(EventInterface $event)
 {
     //First check if the time is the same (within a certain threshold)
     $earliest = clone $this->start;
     $earliest->modify('-' . (self::MAX_ROW_RANGE_MINUTES + 1) . ' minutes');
     $latest = clone $this->start;
     $latest->modify('+' . (self::MAX_ROW_RANGE_MINUTES + 1) . ' minutes');
     if ($event->getStartTime() <= $earliest || $event->getStartTime() >= $latest) {
         return false;
     }
     //Now see if there's space in the row
     if ($event instanceof SingleDayEventInterface) {
         $index = $this->calculateIndex($event->getDate());
         return $this->rangeIsFree($index, $index);
     } elseif ($event instanceof MultiDayEventInterface) {
         $start_index = $this->calculateIndex($event->getStartDate());
         $end_index = $this->calculateIndex($event->getEndDate());
         return $this->rangeIsFree($start_index, $end_index);
     }
 }
Пример #3
0
 protected function createRow(EventInterface $event)
 {
     return new DiaryRow($event->getStartTime(), $this->getStartAt());
 }