/** * Sort a array by the given property and sort direction * * @param array $array * @param string $property * @param int $sort */ function arraySortProperty(&$array, $property, $sort = SORT_ASC) { if (!$array || !is_array($array)) { return array(); } $map = arrayMapProperty($array, $property); array_multisort($map, $sort, $array); }
/** * Lazy load array member - Fetch all array values for all objects that stored in the cache * * @param CHOQ_DB_Object $object * @param CHOQ_DB_TypeMember $member */ public function lazyLoadArrayMember(CHOQ_DB_Object $object, CHOQ_DB_TypeMember $member) { $db = $member->getDb ? $member->getDb : $this; $objects = CHOQ_DB_Object::getCachedObjects($db, $object->_getType()); $objects[$object->getId()] = $object; $ids = array(); if ($objects) { foreach ($objects as $o) { if (!isset($o->_loaded[$member->name]) && isset($o->_dbValues[$member->name])) { $ids[$o->getId()] = $o->getId(); } $o->_loaded[$member->name] = true; } } if ($ids) { $table = $db->quote($member->type->class . "_" . $member->name); $tmp = $db->fetchAsAssoc("SELECT * FROM {$table} WHERE " . $db->quote("o") . " IN " . $db->toDb($ids)); if ($member->fieldTypeArrayClass) { $arr = $db->getByIds(NULL, arrayMapProperty($tmp, "v")); foreach ($tmp as $row) { if (isset($arr[$row["v"]])) { $objects[$row["o"]]->add($member->name, $arr[$row["v"]], $arr[$row["v"]]->getId(), false); } } } else { foreach ($tmp as $row) { if (isset($ids[$row["o"]])) { $objects[$row["o"]]->add($member->name, $member->convertFromDbValue($row["v"]), $row["k"], false); } } } } }