| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/core/src/lmbCollection.class.php'); 10 11 /** 12 * class lmbTreeHelper. 13 * 14 * @package tree 15 * @version $Id: lmbTreeHelper.class.php 5945 2007-06-06 08:31:43Z pachanga $ 16 */ 17 class lmbTreeHelper 18 { 19 function sort($rs, $sort_params, $id_hash = 'id', $parent_hash = 'parent_id') 20 { 21 $tree_array = self :: _convertRs2Array($rs); 22 23 $item = reset($tree_array); 24 $parent_id = $item[$parent_hash]; 25 26 $sorted_tree_array = array(); 27 28 self :: _doSort($tree_array, $sorted_tree_array, $sort_params, $parent_id, $id_hash, $parent_hash); 29 30 return new lmbCollection($sorted_tree_array); 31 } 32 33 function _convertRs2Array($rs) 34 { 35 $tree_array = array(); 36 foreach($rs as $record) 37 $tree_array[] = $record; 38 39 return $tree_array; 40 } 41 42 function _doSort($tree_array, &$sorted_tree_array, $sort_params, $parent_id, $id_hash, $parent_hash) 43 { 44 $children = array(); 45 46 foreach($tree_array as $index => $item) 47 { 48 if($item[$parent_hash] == $parent_id) 49 { 50 $children[] = $item; 51 unset($tree_array[$index]); 52 } 53 } 54 55 if(!($count = sizeof($children))) 56 return; 57 58 $children = lmbArrayHelper :: sortArray($children, $sort_params); 59 60 if(!$sorted_tree_array) 61 { 62 $sorted_tree_array = $children; 63 } 64 else 65 { 66 $ids = lmbArrayHelper :: getColumnValues($id_hash, $sorted_tree_array); 67 68 $offset = array_search($parent_id, $ids) + 1; 69 70 array_splice($sorted_tree_array, $offset, 0, $children); 71 } 72 73 for($i=0; $i < $count; $i++) 74 { 75 lmbTreeHelper :: _doSort($tree_array, $sorted_tree_array, $sort_params, $children[$i][$id_hash], $id_hash, $parent_hash); 76 } 77 } 78 } 79 80 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Dec 2 03:54:09 2008 | Cross-referenced by PHPXref 0.7 |