Beispiel #1
0
 public function testGetEndIndex()
 {
     $item = new DiaryItem();
     $item->setStartIndex(1);
     $item->setNumberOfDays(4);
     $this->assertEquals(4, $item->getEndIndex());
 }
Beispiel #2
0
 public function addEvent(EventInterface $event)
 {
     $item = new DiaryItem();
     $item->setEvent($event);
     $item->setStartAt($event->getStartTime());
     $item->setEndAt($event->getEndTime());
     if ($event instanceof SingleDayEventInterface) {
         $item->setNumberOfDays(1);
         $item->setStartIndex($this->calculateIndex($event->getDate()));
         $this->addItem($item);
     } elseif ($event instanceof MultiDayEventInterface) {
         if ($event->getStartDate() < $event->getExcludeDate() && $event->getExcludeDate() < $event->getEndDate()) {
             $start_index = $this->calculateIndex($event->getStartDate());
             $end_index = $this->calculateIndex($event->getExcludeDate());
             $item->setStartIndex($start_index);
             $item->setNumberOfDays($end_index - $start_index);
             $this->addItem($item);
             $item2 = clone $item;
             $start_index = $this->calculateIndex($event->getExcludeDate());
             $end_index = $this->calculateIndex($event->getEndDate());
             $item2->setStartIndex($start_index + 1);
             $item2->setNumberOfDays($end_index - $start_index);
             $this->addItem($item2);
         } else {
             $start_index = $this->calculateIndex($event->getStartDate());
             $end_index = $this->calculateIndex($event->getEndDate());
             $numberOfDays = $end_index - $start_index + 1;
             if ($numberOfDays > 0) {
                 $item->setStartIndex($start_index);
                 $item->setNumberOfDays($end_index - $start_index + 1);
                 $this->addItem($item);
             }
         }
     }
 }