Example #1
0
 /**
  * Create iCalendar (.ics) file
  * @param bool $with_header
  * @return string
  */
 public function toICS($with_header = true)
 {
     $vCalendar = new Calendar('edt.u-bordeaux');
     $vCalendar->setTimezone(self::$timezone)->setName($this->name)->setDescription($this->name);
     /** @var EdtUbxItem $item */
     foreach ($this->items as $item) {
         $profs = implode(', ', $item->getProfs());
         $location = implode(', ', $item->getLocations());
         $groups = implode(', ', $item->getGroups());
         $vEvent = new Event();
         $vEvent->setUseTimezone(true)->setDtStart($item->getDtStart())->setDtEnd($item->getDtEnd())->setCategories($item->getCategory())->setLocation($location);
         $vEvent->setDescription(sprintf("%s\n%s%s%s%s%s", $item->getName(), $item->getCategory(), $location !== '' ? "\n{$location}" : '', $profs !== '' ? "\n{$profs}" : '', $groups !== '' ? "\n{$groups}" : '', $item->getNotes() ? "\nNotes: " . $item->getNotes() : ''));
         $vEvent->setSummary(sprintf('%s (%s)%s', $item->getName(), $item->getCategory(), $profs !== '' ? " - {$profs}" : ''));
         $vCalendar->addComponent($vEvent);
     }
     if ($with_header === true) {
         header('Content-type: text/calendar; charset=utf-8');
         header('Content-Disposition: attachment; filename=calendar.ics');
     }
     return $vCalendar->render();
 }
Example #2
0
 /**
  * Get common events for task ical events
  *
  * @access protected
  * @param  array   $task
  * @param  string  $uid
  * @return Event
  */
 protected function getTaskIcalEvent(array &$task, $uid)
 {
     $dateCreation = new DateTime();
     $dateCreation->setTimestamp($task['date_creation']);
     $dateModif = new DateTime();
     $dateModif->setTimestamp($task['date_modification']);
     $vEvent = new Event($uid);
     $vEvent->setCreated($dateCreation);
     $vEvent->setModified($dateModif);
     $vEvent->setUseTimezone(true);
     $vEvent->setSummary(t('#%d', $task['id']) . ' ' . $task['title']);
     $vEvent->setUrl($this->helper->url->base() . $this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])));
     if (!empty($task['owner_id'])) {
         $vEvent->setOrganizer('MAILTO:' . ($task['assignee_email'] ?: $task['assignee_username'] . '@kanboard.local'));
     }
     if (!empty($task['creator_id'])) {
         $attendees = new Attendees();
         $attendees->add('MAILTO:' . ($task['creator_email'] ?: $task['creator_username'] . '@kanboard.local'));
         $vEvent->setAttendees($attendees);
     }
     return $vEvent;
 }