/** * This event is triggered when properties are requested for a certain * node. * * This allows us to inject any properties early. * * @param string $path * @param DAV\INode $node * @param array $requestedProperties * @param array $returnedProperties * @return void */ public function beforeGetProperties($path, DAV\INode $node, &$requestedProperties, &$returnedProperties) { if ($node instanceof IShareableCalendar) { if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}invite', $requestedProperties)) !== false) { unset($requestedProperties[$index]); $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}invite'] = new Property\Invite($node->getShares()); } } if ($node instanceof ISharedCalendar) { if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}shared-url', $requestedProperties)) !== false) { unset($requestedProperties[$index]); $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}shared-url'] = new DAV\Property\Href($node->getSharedUrl()); } // The 'invite' property is slightly different for the 'shared' // instance of the calendar, as it also contains the owner // information. if (($index = array_search('{' . Plugin::NS_CALENDARSERVER . '}invite', $requestedProperties)) !== false) { unset($requestedProperties[$index]); // Fetching owner information $props = $this->server->getPropertiesForPath($node->getOwner(), array('{http://sabredav.org/ns}email-address', '{DAV:}displayname'), 1); $ownerInfo = array('href' => $node->getOwner()); if (isset($props[0][200])) { // We're mapping the internal webdav properties to the // elements caldav-sharing expects. if (isset($props[0][200]['{http://sabredav.org/ns}email-address'])) { $ownerInfo['href'] = 'mailto:' . $props[0][200]['{http://sabredav.org/ns}email-address']; } if (isset($props[0][200]['{DAV:}displayname'])) { $ownerInfo['commonName'] = $props[0][200]['{DAV:}displayname']; } } $returnedProperties[200]['{' . Plugin::NS_CALENDARSERVER . '}invite'] = new Property\Invite($node->getShares(), $ownerInfo); } } }
/** * This event is triggered when properties are requested for a certain * node. * * This allows us to inject any properties early. * * @param DAV\PropFind $propFind * @param DAV\INode $node * @return void */ function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { if ($node instanceof IShareableCalendar) { $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function () use($node) { return new Xml\Property\Invite($node->getShares()); }); } if ($node instanceof ISharedCalendar) { $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}shared-url', function () use($node) { return new Href($node->getSharedUrl()); }); $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}invite', function () use($node) { // Fetching owner information $props = $this->server->getPropertiesForPath($node->getOwner(), ['{http://sabredav.org/ns}email-address', '{DAV:}displayname'], 0); $ownerInfo = ['href' => $node->getOwner()]; if (isset($props[0][200])) { // We're mapping the internal webdav properties to the // elements caldav-sharing expects. if (isset($props[0][200]['{http://sabredav.org/ns}email-address'])) { $ownerInfo['href'] = 'mailto:' . $props[0][200]['{http://sabredav.org/ns}email-address']; } if (isset($props[0][200]['{DAV:}displayname'])) { $ownerInfo['commonName'] = $props[0][200]['{DAV:}displayname']; } } return new Xml\Property\Invite($node->getShares(), $ownerInfo); }); } }