Example #1
0
 private function _calculateRecurrences($event, $periodStartTime, $periodEndTime)
 {
     $origPeriodStartTime = $periodStartTime;
     $origPeriodEndTime = $periodEndTime;
     //recurrences can only be calculated correctly if we use the start of the day and the end of the day.
     //we'll use the original times later to check if they really overlap.
     $periodStartTime = \GO\Base\Util\Date::clear_time($periodStartTime) - 1;
     $periodEndTime = \GO\Base\Util\Date::clear_time(\GO\Base\Util\Date::date_add($periodEndTime, 1));
     $localEvent = new LocalEvent($event, $origPeriodStartTime, $origPeriodEndTime);
     if (!$localEvent->isRepeating()) {
         $this->_calculatedEvents[$event->start_time . '-' . $event->name . '-' . $event->id] = $localEvent;
     } else {
         $rrule = new \GO\Base\Util\Icalendar\Rrule();
         try {
             $rrule->readIcalendarRruleString($localEvent->getEvent()->start_time, $localEvent->getEvent()->rrule, true);
         } catch (\Exception $e) {
             trigger_error($e->getMessage() . " Event ID:" . $event->id);
         }
         //we need to start searching for the next occurrence at the period start
         //time minus the duration of the event in days rounded up. Because an
         //occurrence may start before the period but end in it.
         $rrule->setRecurpositionStartTime(\GO\Base\Util\Date::date_add($periodStartTime, -ceil(($event->end_time - $event->start_time) / 86400)));
         //			var_dump('=====');
         //			var_dump(\GO\Base\Util\Date::get_timestamp(\GO\Base\Util\Date::date_add($periodStartTime,-ceil(( ($event->end_time-$event->start_time) /86400)))));
         $origEventAttr = $localEvent->getEvent()->getAttributes('formatted');
         while ($occurenceStartTime = $rrule->getNextRecurrence(false, $periodEndTime)) {
             //				var_dump(\GO\Base\Util\Date::get_timestamp($occurenceStartTime));
             if ($occurenceStartTime > $localEvent->getPeriodEndTime()) {
                 break;
             }
             $localEvent->setAlternateStartTime($occurenceStartTime);
             $diff = $event->getDiff();
             $endTime = new \GO\Base\Util\Date\DateTime(date('c', $occurenceStartTime));
             $endTime->add($diff);
             $localEvent->setAlternateEndTime($endTime->format('U'));
             if ($localEvent->getAlternateStartTime() < $origPeriodEndTime && $localEvent->getAlternateEndTime() > $origPeriodStartTime) {
                 if (!$event->hasException($occurenceStartTime)) {
                     $this->_calculatedEvents[$occurenceStartTime . '-' . $origEventAttr['name'] . '-' . $origEventAttr['id']] = $localEvent;
                 }
             }
             $localEvent = new LocalEvent($event, $periodStartTime, $periodEndTime);
         }
     }
     //		if (empty($event->rrule)) {
     //			//not a recurring event
     //			$this->_calculatedEvents[] = $event->getAttributes('formatted');
     //		} else {
     //			$rrule = new \GO\Base\Util\Icalendar\Rrule();
     //			$rrule->readIcalendarRruleString($event->start_time, $event->rrule);
     //
     //			$rrule->setRecurpositionStartTime($periodStartTime);
     //
     //			$origEventAttr = $event->getAttributes('formatted');
     //
     //			while ($occurenceStartTime = $rrule->getNextRecurrence()) {
     //
     //				if ($occurenceStartTime > $periodEndTime)
     //					break;
     //
     //				$origEventAttr['start_time'] = \GO\Base\Util\Date::get_timestamp($occurenceStartTime);
     //
     //				$diff = $this->getDiff();
     //
     //				$endTime = new \GO\Base\Util\Date\DateTime(date('c', $occurenceStartTime));
     //				$endTime->addDiffCompat($diff);
     //				$origEventAttr['end_time'] = \GO\Base\Util\Date::get_timestamp($endTime->format('U'));
     //
     //				$this->_calculatedEvents[$occurenceStartTime . '-' . $origEventAttr['id']] = $origEventAttr;
     //			}
     //
     //			ksort($this->_calculatedEvents);
     //		}
 }
 /**
  * Render the event row in the PDF
  * 
  * @param \GO\Calendar\Model\Event $event
  */
 private function _renderEventRow(\GO\Calendar\Model\LocalEvent $event)
 {
     $html = '';
     $html .= '<tcpdf method="renderLine" />';
     $html .= '<b><font style="font-size:' . $this->_timeFontSize . 'px">' . \GO\Base\Util\Date\DateTime::fromUnixtime($event->getAlternateStartTime())->format('H:i') . ' - ' . \GO\Base\Util\Date\DateTime::fromUnixtime($event->getAlternateEndTime())->format('H:i') . '</font> <font style="font-size:' . $this->_nameFontSize . 'px">' . \GO\Base\Util\String::text_to_html($event->getName(), true) . '</font></b>';
     $realEvent = $event->getEvent();
     if (!empty($realEvent->description)) {
         $html .= '<br /><font style="font-size:' . $this->_descriptionFontSize . 'px">' . $realEvent->getAttribute('description', 'html') . '</font>';
     }
     $this->writeHTML($html, true, false, false, false, 'L');
 }