1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-11 18:15:20 +02:00

[ticket/11495] Use item_id only as parameter for get_branch_data()

PHPBB3-11495
This commit is contained in:
Joas Schilling 2013-04-19 16:18:03 +02:00
parent f3ff8b36be
commit d24ff2329f
3 changed files with 10 additions and 17 deletions

View File

@ -115,14 +115,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface
*/
public function remove(array $item)
{
if ($item[$this->column_right_id] - $item[$this->column_left_id] > 1)
{
$items = array_keys($this->get_branch_data($item, 'children'));
}
else
{
$items = array((int) $item[$this->column_item_id]);
}
$items = array_keys($this->get_branch_data($item[$this->column_item_id], 'children'));
$this->remove_subset($items, $item);
@ -282,7 +275,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface
throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE');
}
$move_items = array_keys($this->get_branch_data($current_parent, 'children', true, false));
$move_items = array_keys($this->get_branch_data((int) $current_parent[$this->column_item_id], 'children', true, false));
if (in_array($new_parent[$this->column_item_id], $move_items))
{
@ -363,7 +356,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface
throw new phpbb_nestedset_exception($this->message_prefix . 'LOCK_FAILED_ACQUIRE');
}
$move_items = array_keys($this->get_branch_data($item, 'children'));
$move_items = array_keys($this->get_branch_data((int) $item[$this->column_item_id], 'children'));
if (in_array($new_parent[$this->column_item_id], $move_items))
{
@ -437,7 +430,7 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface
/**
* @inheritdoc
*/
public function get_branch_data(array $item, $type = 'all', $order_desc = true, $include_item = true)
public function get_branch_data($item_id, $type = 'all', $order_desc = true, $include_item = true)
{
switch ($type)
{
@ -461,14 +454,14 @@ abstract class phpbb_nestedset_base implements phpbb_nestedset_interface
FROM ' . $this->table_name . ' i1
LEFT JOIN ' . $this->table_name . " i2
ON (($condition) " . $this->get_sql_where('AND', 'i2.') . ')
WHERE i1.' . $this->column_item_id . ' = ' . (int) $item[$this->column_item_id] . '
WHERE i1.' . $this->column_item_id . ' = ' . (int) $item_id . '
' . $this->get_sql_where('AND', 'i1.') . '
ORDER BY i2.' . $this->column_left_id . ' ' . ($order_desc ? 'ASC' : 'DESC');
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if (!$include_item && $item[$this->column_item_id] == $row[$this->column_item_id])
if (!$include_item && $item_id == $row[$this->column_item_id])
{
continue;
}

View File

@ -101,19 +101,19 @@ interface phpbb_nestedset_interface
*
* This method can return all parents, children or both of the given item
*
* @param array $item The item to get the branch from
* @param int $item_id The item id to get the parents from
* @param string $type One of all|parent|children
* @param bool $order_desc Order the items descending (most outer parent first)
* @param bool $include_item Should the given item be included in the list aswell
* @return array Array of items (containing all columns from the item table)
* ID => Item data
*/
public function get_branch_data(array $item, $type, $order_desc, $include_item);
public function get_branch_data($item_id, $type, $order_desc, $include_item);
/**
* Get base information of parent items
*
* @param array $item The item to get the parents from
* @param array $item The item to get the branch from
* @return array Array of items (containing basic columns from the item table)
* ID => Item data
*/

View File

@ -66,7 +66,7 @@ class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedse
*/
public function test_get_branch_data($forum_id, $type, $order_desc, $include_item, $expected)
{
$this->assertEquals($expected, array_keys($this->set->get_branch_data($this->forum_data[$forum_id], $type, $order_desc, $include_item)));
$this->assertEquals($expected, array_keys($this->set->get_branch_data($forum_id, $type, $order_desc, $include_item)));
}
public function get_parent_data_data()