Esempio n. 1
0
 /**
  * Create a usable array from the data in the database from getStructure()
  * @param $pStructureHash raw structure data from database
  * @return nicely formatted and cleaned up structure array
  */
 function createSubTree($pStructureHash, $pParentId = 0, $pParentPos = '', $pLevel = 0)
 {
     $ret = array();
     // get all child menu Nodes for this structure_id
     $children = LibertyStructure::getChildNodes($pStructureHash, $pParentId);
     $pos = 1;
     $row_max = count($children);
     // we need to insert the root structure item first
     if (!$pLevel && !empty($pStructureHash)) {
         foreach ($pStructureHash as $node) {
             if ($pParentId == 0 && $node['structure_id'] == $node['root_structure_id'] || $node['structure_id'] == $pParentId) {
                 $aux = $node;
                 $aux["first"] = true;
                 $aux["last"] = true;
                 $aux["pos"] = '';
                 $aux["level"] = $pLevel++;
                 $ret[] = $aux;
             }
         }
     }
     foreach ($children as $node) {
         $aux = $node;
         $aux['level'] = $pLevel;
         $aux['first'] = $pos == 1;
         $aux['last'] = FALSE;
         $aux['has_children'] = FALSE;
         if (strlen($pParentPos) == 0) {
             $aux["pos"] = "{$pos}";
         } else {
             $aux["pos"] = $pParentPos . '.' . "{$pos}";
         }
         $ret[] = $aux;
         //Recursively add any children
         $subs = LibertyStructure::createSubTree($pStructureHash, $node['structure_id'], $aux['pos'], $pLevel + 1);
         if (!empty($subs)) {
             $r = array_pop($ret);
             $r['has_children'] = TRUE;
             array_push($ret, $r);
             $ret = array_merge($ret, $subs);
         }
         if ($pos == $row_max) {
             $aux['structure_id'] = $node['structure_id'];
             $aux['first'] = FALSE;
             $aux['last'] = TRUE;
             $ret[] = $aux;
         }
         $pos++;
     }
     return $ret;
 }