Turba_Driver::_toTurbaObjects PHP Method

_toTurbaObjects() protected method

Takes an array of object hashes and returns a Turba_List containing the correct Turba_Objects
protected _toTurbaObjects ( array $objects, array $sort_order = null ) : Turba_List
$objects array An array of object hashes (keyed to backend).
$sort_order array Array of hashes describing sort fields. Each hash has the following fields:
ascending - (boolean) Indicating sort direction.
field - (string) Sort field.
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;
    }