/** * @param CAccount $oAccount */ public function InitByAccount($oAccount) { $bResult = false; if ($oAccount && (!$this->Account || $this->Account->Email !== $oAccount->Email)) { $this->Account = $oAccount; $this->aAddressBooksCache = array(); $this->aContactItemsCache = array(); $this->aGroupItemsCache = array(); $this->ContactsCache = array(); $this->GroupsCache = array(); \afterlogic\DAV\Auth\Backend::getInstance()->setCurrentUser($oAccount->Email); \afterlogic\DAV\Utils::CheckPrincipals($oAccount->Email); $aPrincipalProperties = \afterlogic\DAV\Backend::Principal()->getPrincipalByPath(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $oAccount->Email); if ($aPrincipalProperties) { if (isset($aPrincipalProperties['uri'])) { $this->Principal = $aPrincipalProperties['uri']; } } } if ($this->Account) { $bResult = true; } return $bResult; }
protected function getSharedCalendarsForUser($sPrincipalUri, $bSharedToAll = false) { $aCalendars = array(); $sTenantPrincipalUri = null; if (!$sPrincipalUri) { return $aCalendars; } if ($sPrincipalUri) { if ($bSharedToAll) { $sTenantPrincipalUri = $sPrincipalUri; $sPrincipalUri = \afterlogic\DAV\Utils::getTenantPrincipalUri($sPrincipalUri); } $sFields = $this->getCalendarFields(); $sShareFields = implode(', ', $this->sharesProperties); $oPrincipalBackend = \afterlogic\DAV\Backend::Principal(); $aPrincipal = $oPrincipalBackend->getPrincipalByPath($sPrincipalUri); if ($aPrincipal) { $oStmt = $this->pdo->prepare("SELECT " . $sShareFields . " FROM " . $this->calendarSharesTableName . " WHERE member = ?"); $oStmt->execute(array($aPrincipal['id'])); $aRows = $oStmt->fetchAll(\PDO::FETCH_ASSOC); foreach ($aRows as $aRow) { // get the original calendar $oCalStmt = $this->pdo->prepare("SELECT " . $sFields . " FROM " . $this->calendarTableName . " WHERE id = ? ORDER BY id ASC LIMIT 1"); $oCalStmt->execute(array($aRow['calendarid'])); while ($calRow = $oCalStmt->fetch(\PDO::FETCH_ASSOC)) { $aComponents = array(); if ($calRow['components']) { $aComponents = explode(',', $calRow['components']); } $aCalendar = array('id' => $calRow['id'], 'uri' => $calRow['uri'], 'principaluri' => $bSharedToAll ? $sTenantPrincipalUri : $sPrincipalUri, '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => $calRow['ctag'] ? $calRow['ctag'] : '0', '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Property\SupportedCalendarComponentSet($aComponents), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp' => new \Sabre\CalDAV\Property\ScheduleCalendarTransp($calRow['transparent'] ? 'transparent' : 'opaque')); // some specific properies for shared calendars $aCalendar['{http://calendarserver.org/ns/}shared-url'] = $calRow['uri']; $aCalendar['{http://sabredav.org/ns}owner-principal'] = $calRow['principaluri']; $aCalendar['{http://sabredav.org/ns}read-only'] = $aRow['readonly']; $aCalendar['{http://calendarserver.org/ns/}summary'] = $aRow['summary']; foreach ($this->propertyMap as $xmlName => $dbName) { if ($xmlName == '{DAV:}displayname') { $aCalendar[$xmlName] = $calRow['displayname']; //$aRow['displayname'] == null ? $calRow['displayname'] : $aRow['displayname']; } elseif ($xmlName == '{http://apple.com/ns/ical/}calendar-color') { $aCalendar[$xmlName] = $aRow['color'] == null ? $calRow['calendarcolor'] : $aRow['color']; } else { $aCalendar[$xmlName] = $calRow[$dbName]; } } $aCalendars[$aCalendar['id']] = $aCalendar; } } } } return $aCalendars; }
/** * @param CAccount $oAccount * @return bool */ public function DeletePrincipal($oAccount) { $oPrincipalBackend = \afterlogic\DAV\Backend::Principal(); $oPrincipalBackend->deletePrincipal(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $oAccount->Email); }