}
/**
- * Translates an array of hashes from being keyed on driver-specific
- * fields to being keyed on the generalized Turba attributes. The
- * translation is based on the contents of $this->map.
+ * Translates a hash from being keyed on driver-specific fields to being
+ * keyed on the generalized Turba attributes. The translation is based on
+ * the contents of $this->map.
*
- * @param array $objects Array of hashes using driver-specific keys.
+ * @param array $entry A hash using driver-specific keys.
*
- * @return array Translated version of $objects.
+ * @return array Translated version of $entry.
*/
- function toTurbaKeys($objects)
+ function toTurbaKeys($entry)
{
- $attributes = array();
- foreach ($objects as $entry) {
- $new_entry = array();
-
- foreach ($this->map as $key => $val) {
- if (!is_array($val)) {
- $new_entry[$key] = null;
- if (isset($entry[$val]) && strlen($entry[$val])) {
- $new_entry[$key] = trim($entry[$val]);
- }
+ $new_entry = array();
+ foreach ($this->map as $key => $val) {
+ if (!is_array($val)) {
+ $new_entry[$key] = null;
+ if (isset($entry[$val]) && strlen($entry[$val])) {
+ $new_entry[$key] = trim($entry[$val]);
}
}
-
- $attributes[] = $new_entry;
}
- return $attributes;
+ return $new_entry;
}
/**
*/
function _toTurbaObjects($objects, $sort_order = null)
{
- /* Translate the driver-specific fields in the result back to the more
- * generalized common Turba attributes using the map. */
- $objects = $this->toTurbaKeys($objects);
-
$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') {
}
$results = array();
- $objects = $this->toTurbaKeys($objects);
foreach ($objects as $object) {
+ $object = $this->toTurbaKeys($object);
$done = false;
if (!empty($object['__type']) &&
ucwords($object['__type']) != 'Object') {
*
* @return integer Comparison of the two field values.
*/
- function cmp($a, $b)
+ function cmp(&$a, &$b)
{
require TURBA_BASE . '/config/attributes.php';
foreach ($this->_usortCriteria as $field) {
}
$method = 'cmp_' . $usortType;
- $result = $this->$method($a->getValue($field['field']),
- $b->getValue($field['field']));
+ $result = $this->$method($a, $b, $field['field']);
if (!$field['ascending']) {
$result = -$result;
}
return 0;
}
- function cmp_text($a, $b)
+ function cmp_text(&$a, &$b, $field)
{
- $acmp = Horde_String::lower($a, true);
- $bcmp = Horde_String::lower($b, true);
+ if (!isset($a->sortValue[$field])) {
+ $a->sortValue[$field] = Horde_String::lower($a->getValue($field), true);
+ }
+ if (!isset($b->sortValue[$field])) {
+ $b->sortValue[$field] = Horde_String::lower($b->getValue($field), true);
+ }
// Use strcoll for locale-safe comparisons.
- return strcoll($acmp, $bcmp);
+ return strcoll($a->sortValue[$field], $b->sortValue[$field]);
}
- function cmp_int($a, $b)
+ function cmp_int($a, $b, $field)
{
- return ($a > $b) ? 1 : -1;
+ return ($a->getValue($field) > $b->getValue($field)) ? 1 : -1;
}
}