/** * Get this task as a VObject. This can be turned into a vcalendar file data. * * @return Sabre\VObject\Component */ public function toVObject() { $calendar = new Sabre\VObject\Component\VCalendar(); $e = $calendar->createComponent('VTODO'); $e->uid = $this->uuid; $e->add('dtstamp', new \DateTime("now", new \DateTimeZone('UTC'))); $mtimeDateTime = new \DateTime('@' . $this->mtime); $mtimeDateTime->setTimezone(new \DateTimeZone('UTC')); $e->add('LAST-MODIFIED', $mtimeDateTime); $ctimeDateTime = new \DateTime('@' . $this->mtime); $ctimeDateTime->setTimezone(new \DateTimeZone('UTC')); $e->add('created', $ctimeDateTime); $e->summary = $this->name; $e->status = $this->status; $dateType = "DATE"; if (!empty($this->start_time)) { $e->add('dtstart', \GO\Base\Util\Date\DateTime::fromUnixtime($this->start_time), array('VALUE' => $dateType)); } $e->add('due', \GO\Base\Util\Date\DateTime::fromUnixtime($this->due_time), array('VALUE' => $dateType)); if ($this->completion_time > 0) { $e->add('completed', \GO\Base\Util\Date\DateTime::fromUnixtime($this->completion_time), array('VALUE' => $dateType)); } if (!empty($this->percentage_complete)) { $e->add('percent-complete', $this->percentage_complete); } if (!empty($this->description)) { $e->description = $this->description; } //todo exceptions if (!empty($this->rrule)) { $e->rrule = str_replace('RRULE:', '', $this->rrule); } switch ($this->priority) { case self::PRIORITY_LOW: $e->priority = 9; break; case self::PRIORITY_HIGH: $e->priority = 1; break; default: $e->priority = 5; } if ($this->reminder > 0) { $a = $calendar->createComponent('VALARM'); // BEGIN:VALARM //ACTION:DISPLAY //TRIGGER;VALUE=DURATION:-PT5M //DESCRIPTION:Default Mozilla Description //END:VALARM $a->action = 'DISPLAY'; $a->add('trigger', date('Ymd\\THis', $this->reminder), array('value' => 'DATE-TIME')); $a->description = "Alarm"; //for funambol compatibility, the \GO\Base\VObject\Reader class use this to convert it to a vcalendar 1.0 aalarm tag. $e->{"X-GO-REMINDER-TIME"} = date('Ymd\\THis', $this->reminder); $e->add($a); } return $e; }
/** * Generate the holidays from the holidays file for the given year and locale. * * @param string $year * @param string $locale * @throws Exception */ public function generateHolidays($year, $locale = 'en') { $this->deleteHolidays($year, $locale); // Load the holidays file for the given $locale if (is_file(\GO::config()->root_path . 'language/holidays/' . $locale . '.php')) { require \GO::config()->root_path . 'language/holidays/' . $locale . '.php'; } // else // throw new \Exception('No holidays file for this language: '.$locale.'.'); if (empty($year)) { $year = date('Y'); } $holidays = array(); if (!empty($input_holidays)) { $holidays = $input_holidays; } // Set the fixed holidays from the holidays file if (isset($holidays['fix'])) { foreach ($holidays['fix'] as $key => $record) { if (is_string($record)) { $month_day = explode("-", $key); $date = mktime(0, 0, 0, $month_day[0], $month_day[1], $year); $holiday = new Holiday(); $holiday->name = $record; $holiday->date = date('Y-m-d', $date); $holiday->region = $locale; $holiday->save(); } else { if (is_array($record)) { $month_day = explode("-", $key); $date = mktime(0, 0, 0, $month_day[0], $month_day[1], $year); $holiday = new Holiday(); $holiday->name = $record['name']; $holiday->date = date('Y-m-d', $date); $holiday->region = $locale; $holiday->free_day = $record['free']; $holiday->save(); } } } } // Set the variable holidays if (isset($holidays['var']) && function_exists('easter_date') && $year > 1969 && $year < 2037) { // $easter_day = easter_date($year); $easterDT = \GO\Base\Util\Date\DateTime::getEasterDatetime($year); $easter_day = $easterDT->format('U'); foreach ($holidays['var'] as $key => $record) { if (is_string($record)) { $date = strtotime($key . " days", $easter_day); $holiday = new Holiday(); $holiday->name = $record; $holiday->date = date('Y-m-d', $date); $holiday->region = $locale; $holiday->save(); } else { if (is_array($record)) { $date = strtotime($key . " days", $easter_day); $holiday = new Holiday(); $holiday->name = $record['name']; $holiday->date = date('Y-m-d', $date); $holiday->region = $locale; $holiday->free_day = $record['free']; $holiday->save(); } } } } if (isset($holidays['spc'])) { $weekday = $this->get_weekday("24", "12", $year); foreach ($holidays['spc'] as $key => $name) { if (is_string($record)) { $count = $key - $weekday; $date = strtotime($count . " days", mktime(0, 0, 0, "12", "24", $year)); $holiday = new Holiday(); $holiday->name = $record; $holiday->date = date('Y-m-d', $date); $holiday->region = $locale; $holiday->save(); } else { if (is_array($record)) { $count = $key - $weekday; $date = strtotime($count . " days", mktime(0, 0, 0, "12", "24", $year)); $holiday = new Holiday(); $holiday->name = $record['name']; $holiday->date = date('Y-m-d', $date); $holiday->region = $locale; $holiday->free_day = $record['free']; $holiday->save(); } } } } if (isset($holidays['fn'])) { foreach ($holidays['fn'] as $def) { $d = call_user_func($def[1], $year); if (!empty($d)) { $holiday = new Holiday(); $holiday->name = $def[0]; $holiday->date = $d; $holiday->region = $locale; $holiday->save(); } } } }
/** * Get this event as a VObject. This can be turned into a vcalendar file data. * * @param string $method REQUEST, REPLY or CANCEL * @param Participant $updateByParticipant The participant that is generating this ICS for a response. * @param int $recurrenceTime Export for a specific recurrence time for the recurrence-id. * @param boolean $includeExdatesForMovedEvents Funambol need EXDATE lines even for appointments that have been moved. CalDAV doesn't need those lines. * * If this event is an occurence and has a exception_for_event_id it will automatically determine this value. * This option is only useful for cancelling a single occurence. Because in that case there is no event model for the occurrence. There's just an exception. * * @return Sabre\VObject\Component */ public function toVObject($method = 'REQUEST', $updateByParticipant = false, $recurrenceTime = false, $includeExdatesForMovedEvents = false) { $calendar = new Sabre\VObject\Component\VCalendar(); $e = $calendar->createComponent('VEVENT'); if (empty($this->uuid)) { $this->uuid = \GO\Base\Util\UUID::create('event', $this->id); $this->save(true); } $e->uid = $this->uuid; if (isset($this->sequence)) { $e->sequence = $this->sequence; } $e->add('dtstamp', new \DateTime("now", new \DateTimeZone('UTC'))); $mtimeDateTime = new \DateTime('@' . $this->mtime); $mtimeDateTime->setTimezone(new \DateTimeZone('UTC')); $e->add('LAST-MODIFIED', $mtimeDateTime); $ctimeDateTime = new \DateTime('@' . $this->mtime); $ctimeDateTime->setTimezone(new \DateTimeZone('UTC')); $e->add('created', $ctimeDateTime); $e->summary = (string) $this->name; // switch($this->owner_status){ // case Participant::STATUS_ACCEPTED: // $e->status = "CONFIRMED"; // break; // case Participant::STATUS_DECLINED: // $e->status = "CANCELLED"; // break; // default: // $e->status = "TENTATIVE"; // break; // } $e->status = $this->status; $dateType = $this->all_day_event ? "DATE" : "DATETIME"; // if($this->all_day_event){ // $e->{"X-FUNAMBOL-ALLDAY"}=1; // } if ($this->exception_for_event_id > 0) { //this is an exception $exception = $this->recurringEventException(); //get master event from relation if ($exception) { $recurrenceTime = $exception->getStartTime(); } } if ($recurrenceTime) { $dt = \GO\Base\Util\Date\DateTime::fromUnixtime($recurrenceTime); $rId = $e->add('recurrence-id', $dt); if ($this->_exceptionEvent->all_day_event) { $rId['VALUE'] = 'DATE'; } } $dtstart = $e->add('dtstart', \GO\Base\Util\Date\DateTime::fromUnixtime($this->start_time)); if ($this->all_day_event) { $dtstart['VALUE'] = 'DATE'; } if ($this->all_day_event) { $end_time = \GO\Base\Util\Date::clear_time($this->end_time); $end_time = \GO\Base\Util\Date::date_add($end_time, 1); } else { $end_time = $this->end_time; } $dtend = $e->add('dtend', \GO\Base\Util\Date\DateTime::fromUnixtime($end_time)); if ($this->all_day_event) { $dtend['VALUE'] = 'DATE'; } if (!empty($this->description)) { $e->description = $this->description; } if (!empty($this->location)) { $e->location = $this->location; } if (!empty($this->rrule)) { $rRule = $this->getRecurrencePattern(); $rRule->shiftDays(false); $e->add('rrule', str_replace('RRULE:', '', $rRule->createRrule())); $findParams = \GO\Base\Db\FindParams::newInstance(); if (!$includeExdatesForMovedEvents) { $findParams->getCriteria()->addCondition('exception_event_id', 0); } $stmt = $this->exceptions($findParams); while ($exception = $stmt->fetch()) { $dt = \GO\Base\Util\Date\DateTime::fromUnixtime($exception->getStartTime()); $exdate = $e->add('exdate', $dt); if ($this->all_day_event) { $exdate['VALUE'] = 'DATE'; } } } $stmt = $this->participants(); while ($participant = $stmt->fetch()) { if ($participant->is_organizer || $method == 'REQUEST' || $updateByParticipant && $updateByParticipant->id == $participant->id) { //If this is a meeting REQUEST then we must send all participants. //For a CANCEL or REPLY we must send the organizer and the current user. $e->add($participant->is_organizer ? 'organizer' : 'attendee', 'mailto:' . $participant->email, array('cn' => $participant->name, 'rsvp' => 'true', 'partstat' => $this->_exportVObjectStatus($participant->status))); } } if ($this->category) { $e->categories = $this->category->name; } if ($this->reminder > 0) { $a = $calendar->createComponent('VALARM'); // BEGIN:VALARM //ACTION:DISPLAY //TRIGGER;VALUE=DURATION:-PT5M //DESCRIPTION:Default Mozilla Description //END:VALARM $a->action = 'DISPLAY'; $a->add('trigger', '-PT' . $this->reminder / 60 . 'M', array('value' => 'DURATION')); $a->description = "Alarm"; //for funambol compatibility, the \GO\Base\VObject\Reader class use this to convert it to a vcalendar 1.0 aalarm tag. $e->{"X-GO-REMINDER-TIME"} = date('Ymd\\THis', $this->start_time - $this->reminder); $e->add($a); } if ($this->private) { $e->class = 'PRIVATE'; } return $e; }
/** * 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'); }