mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/11495] Use descendants and ancestors instead of parents/children
PHPBB3-11495
This commit is contained in:
parent
4810c61fd7
commit
67f2edae17
3 changed files with 29 additions and 29 deletions
|
@ -65,9 +65,9 @@ interface phpbb_tree_interface
|
||||||
public function move_up($item_id);
|
public function move_up($item_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves all children of one item to another item
|
* Moves all descendants of one item to another item
|
||||||
*
|
*
|
||||||
* If the new parent already has children, the new children are appended
|
* If the new parent already has descendants, the new descendants are appended
|
||||||
* to the list.
|
* to the list.
|
||||||
*
|
*
|
||||||
* @param int $current_parent_id The current parent item
|
* @param int $current_parent_id The current parent item
|
||||||
|
@ -88,35 +88,35 @@ interface phpbb_tree_interface
|
||||||
public function change_parent($item_id, $new_parent_id);
|
public function change_parent($item_id, $new_parent_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all items that are either a parent or part of the subtree of the item
|
* Get all items that are either an ancestors or descendants of the item
|
||||||
*
|
*
|
||||||
* @param int $item_id The item id to get the parents/children from
|
* @param int $item_id The item to get the ancestors/descendants from
|
||||||
* @param bool $order_desc Order the items descending (most outer parent first)
|
* @param bool $order_asc Order the items ascending (most outer ancestor first)
|
||||||
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
||||||
* @return array Array of items (containing all columns from the item table)
|
* @return array Array of items (containing all columns from the item table)
|
||||||
* ID => Item data
|
* ID => Item data
|
||||||
*/
|
*/
|
||||||
public function get_path_and_subtree_data($item_id, $order_desc, $include_item);
|
public function get_path_and_subtree_data($item_id, $order_asc, $include_item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all parent items of the item
|
* Get all ancestors items of the item
|
||||||
*
|
*
|
||||||
* @param int $item_id The item id to get the parents from
|
* @param int $item_id The item id to get the ancestors from
|
||||||
* @param bool $order_desc Order the items descending (most outer parent first)
|
* @param bool $order_asc Order the items ascending (most outer ancestor first)
|
||||||
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
||||||
* @return array Array of items (containing all columns from the item table)
|
* @return array Array of items (containing all columns from the item table)
|
||||||
* ID => Item data
|
* ID => Item data
|
||||||
*/
|
*/
|
||||||
public function get_path_data($item_id, $order_desc, $include_item);
|
public function get_path_data($item_id, $order_asc, $include_item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all items of the item's subtree
|
* Get all descendants of the item
|
||||||
*
|
*
|
||||||
* @param int $item_id The item id to get the children from
|
* @param int $item_id The item id to get the descendants from
|
||||||
* @param bool $order_desc Order the items descending (most outer parent first)
|
* @param bool $order_asc Order the items ascending
|
||||||
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
||||||
* @return array Array of items (containing all columns from the item table)
|
* @return array Array of items (containing all columns from the item table)
|
||||||
* ID => Item data
|
* ID => Item data
|
||||||
*/
|
*/
|
||||||
public function get_subtree_data($item_id, $order_desc, $include_item);
|
public function get_subtree_data($item_id, $order_asc, $include_item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -529,32 +529,32 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function get_path_and_subtree_data($item_id, $order_desc = true, $include_item = true)
|
public function get_path_and_subtree_data($item_id, $order_asc = true, $include_item = true)
|
||||||
{
|
{
|
||||||
$condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . '
|
$condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . '
|
||||||
OR i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id;
|
OR i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id;
|
||||||
|
|
||||||
return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item);
|
return $this->get_set_of_nodes_data($item_id, $condition, $order_asc, $include_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function get_path_data($item_id, $order_desc = true, $include_item = true)
|
public function get_path_data($item_id, $order_asc = true, $include_item = true)
|
||||||
{
|
{
|
||||||
$condition = 'i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id . '';
|
$condition = 'i1.' . $this->column_left_id . ' BETWEEN i2.' . $this->column_left_id . ' AND i2.' . $this->column_right_id . '';
|
||||||
|
|
||||||
return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item);
|
return $this->get_set_of_nodes_data($item_id, $condition, $order_asc, $include_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function get_subtree_data($item_id, $order_desc = true, $include_item = true)
|
public function get_subtree_data($item_id, $order_asc = true, $include_item = true)
|
||||||
{
|
{
|
||||||
$condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . '';
|
$condition = 'i2.' . $this->column_left_id . ' BETWEEN i1.' . $this->column_left_id . ' AND i1.' . $this->column_right_id . '';
|
||||||
|
|
||||||
return $this->get_set_of_nodes_data($item_id, $condition, $order_desc, $include_item);
|
return $this->get_set_of_nodes_data($item_id, $condition, $order_asc, $include_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -562,12 +562,12 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface
|
||||||
*
|
*
|
||||||
* @param int $item_id The item id to get the node set from
|
* @param int $item_id The item id to get the node set from
|
||||||
* @param string $condition Query string restricting the item list
|
* @param string $condition Query string restricting the item list
|
||||||
* @param bool $order_desc Order the items descending (most outer parent first)
|
* @param bool $order_asc Order the items ascending by their left_id
|
||||||
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
* @param bool $include_item Should the item (matching the given item id) be included in the list aswell
|
||||||
* @return array Array of items (containing all columns from the item table)
|
* @return array Array of items (containing all columns from the item table)
|
||||||
* ID => Item data
|
* ID => Item data
|
||||||
*/
|
*/
|
||||||
protected function get_set_of_nodes_data($item_id, $condition, $order_desc = true, $include_item = true)
|
protected function get_set_of_nodes_data($item_id, $condition, $order_asc = true, $include_item = true)
|
||||||
{
|
{
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
|
||||||
|
@ -577,7 +577,7 @@ abstract class phpbb_tree_nestedset implements phpbb_tree_interface
|
||||||
ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ')
|
ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ')
|
||||||
WHERE i1.' . $this->column_item_id . ' = ' . (int) $item_id . '
|
WHERE i1.' . $this->column_item_id . ' = ' . (int) $item_id . '
|
||||||
' . $this->get_sql_where('AND', 'i1.') . '
|
' . $this->get_sql_where('AND', 'i1.') . '
|
||||||
ORDER BY i2.' . $this->column_left_id . ' ' . ($order_desc ? 'ASC' : 'DESC');
|
ORDER BY i2.' . $this->column_left_id . ' ' . ($order_asc ? 'ASC' : 'DESC');
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
|
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
|
|
@ -34,9 +34,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne
|
||||||
/**
|
/**
|
||||||
* @dataProvider get_path_and_subtree_data_data
|
* @dataProvider get_path_and_subtree_data_data
|
||||||
*/
|
*/
|
||||||
public function test_get_path_and_subtree_data($forum_id, $order_desc, $include_item, $expected)
|
public function test_get_path_and_subtree_data($forum_id, $order_asc, $include_item, $expected)
|
||||||
{
|
{
|
||||||
$this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_desc, $include_item)));
|
$this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_asc, $include_item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_path_data_data()
|
public function get_path_data_data()
|
||||||
|
@ -62,9 +62,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne
|
||||||
/**
|
/**
|
||||||
* @dataProvider get_path_data_data
|
* @dataProvider get_path_data_data
|
||||||
*/
|
*/
|
||||||
public function test_get_path_data($forum_id, $order_desc, $include_item, $expected)
|
public function test_get_path_data($forum_id, $order_asc, $include_item, $expected)
|
||||||
{
|
{
|
||||||
$this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_desc, $include_item)));
|
$this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_asc, $include_item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_subtree_data_data()
|
public function get_subtree_data_data()
|
||||||
|
@ -90,9 +90,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne
|
||||||
/**
|
/**
|
||||||
* @dataProvider get_subtree_data_data
|
* @dataProvider get_subtree_data_data
|
||||||
*/
|
*/
|
||||||
public function test_get_subtree_data($forum_id, $order_desc, $include_item, $expected)
|
public function test_get_subtree_data($forum_id, $order_asc, $include_item, $expected)
|
||||||
{
|
{
|
||||||
$this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_desc, $include_item)));
|
$this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_asc, $include_item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_path_basic_data_data()
|
public function get_path_basic_data_data()
|
||||||
|
|
Loading…
Add table
Reference in a new issue