Beispiel #1
0
 /**
  * Recursively sorts a heirarchical tree of data
  *
  * @param array $item The item data to be sorted
  * @param int $parent (internal) The parent item of the current iteration
  * @param int $key (internal) The identified index of the parent item in the current iteration
  * @param int $depth (internal) The number of the nested depth in the current iteration
  * @return array The sorted tree of data
  * @author Jonathan Davis
  * @deprecated 1.3
  **/
 public static function sort_tree($items, $parent = 0, $key = -1, $depth = -1)
 {
     $depth++;
     $position = 1;
     $result = array();
     if ($items) {
         foreach ($items as $item) {
             // Preserve initial priority
             if (isset($item->priority)) {
                 $item->_priority = $item->priority;
             }
             if ($item->parent == $parent) {
                 $item->parentkey = $key;
                 $item->depth = $depth;
                 $item->priority = $position++;
                 $result[] = $item;
                 $children = Shopp::sort_tree($items, $item->id, count($result) - 1, $depth);
                 $result = array_merge($result, $children);
                 // Add children in as they are found
             }
         }
     }
     $depth--;
     return $result;
 }