sort() public method

The default sort order is by last name, ascending.
public sort ( array $order = null )
$order array Array of hashes describing sort fields. Each hash has the following fields:
ascending - (boolean) Sort direction.
field - (string) Sort field.
コード例 #1
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;
 }
コード例 #2
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;
 }