diff --git a/phpBB/phpbb/tree/nestedset.php b/phpBB/phpbb/tree/nestedset.php index 13184cf41c..c4ab3b0740 100644 --- a/phpBB/phpbb/tree/nestedset.php +++ b/phpBB/phpbb/tree/nestedset.php @@ -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 * diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index ca1863e55e..a0d0778e82 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -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))); + } }