Exemple #1
0
 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;
 }
Exemple #2
0
 /**
  * @param CAccount $oAccount
  * @return bool
  */
 public function ClearAllContactsAndGroups($oAccount)
 {
     $bResult = false;
     $this->InitByAccount($oAccount);
     $oAddressBooks = new \Sabre\CardDAV\UserAddressBooks(\afterlogic\DAV\Backend::Carddav(), $this->Principal);
     foreach ($oAddressBooks->getChildren() as $oAddressBook) {
         if ($oAddressBook && $oAddressBook instanceof \Sabre\CardDAV\AddressBook) {
             try {
                 $oAddressBook->delete();
                 $bResult = true;
             } catch (Exception $ex) {
                 CApi::Log($ex->getTraceAsString());
                 $bResult = false;
             }
         }
     }
     return $bResult;
 }
Exemple #3
0
 /**
  * @param CAccount $oAccount
  * @return bool
  */
 public function DeletePrincipal($oAccount)
 {
     $oPrincipalBackend = \afterlogic\DAV\Backend::Principal();
     $oPrincipalBackend->deletePrincipal(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $oAccount->Email);
 }