Exemplo n.º 1
0
 function _doSort($tree_array, &$sorted_tree_array, $sort_params, $parent_id, $id_hash, $parent_hash)
 {
     $children = array();
     foreach ($tree_array as $index => $item) {
         if ($item[$parent_hash] == $parent_id) {
             $children[] = $item;
             unset($tree_array[$index]);
         }
     }
     if (!($count = sizeof($children))) {
         return;
     }
     $children = lmbArrayHelper::sortArray($children, $sort_params);
     if (!$sorted_tree_array) {
         $sorted_tree_array = $children;
     } else {
         $ids = lmbArrayHelper::getColumnValues($id_hash, $sorted_tree_array);
         $offset = array_search($parent_id, $ids) + 1;
         array_splice($sorted_tree_array, $offset, 0, $children);
     }
     for ($i = 0; $i < $count; $i++) {
         lmbTreeHelper::_doSort($tree_array, $sorted_tree_array, $sort_params, $children[$i][$id_hash], $id_hash, $parent_hash);
     }
 }
Exemplo n.º 2
0
 function testGetColumnValues()
 {
     $arr = array(array('foo' => 1), array('foo' => 2));
     $this->assertEqual(lmbArrayHelper::getColumnValues('foo', $arr), array(1, 2));
 }
 function rewind()
 {
     foreach ($this->attach_relations as $relation_name => $params) {
         if (!in_array($relation_name, array_keys($this->loaded_attaches))) {
             $relation_type = $this->base_object->getRelationType($relation_name);
             $relation_info = $this->base_object->getRelationInfo($relation_name);
             $relation_class = $relation_info['class'];
             $relation_object = new $relation_class(null, $this->conn);
             switch ($relation_type) {
                 case lmbActiveRecord::HAS_ONE:
                 case lmbActiveRecord::MANY_BELONGS_TO:
                     $ids = lmbArrayHelper::getColumnValues($this->prefix . $relation_info['field'], $this->iterator);
                     if (!count($ids)) {
                         $this->loaded_attaches[$relation_name] = array();
                     } else {
                         $attached_objects = lmbActiveRecord::findByIds($relation_class, $ids, $params, $this->conn);
                         $this->loaded_attaches[$relation_name] = lmbCollection::toFlatArray($attached_objects, $key_field = $relation_object->getPrimaryKeyName(), $export_each = false);
                     }
                     break;
                 case lmbActiveRecord::BELONGS_TO:
                     $ids = lmbArrayHelper::getColumnValues($this->prefix . $this->base_object->getPrimaryKeyName(), $this->iterator);
                     if (!count($ids)) {
                         $this->loaded_attaches[$relation_name] = array();
                     } else {
                         $criteria = lmbSQLCriteria::in($relation_info['field'], $ids);
                         $params['criteria'] = isset($params['criteria']) ? $params['criteria']->addAnd($criteria) : $criteria;
                         $attached_objects = lmbActiveRecord::find($relation_class, $params, $this->conn);
                         $this->loaded_attaches[$relation_name] = lmbCollection::toFlatArray($attached_objects, $key_field = $relation_info['field'], $export_each = false);
                     }
                     break;
                 case lmbActiveRecord::HAS_MANY:
                     if (!isset($params['sort'])) {
                         $params['sort'] = $relation_object->getDefaultSortParams();
                     }
                     $params['sort'] = array($relation_info['field'] => 'ASC') + $params['sort'];
                     $query = lmbAROneToManyCollection::createFullARQueryForRelation($relation_info, $this->conn, $params);
                     $ids = lmbArrayHelper::getColumnValues($this->prefix . $this->base_object->getPrimaryKeyName(), $this->iterator);
                     $this->loaded_attaches[$relation_name] = array();
                     if (!count($ids)) {
                         break;
                     }
                     $query->addCriteria(lmbSQLCriteria::in($relation_info['field'], $ids));
                     $attached_objects = $query->fetch();
                     foreach ($attached_objects as $attached_object) {
                         $this->loaded_attaches[$relation_name][$attached_object->get($relation_info['field'])][] = $attached_object;
                     }
                     break;
                 case lmbActiveRecord::HAS_MANY_TO_MANY:
                     if (!isset($params['sort'])) {
                         $params['sort'] = $relation_object->getDefaultSortParams();
                     }
                     $params['sort'] = array($relation_info['field'] => 'ASC') + $params['sort'];
                     $query = lmbARManyToManyCollection::createFullARQueryForRelation($relation_info, $this->conn, $params);
                     $query->addField($relation_info['table'] . '.' . $relation_info['field'], "link__id");
                     $ids = lmbArrayHelper::getColumnValues($this->prefix . $this->base_object->getPrimaryKeyName(), $this->iterator);
                     $this->loaded_attaches[$relation_name] = array();
                     if (!count($ids)) {
                         break;
                     }
                     $query->addCriteria(lmbSQLCriteria::in($relation_info['field'], $ids));
                     $attached_objects = $query->fetch();
                     foreach ($attached_objects as $attached_object) {
                         $this->loaded_attaches[$relation_name][$attached_object->get("link__id")][] = $attached_object;
                     }
                     break;
             }
         }
     }
     parent::rewind();
 }
Exemplo n.º 4
0
 static function getMinColumnValue($column_name, $array, &$index)
 {
     $index = 0;
     if (!($values = lmbArrayHelper::getColumnValues($column_name, $array))) {
         return false;
     }
     $min = min($values);
     $index = array_search($min, $values);
     return $min;
 }