Ejemplo n.º 1
0
 /**
  * Load content tree from a flat array of hashes (from the database?)
  *
  * This method uses recursion to load the tree.
  *
  * @internal
  * @access private
  * @param array The data to import
  * @param integer (optional) The parent id to load the tree from (default is -1)
  * @param cms_content_tree (optional) The cms_content_tree node to add generated objects to.
  * @return cms_content_tree
  */
 public static function load_from_list($data, $parent_id = -1, cms_content_tree &$tree = null)
 {
     for ($i = 0; $i < count($data); $i++) {
         $row = $data[$i];
         if ($row['parent_id'] < $parent_id) {
             continue;
         }
         if ($row['parent_id'] > $parent_id) {
             break;
         }
         // create a tree object
         if (!is_object($tree)) {
             $tree = new cms_content_tree();
         }
         $node = new cms_content_tree(array('id' => $row['content_id'], 'alias' => $row['content_alias']));
         self::load_from_list($data, $row['content_id'], $node);
         $tree->add_node($node);
     }
     return $tree;
 }
 /**
  * Load tree from a flat, CSV encoded list.
  *
  * This function accepts an array of ASCII encoded lines like:
  * the_alias,gr_grandparent.grandparent.parent
  *
  * @internal
  * @access private
  * @param array The csv data to import
  * @param char  The delimiter separating hierarchy paths
  * @param char  The delimiter separating the node alias from the path.
  * @return cms_tree
  */
 public static function load_from_list($data, $path_delim = '.', $alias_delim = ',')
 {
     $tree = new cms_content_tree();
     $count = 0;
     $nodelist = array();
     if (!is_array($data)) {
         return $count;
     }
     for ($i = 0; $i < count($data); $i++) {
         $line =& $data[$i];
         list($path, $alias) = explode($alias_delim, $line, 2);
         $path_parts = explode($path_delim, $path);
         if (count($path_parts) == 1) {
             if (isset($node_list[$path])) {
                 continue;
             }
             $obj = new cms_content_tree(array('id' => (int) $path_parts[0], 'alias' => $alias));
             $node_list[$path] = $obj;
             $tree->add_node($obj);
         } else {
             $parent = $tree;
             for ($j = 0; $j < count($path_parts); $j++) {
                 $cur_path = implode($path_delim, array_slice($path_parts, 0, $j + 1));
                 if (isset($node_list[$cur_path])) {
                     continue;
                 }
                 $parent_id = (int) $path_parts[$j - 1];
                 $parent = $tree->find_by_tag('id', $parent_id);
                 $obj = new cms_content_tree(array('id' => (int) $path_parts[$j], 'alias' => $alias));
                 $node_list[$cur_path] = $obj;
                 $parent->add_node($obj);
             }
         }
     }
     return $tree;
 }