aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/tree/nestedset.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/tree/nestedset.php')
-rw-r--r--phpBB/phpbb/tree/nestedset.php73
1 files changed, 52 insertions, 21 deletions
diff --git a/phpBB/phpbb/tree/nestedset.php b/phpBB/phpbb/tree/nestedset.php
index 13184cf41c..7149513fd9 100644
--- a/phpBB/phpbb/tree/nestedset.php
+++ b/phpBB/phpbb/tree/nestedset.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package tree
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
*
*/
@@ -11,7 +15,7 @@ namespace phpbb\tree;
abstract class nestedset implements \phpbb\tree\tree_interface
{
- /** @var \phpbb\db\driver\driver */
+ /** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\lock\db */
@@ -52,7 +56,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
/**
* Construct
*
- * @param \phpbb\db\driver\driver $db Database connection
+ * @param \phpbb\db\driver\driver_interface $db Database connection
* @param \phpbb\lock\db $lock Lock class used to lock the table when moving forums around
* @param string $table_name Table name
* @param string $message_prefix Prefix for the messages thrown by exceptions
@@ -60,7 +64,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
* @param array $item_basic_data Array with basic item data that is stored in item_parents
* @param array $columns Array with column names to overwrite
*/
- public function __construct(\phpbb\db\driver\driver $db, \phpbb\lock\db $lock, $table_name, $message_prefix = '', $sql_where = '', $item_basic_data = array(), $columns = array())
+ public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\lock\db $lock, $table_name, $message_prefix = '', $sql_where = '', $item_basic_data = array(), $columns = array())
{
$this->db = $db;
$this->lock = $lock;
@@ -99,7 +103,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
*
* @return bool True if the lock was acquired, false if it has been acquired previously
*
- * @throws RuntimeException If the lock could not be acquired
+ * @throws \RuntimeException If the lock could not be acquired
*/
protected function acquire_lock()
{
@@ -117,7 +121,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function insert(array $additional_data)
{
@@ -172,6 +176,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
*
* @param int $item_id The item to be deleted
* @return array Item ids that have been removed
+ * @throws \OutOfBoundsException
*/
protected function remove_item_from_nestedset($item_id)
{
@@ -195,7 +200,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function delete($item_id)
{
@@ -210,7 +215,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function move($item_id, $delta)
{
@@ -328,7 +333,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function move_down($item_id)
{
@@ -336,7 +341,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function move_up($item_id)
{
@@ -344,7 +349,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function move_children($current_parent_id, $new_parent_id)
{
@@ -386,7 +391,6 @@ abstract class nestedset implements \phpbb\tree\tree_interface
throw new \OutOfBoundsException($this->message_prefix . 'INVALID_PARENT');
}
- $diff = sizeof($move_items) * 2;
$sql_exclude_moved_items = $this->db->sql_in_set($this->column_item_id, $move_items, true);
$this->db->sql_transaction('begin');
@@ -450,7 +454,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function change_parent($item_id, $new_parent_id)
{
@@ -485,7 +489,6 @@ abstract class nestedset implements \phpbb\tree\tree_interface
throw new \OutOfBoundsException($this->message_prefix . 'INVALID_PARENT');
}
- $diff = sizeof($move_items) * 2;
$sql_exclude_moved_items = $this->db->sql_in_set($this->column_item_id, $move_items, true);
$this->db->sql_transaction('begin');
@@ -549,7 +552,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function get_path_and_subtree_data($item_id, $order_asc = true, $include_item = true)
{
@@ -560,7 +563,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function get_path_data($item_id, $order_asc = true, $include_item = true)
{
@@ -570,7 +573,7 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function get_subtree_data($item_id, $order_asc = true, $include_item = true)
{
@@ -664,6 +667,32 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
/**
+ * Get all items from the tree
+ *
+ * @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 *
+ 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
*
* @param array $subset_items Subset of items to remove
@@ -806,7 +835,10 @@ abstract class nestedset implements \phpbb\tree\tree_interface
' . $this->get_sql_where('AND') . '
ORDER BY ' . $this->column_left_id . ', ' . $this->column_item_id . ' ASC';
$result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ foreach ($rows as $row)
{
// First we update the left_id for this module
if ($row[$this->column_left_id] != $new_id)
@@ -831,7 +863,6 @@ abstract class nestedset implements \phpbb\tree\tree_interface
}
$new_id++;
}
- $this->db->sql_freeresult($result);
if ($acquired_new_lock)
{