Copyright 2000-2016 Horde LLC (http://www.horde.org/) See the enclosed file LICENSE for license information (ASL). If you did did not receive this file, see http://www.horde.org/licenses/apache.
Author: Chuck Hagenbuch (chuck@horde.org)
Author: Jon Parise (jon@csh.rit.edu)
Inheritance: implements Countable
コード例 #1
0
ファイル: List.php プロジェクト: horde/horde
 /**
  * Returns a filtered list of objects.
  *
  * @param  string $field  The field to filter on.
  * @param  array $values  An array of values that $field must be equal to
  *                        in order to be returned in the filtered list.
  *
  * @return Turba_List  The filtered list object.
  */
 public function filter($field, array $values)
 {
     $objects = new Turba_List();
     foreach ($this->objects as $obj) {
         if (in_array($obj->getValue($field), $values) !== false) {
             $objects->insert($obj);
         }
     }
     return $objects;
 }
コード例 #2
0
ファイル: TestBase.php プロジェクト: jubinpatel/horde
 /**
  * Constructs and returns a Turba_List:: object populated with items
  *
  * @return Turba_List
  */
 function getList()
 {
     $list = new Turba_List();
     $driver = $this->getDriver();
     foreach (array('eee', 'ccc', 'ddd', 'bbb', 'aaa') as $id) {
         $result = $list->insert($driver->getObject($id));
         $this->assertOk($result);
     }
     return $list;
 }
コード例 #3
0
ファイル: Group.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Retrieve the Objects in this group
  *
  * @param array $sort   The requested sort order which is passed to
  *                      Turba_List::sort().
  *
  * @return Turba_List   List containing the members of this group
  */
 public function listMembers($sort = null)
 {
     $list = new Turba_List();
     $children = unserialize($this->attributes['__members']);
     if (!is_array($children)) {
         $children = array();
     }
     reset($children);
     $modified = false;
     foreach ($children as $member) {
         if (strpos($member, ':') === false) {
             try {
                 $contact = $this->driver->getObject($member);
             } catch (Horde_Exception_NotFound $e) {
                 if (!empty($this->_options['removeMissing'])) {
                     // Remove the contact if it no longer exists
                     $this->removeMember($member);
                     $modified = true;
                 }
                 continue;
             }
         } else {
             list($sourceId, $contactId) = explode(':', $member, 2);
             try {
                 $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($sourceId);
             } catch (Turba_Exception $e) {
                 continue;
             }
             try {
                 $contact = $driver->getObject($contactId);
             } catch (Horde_Exception_NotFound $e) {
                 if (!empty($this->_options['removeMissing'])) {
                     // Remove the contact if it no longer exists
                     $this->removeMember($member);
                     $modified = true;
                 }
                 continue;
             }
         }
         $list->insert($contact);
     }
     // If we've pruned any dead entries, store the changes.
     if ($modified) {
         $this->store();
     }
     $list->sort($sort);
     return $list;
 }
コード例 #4
0
ファイル: Driver.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Takes an array of object hashes and returns a Turba_List
  * containing the correct Turba_Objects
  *
  * @param array $objects     An array of object hashes (keyed to backend).
  * @param array $sort_order  Array of hashes describing sort fields.  Each
  *                           hash has the following fields:
  * <pre>
  * ascending - (boolean) Indicating sort direction.
  * field - (string) Sort field.
  * </pre>
  *
  * @return Turba_List  A list object.
  */
 protected function _toTurbaObjects(array $objects, array $sort_order = null)
 {
     $list = new Turba_List();
     foreach ($objects as $object) {
         /* Translate the driver-specific fields in the result back to the
          * more generalized common Turba attributes using the map. */
         $object = $this->toTurbaKeys($object);
         $done = false;
         if (!empty($object['__type']) && ucwords($object['__type']) != 'Object') {
             $class = 'Turba_Object_' . ucwords($object['__type']);
             if (class_exists($class)) {
                 $list->insert(new $class($this, $object, $this->_objectOptions));
                 $done = true;
             }
         }
         if (!$done) {
             $list->insert(new Turba_Object($this, $object, $this->_objectOptions));
         }
     }
     $list->sort($sort_order);
     /* Return the filtered (sorted) results. */
     return $list;
 }
コード例 #5
0
ファイル: List.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Returns the number of Turba_Objects that are in the list. Use this to
  * hide internal implementation details from client objects.
  *
  * @return integer  The number of objects in the list.
  */
 public function count()
 {
     return $this->list->count();
 }