Turba_List::_cmp PHP Method

_cmp() protected method

Compares two Turba_Objects based on the member variable $_usortCriteria, taking care to sort numerically if it is an integer field.
protected _cmp ( Turba_Object $a, Turba_Object $b ) : integer
$a Turba_Object The first Turba_Object to compare.
$b Turba_Object The second Turba_Object to compare.
return integer Comparison of the two field values.
    protected function _cmp(Turba_Object $a, Turba_Object $b)
    {
        foreach ($this->_usortCriteria as $field) {
            $f = $field['field'];
            switch ($field['sortmethod']) {
                case 'int':
                    $result = $a->getValue($f) > $b->getValue($f) ? 1 : -1;
                    break;
                case 'text':
                    if (!isset($a->sortValue[$f])) {
                        $a->sortValue[$f] = Horde_String::lower($a->getValue($f), true, 'UTF-8');
                    }
                    if (!isset($b->sortValue[$f])) {
                        $b->sortValue[$f] = Horde_String::lower($b->getValue($f), true, 'UTF-8');
                    }
                    // Use strcoll for locale-safe comparisons.
                    $result = strcoll($a->sortValue[$f], $b->sortValue[$f]);
                    break;
            }
            if ($result != 0) {
                return ($field['ascending'] ? 1 : -1) * $result;
            }
        }
        return 0;
    }