mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/12117] Add get_all_tree_data method to tree class
PHPBB3-12117
This commit is contained in:
parent
c169583dc3
commit
c1115d9451
2 changed files with 44 additions and 0 deletions
|
@ -663,6 +663,34 @@ abstract class nestedset implements \phpbb\tree\tree_interface
|
|||
return $parents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all items from the tree
|
||||
*
|
||||
* Basic data is defined in the $item_basic_data property.
|
||||
*
|
||||
* @param bool $order_asc Order the items ascending by their left_id
|
||||
* @return array Array of items (containing all columns from the item table)
|
||||
* ID => Item data
|
||||
*/
|
||||
public function get_all_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a subset from the nested set
|
||||
*
|
||||
|
|
|
@ -116,4 +116,20 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne
|
|||
$forum_data['forum_parents'] = $forum_parents;
|
||||
$this->assertEquals($expected, array_keys($this->set->get_path_basic_data($forum_data)));
|
||||
}
|
||||
|
||||
public function get_all_tree_data_data()
|
||||
{
|
||||
return array(
|
||||
array(true, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)),
|
||||
array(false, array(11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider get_all_tree_data_data
|
||||
*/
|
||||
public function test_get_all_tree_data($order_asc, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, array_keys($this->set->get_all_tree_data($order_asc)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue