Esempio n. 1
0
 function testSortArray()
 {
     $arr = array(array('a' => 1, 'b' => 2), array('a' => 2, 'b' => 1), array('a' => 2, 'b' => 0));
     $res = lmbArrayHelper::sortArray($arr, array('a' => 'DESC', 'b' => 'ASC'));
     $this->assertEqual($res, array(2 => array('a' => 2, 'b' => 0), 1 => array('a' => 2, 'b' => 1), 0 => array('a' => 1, 'b' => 2)));
     $res = lmbArrayHelper::sortArray($arr, array('a' => 'DESC', 'b' => 'ASC'), false);
     $this->assertEqual($res, array(array('a' => 2, 'b' => 0), array('a' => 2, 'b' => 1), array('a' => 1, 'b' => 2)));
 }
Esempio n. 2
0
 function sort($params)
 {
     if (count($this->dataset)) {
         $this->dataset = lmbArrayHelper::sortArray($this->dataset, $params, false);
         $this->iteratedDataset = null;
     }
     return $this;
 }
Esempio n. 3
0
 function _checkProperNesting($nodes, $line = '')
 {
     $this->assertEqual(lmbArrayHelper::sortArray($nodes, array('path' => 'ASC')), $nodes);
     $path = lmbArrayHelper::getMinColumnValue('path', $nodes, $index);
     $parent_paths[] = $this->_getParentPath($path);
     $counter = 0;
     foreach ($nodes as $id => $node) {
         $parent_path = $this->_getParentPath($node['path']);
         $this->assertTrue(in_array($parent_path, $parent_paths), 'path is improperly nested: ' . $node['path'] . ' , expected parent not found: ' . $parent_path . ' at line: ' . $line);
         $parent_paths[] = $node['path'];
     }
 }
Esempio n. 4
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);
     }
 }