/** * Returns all calendar objects within a calendar object. * * Every item contains an array with the following keys: * * id - unique identifier which will be used for subsequent updates * * calendardata - The iCalendar-compatible calnedar data * * uri - a unique key which will be used to construct the uri. This can be any arbitrary string. * * lastmodified - a timestamp of the last modification time * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: * ' "abcdef"') * * calendarid - The calendarid as it was passed to this function. * * Note that the etag is optional, but it's highly encouraged to return for * speed reasons. * * The calendardata is also optional. If it's not returned * 'getCalendarObject' will be called later, which *is* expected to return * calendardata. * * @param string $calendarId * @return array */ public function getCalendarObjects($calendarId) { $data = array(); if ($calendarId === 'contact_birthdays') { $app = new \OCA\Contacts\App(); $addressBooks = $app->getAddressBooksForUser(); foreach ($addressBooks as $addressBook) { foreach ($addressBook->getChildren() as $contact) { $vevent = $contact->getBirthdayEvent(); if (is_null($vevent)) { continue; } $data[] = $this->OCAddETag(array('id' => 0, 'calendarid' => 'contact_birthdays', 'uri' => $addressBook->getBackend()->name . '::' . $addressBook->getId() . '::' . $contact->getId() . '.ics', 'lastmodified' => $contact->lastModified(), 'summary' => $vevent->SUMMARY, 'calendardata' => $vevent->serialize())); } } } else { $calendar = OC_Calendar_Calendar::find($calendarId); $isShared = $calendar['userid'] !== OCP\USER::getUser(); foreach (OC_Calendar_Object::all($calendarId) as $row) { if (!$isShared) { $data[] = $this->OCAddETag($row); } else { if (substr_count($row['calendardata'], 'CLASS') === 0) { $data[] = $this->OCAddETag($row); } else { $object = \Sabre\VObject\Reader::read($row['calendardata']); if (!$object) { return false; } $isPrivate = false; $toCheck = array('VEVENT', 'VJOURNAL', 'VTODO'); foreach ($toCheck as $type) { foreach ($object->select($type) as $vobject) { if (isset($vobject->{'CLASS'}) && $vobject->{'CLASS'}->getValue() === 'PRIVATE') { $isPrivate = true; } } } if ($isPrivate === false) { $data[] = $this->OCAddETag($row); } } } } } return $data; }
/** * Returns all calendar objects within a calendar object. * * Every item contains an array with the following keys: * * id - unique identifier which will be used for subsequent updates * * calendardata - The iCalendar-compatible calnedar data * * uri - a unique key which will be used to construct the uri. This can be any arbitrary string. * * lastmodified - a timestamp of the last modification time * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: * ' "abcdef"') * * calendarid - The calendarid as it was passed to this function. * * Note that the etag is optional, but it's highly encouraged to return for * speed reasons. * * The calendardata is also optional. If it's not returned * 'getCalendarObject' will be called later, which *is* expected to return * calendardata. * * @param string $calendarId * @return array */ public function getCalendarObjects($calendarId) { $data = array(); if ($calendarId === 'contact_birthdays') { $app = new \OCA\Contacts\App(); $addressBooks = $app->getAddressBooksForUser(); foreach ($addressBooks as $addressBook) { foreach ($addressBook->getChildren() as $contact) { $vevent = $contact->getBirthdayEvent(); if (is_null($vevent)) { continue; } $data[] = $this->OCAddETag(array('id' => 0, 'calendarid' => 'contact_birthdays', 'uri' => $addressBook->getBackend()->name . '::' . $addressBook->getId() . '::' . $contact->getId(), 'lastmodified' => $contact->lastModified(), 'summary' => $vevent->SUMMARY, 'calendardata' => $vevent->serialize())); } } } else { foreach (OC_Calendar_Object::all($calendarId) as $row) { $data[] = $this->OCAddETag($row); } } return $data; }