Horde_Core_ActiveSync_Connector::getFolders PHP Method

getFolders() public method

Return the list of folders to sync for the specified collection.
Since: 2.12.0
public getFolders ( string $collection, integer $multiplex ) : array | string
$collection string The collection class A Horde_ActiveSync::CLASS_* constant.
$multiplex integer A bitmask flagging the collections that must be multiplexed, regardless of horde's settings
return array | string A list of folder uids or $collection if supporting API is not found. If a list is returned, it is in the following format: 'uid' => array('display' => "Display Name", 'primary' => boolean)
    public function getFolders($collection, $multiplex)
    {
        $folders = false;
        if (empty($this->_folderCache[$collection])) {
            switch ($collection) {
                case Horde_ActiveSync::CLASS_CALENDAR:
                    if ($this->_registry->hasMethod('calendar/sources') && $this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex') && !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_CALENDAR)) {
                        $folders = $this->_registry->calendar->sources(true, true);
                        $default = $this->_registry->calendar->getDefaultShare();
                    } else {
                        $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::APPOINTMENTS_FOLDER_UID;
                    }
                    break;
                case Horde_ActiveSync::CLASS_CONTACTS:
                    if ($this->_registry->hasMethod('contacts/sources') && $this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex') && !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_CONTACTS)) {
                        $folders = $this->_registry->contacts->sources(true, true);
                        $default = $this->_registry->contacts->getDefaultShare();
                    } else {
                        $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::CONTACTS_FOLDER_UID;
                    }
                    break;
                case Horde_ActiveSync::CLASS_TASKS:
                    if ($this->_registry->hasMethod('tasks/sources') && $this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex') && !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_TASKS)) {
                        $folders = $this->_registry->tasks->sources(true, true);
                        $default = $this->_registry->tasks->getDefaultShare();
                    } else {
                        $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::TASKS_FOLDER_UID;
                    }
                    break;
                case Horde_ActiveSync::CLASS_NOTES:
                    if ($this->_registry->hasMethod('notes/sources') && $this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex') && !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_NOTES)) {
                        $folders = $this->_registry->notes->sources(true, true);
                        $default = $this->_registry->notes->getDefaultShare();
                    } else {
                        $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::NOTES_FOLDER_UID;
                    }
            }
            if (!empty($folders) && is_array($folders)) {
                $results = array();
                foreach ($folders as $id => $folder) {
                    $results[$id] = array('display' => $folder, 'primary' => $id == $default);
                }
                $this->_folderCache[$collection] = $results;
            } elseif (is_array($folders)) {
                $this->_folderCache[$collection] = false;
            }
        }
        return $this->_folderCache[$collection];
    }

Usage Example

Example #1
0
 /**
  * Return an array of the server's folder objects.
  *
  * @return array  An array of Horde_ActiveSync_Message_Folder objects.
  */
 public function getFolders()
 {
     $multiplex = $this->_device->multiplex;
     if (empty($this->_folders)) {
         ob_start();
         try {
             $supported = $this->_connector->horde_listApis();
         } catch (Exception $e) {
             $this->_logger->err($e->getMessage());
             $this->_endBuffer();
             return array();
         }
         $folders = array();
         if (array_search('calendar', $supported) !== false) {
             $temp = $this->_connector->getFolders(Horde_ActiveSync::CLASS_CALENDAR, $multiplex);
             if (is_array($temp)) {
                 foreach ($temp as $id => $folder) {
                     try {
                         $folders[] = $this->_getFolder(Horde_ActiveSync::CLASS_CALENDAR . ':' . $id, array('class' => Horde_ActiveSync::CLASS_CALENDAR, 'primary' => $folder['primary'], 'display' => $folder['display']));
                     } catch (Horde_ActiveSync_Exception $e) {
                     }
                 }
             } else {
                 try {
                     $folders[] = $this->_getFolder($temp);
                 } catch (Horde_ActiveSync_Exception $e) {
                 }
             }
         }
         if (array_search('contacts', $supported) !== false) {
             $temp = $this->_connector->getFolders(Horde_ActiveSync::CLASS_CONTACTS, $multiplex);
             if (is_array($temp)) {
                 foreach ($temp as $id => $folder) {
                     try {
                         $folders[] = $this->_getFolder(Horde_ActiveSync::CLASS_CONTACTS . ':' . $id, array('class' => Horde_ActiveSync::CLASS_CONTACTS, 'primary' => $folder['primary'], 'display' => $folder['display']));
                     } catch (Horde_ActiveSync_Exception $e) {
                     }
                 }
             } else {
                 try {
                     $folders[] = $this->_getFolder($temp);
                 } catch (Horde_ActiveSync_Exception $e) {
                 }
             }
         }
         if (array_search('tasks', $supported) !== false) {
             $temp = $this->_connector->getFolders(Horde_ActiveSync::CLASS_TASKS, $multiplex);
             if (is_array($temp)) {
                 foreach ($temp as $id => $folder) {
                     try {
                         $folders[] = $this->_getFolder(Horde_ActiveSync::CLASS_TASKS . ':' . $id, array('class' => Horde_ActiveSync::CLASS_TASKS, 'primary' => $folder['primary'], 'display' => $folder['display']));
                     } catch (Horde_ActiveSync_Exception $e) {
                     }
                 }
             } else {
                 try {
                     $folders[] = $this->_getFolder($temp);
                 } catch (Horde_ActiveSync_Exception $e) {
                 }
             }
         }
         if (array_search('notes', $supported) !== false) {
             $temp = $this->_connector->getFolders(Horde_ActiveSync::CLASS_NOTES, $multiplex);
             if (is_array($temp)) {
                 foreach ($temp as $id => $folder) {
                     try {
                         $folders[] = $this->_getFolder(Horde_ActiveSync::CLASS_NOTES . ':' . $id, array('class' => Horde_ActiveSync::CLASS_NOTES, 'primary' => $folder['primary'], 'display' => $folder['display']));
                     } catch (Horde_ActiveSync_Exception $e) {
                     }
                 }
             } else {
                 try {
                     $folders[] = $this->_getFolder($temp);
                 } catch (Horde_ActiveSync_Exception $e) {
                 }
             }
         }
         if ($this->_version > Horde_ActiveSync::VERSION_TWELVEONE) {
             $folders[] = $this->_getFolder('RI', array('class' => 'RI'));
         }
         // Always return at least the "dummy" IMAP folders since some
         // clients refuse to consider a FOLDERSYNC successful without
         // at least an INBOX, even with email sync turned off.
         try {
             $folders = array_merge($folders, $this->_getMailFolders());
         } catch (Horde_ActiveSync_Exception $e) {
             $this->_logger->err($e->getMessage());
             $this->_endBuffer();
             return array();
         }
         $this->_endBuffer();
         $this->_folders = $folders;
     }
     return $this->_folders;
 }