Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-12117

Nested Set Tree Classes Should be able to get all roots

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • 3.1.0-b1
    • 3.1.0-dev
    • Other
    • None

      The nested set tree class does not seem to have a function to allow one to retrieve all entries in a table using trees. It only seems to allow access to sub-trees. In other words, can it get the entire tree, all roots/parents and all children, just as a general function (not based on any particular supplied item_id)?

      Using $this->get_subtree_data(0, $order_asc, $include_item); as suggested, does not work, because 0 returns nothing if it is used as the item_id, and if you use an overwrite, i.e.: $this->column_item_id = 'parent_id' to make 0 refer to the parent_id in the SQL generated by get_set_of_nodes_data(), it still fails, because that function returns an array $rows[(int) $row[$this->column_item_id]] = $row; in which each $row has the same parent_id key, so you only end up with one parent + one child in the end.

      To get the entire tree of data, should it have a basic way to get everything, similar to:

      SELECT * FROM table ORDER_BY left_id

      More specifically, a function something like this does what we (naderman, EXreaction and myself) were sort of intending:

      public function get_tree_data($order_asc = true)
      {
      	$rows = array();
       
      	$sql = 'SELECT ' . implode(', ', $this->item_basic_data) . '
      		FROM ' . $this->table_name . ' ' .
      		$this->get_sql_where('WHERE') . '
      		ORDER BY ' . $this->column_left_id . ' ' . ($order_asc ? 'ASC' : 'DESC');
      	$result = $this->db->sql_query($sql);
       
      	while ($row = $this->db->sql_fetchrow($result))
      	{
      		$rows[(int) $row[$this->column_item_id]] = $row;
      	}
      	$this->db->sql_freeresult($result);
       
      	return $rows;
      }
      

            EXreaction EXreaction [X] (Inactive)
            VSE Matt Friedman [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: