/** * 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(); }