phpBB API Documentation
Class

phpbb\tree\nestedset_forum

class nestedset_forum extends nestedset

Methods

__construct(driver_interface $db, db $lock, string $table_name)

Construct

string get_sql_where(string $operator = 'AND', string $column_prefix = '')

Returns additional sql where restrictions

from nestedset
array insert(array $additional_data)

Inserts an item into the database table and into the tree.

from nestedset
array delete(int $item_id)

Delete an item from the tree and from the database table

from nestedset
bool move(int $item_id, int $delta)

Move an item by a given delta

from nestedset
bool move_down(int $item_id)

Move an item down by 1

from nestedset
bool move_up(int $item_id)

Move an item up by 1

from nestedset
bool move_children(int $current_parent_id, int $new_parent_id)

Moves all children of one item to another item

from nestedset
bool change_parent(int $item_id, int $new_parent_id)

Change parent item

from nestedset
array get_path_and_subtree_data(int $item_id, bool $order_asc = true, bool $include_item = true)

Get all items that are either ancestors or descendants of the item

from nestedset
array get_path_data(int $item_id, bool $order_asc = true, bool $include_item = true)

Get all of the item's ancestors

from nestedset
array get_subtree_data(int $item_id, bool $order_asc = true, bool $include_item = true)

Get all of the item's descendants

from nestedset
array get_path_basic_data(array $item)

Get basic data of all parent items

from nestedset
array get_all_tree_data(bool $order_asc = true)

Get all items from the tree

from nestedset
regenerate_left_right_ids(int $new_id, int $parent_id, bool $reset_ids = false)

Regenerate left/right ids from parent/child relationship

from nestedset

Details

at line 25
public __construct(driver_interface $db, db $lock, string $table_name)

Construct

Parameters

driver_interface $db Database connection
db $lock Lock class used to lock the table when moving forums around
string $table_name Table name

in nestedset at line 96
public string get_sql_where(string $operator = 'AND', string $column_prefix = '')

Returns additional sql where restrictions

Parameters

string $operator SQL operator that needs to be prepended to sql_where, if it is not empty.
string $column_prefix Prefix that needs to be prepended to column names

Return Value

string Returns additional where statements to narrow down the tree, prefixed with operator and prepended column_prefix to column names

in nestedset at line 126
public array insert(array $additional_data)

Inserts an item into the database table and into the tree.

Parameters

array $additional_data The item to be added

Return Value

array Array with item data as set in the database

in nestedset at line 205
public array delete(int $item_id)

Delete an item from the tree and from the database table

Also deletes the subtree from the tree and from the database table

Parameters

int $item_id The item to be deleted

Return Value

array Item ids that have been deleted

in nestedset at line 220
public bool move(int $item_id, int $delta)

Move an item by a given delta

An item is only moved up/down within the same parent. If the delta is larger then the number of children, the item is moved to the top/bottom of the list of children within this parent.

Parameters

int $item_id The item to be moved
int $delta Number of steps to move this item, < 0 => down, > 0 => up

Return Value

bool True if the item was moved

in nestedset at line 338
public bool move_down(int $item_id)

Move an item down by 1

Parameters

int $item_id The item to be moved

Return Value

bool True if the item was moved

in nestedset at line 346
public bool move_up(int $item_id)

Move an item up by 1

Parameters

int $item_id The item to be moved

Return Value

bool True if the item was moved

in nestedset at line 354
public bool move_children(int $current_parent_id, int $new_parent_id)

Moves all children of one item to another item

If the new parent already has children, the new children are appended to the list.

Parameters

int $current_parent_id The current parent item
int $new_parent_id The new parent item

Return Value

bool True if any items where moved

in nestedset at line 460
public bool change_parent(int $item_id, int $new_parent_id)

Change parent item

Moves the item to the bottom of the new \parent's list of children

Parameters

int $item_id The item to be moved
int $new_parent_id The new parent item

Return Value

bool True if the parent was set successfully

in nestedset at line 559
public array get_path_and_subtree_data(int $item_id, bool $order_asc = true, bool $include_item = true)

Get all items that are either ancestors or descendants of the item

Parameters

int $item_id Id of the item to retrieve the ancestors/descendants from
bool $order_asc Order the items ascendingly (most outer ancestor first)
bool $include_item Should the item matching the given item id be included in the list as well

Return Value

array Array of items (containing all columns from the item table) ID => Item data

in nestedset at line 570
public array get_path_data(int $item_id, bool $order_asc = true, bool $include_item = true)

Get all of the item's ancestors

Parameters

int $item_id Id of the item to retrieve the ancestors from
bool $order_asc Order the items ascendingly (most outer ancestor first)
bool $include_item Should the item matching the given item id be included in the list as well

Return Value

array Array of items (containing all columns from the item table) ID => Item data

in nestedset at line 580
public array get_subtree_data(int $item_id, bool $order_asc = true, bool $include_item = true)

Get all of the item's descendants

Parameters

int $item_id Id of the item to retrieve the descendants from
bool $order_asc Order the items ascendingly
bool $include_item Should the item matching the given item id be included in the list as well

Return Value

array Array of items (containing all columns from the item table) ID => Item data

in nestedset at line 634
public array get_path_basic_data(array $item)

Get basic data of all parent items

Basic data is defined in the $itembasicdata property. Data is cached in the item_parents column in the item table

Parameters

array $item The item to get the path from

Return Value

array Array of items (containing basic columns from the item table) ID => Item data

in nestedset at line 678
public array get_all_tree_data(bool $order_asc = true)

Get all items from the tree

Parameters

bool $order_asc Order the items ascending by their left_id

Return Value

array Array of items (containing all columns from the item table) ID => Item data

in nestedset at line 807
public regenerate_left_right_ids(int $new_id, int $parent_id, bool $reset_ids = false)

Regenerate left/right ids from parent/child relationship

This method regenerates the left/right ids for the tree based on the parent/child relations. This function executes three queries per item, so it should only be called, when the set has one of the following problems: - The set has a duplicated value inside the left/right id chain - The set has a missing value inside the left/right id chain - The set has items that do not have a left/right id set

When regenerating the items, the items are sorted by parent id and their current left id, so the current child/parent relationships are kept and running the function on a working set will not change the order.

Parameters

int $new_id First left_id to be used (should start with 1)
int $parent_id parent_id of the current set (default = 0)
bool $reset_ids Should we reset all leftid/rightid on the first call?