nestedset
abstract class nestedset implements tree_interface
Properties
protected driver_interface | $db | ||
protected db | $lock | ||
protected string | $table_name | ||
protected string | $message_prefix | Prefix for the language keys returned by exceptions |
|
protected string | $column_item_id | Column names in the table |
|
protected | $column_left_id | ||
protected | $column_right_id | ||
protected | $column_parent_id | ||
protected | $column_item_parents | ||
protected string | $sql_where | Additional SQL restrictions Allows to have multiple nested sets in one table |
|
protected array | $item_basic_data | List of item properties to be cached in the item_parents column |
Methods
Construct
Returns additional sql where restrictions
Acquires a lock on the item table
Inserts an item into the database table and into the tree.
Add an item which already has a database row at the end of the tree
Remove an item from the tree without deleting it from the database
Delete an item from the tree and from the database table
Move an item by a given delta
Move an item down by 1
Move an item up by 1
Moves all children of one item to another item
Change parent item
Get all items that are either ancestors or descendants of the item
Get all of the item's ancestors
Get all of the item's descendants
Get items that are related to the given item by the condition
Get basic data of all parent items
Get all items from the tree
Remove a subset from the nested set
Prepare adding a subset to the nested set
Resets values required for the nested set system
Regenerate left/right ids from parent/child relationship
Details
at line 67
__construct(driver_interface $db, db $lock, string $table_name, string $message_prefix = '', string $sql_where = '', array $item_basic_data = array(), array $columns = array())
Construct
at line 96
string
get_sql_where(string $operator = 'AND', string $column_prefix = '')
Returns additional sql where restrictions
at line 108
protected bool
acquire_lock()
Acquires a lock on the item table
at line 126
array
insert(array $additional_data)
Inserts an item into the database table and into the tree.
at line 145
protected array
add_item_to_nestedset(int $item_id)
Add an item which already has a database row at the end of the tree
at line 181
protected array
remove_item_from_nestedset(int $item_id)
Remove an item from the tree without deleting it from the database
Also removes all subitems from the tree without deleting them from the database either
at line 205
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
at line 220
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.
at line 338
bool
move_down(int $item_id)
Move an item down by 1
at line 346
bool
move_up(int $item_id)
Move an item up by 1
at line 354
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.
at line 459
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
at line 557
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
at line 568
array
get_path_data(int $item_id, bool $order_asc = true, bool $include_item = true)
Get all of the item's ancestors
at line 578
array
get_subtree_data(int $item_id, bool $order_asc = true, bool $include_item = true)
Get all of the item's descendants
at line 595
protected array
get_set_of_nodes_data(int $item_id, string $condition, bool $order_asc = true, bool $include_item = true)
Get items that are related to the given item by the condition
at line 632
array
get_path_basic_data(array $item)
Get basic data of all parent items
Basic data is defined in the $item_basic_data property. Data is cached in the item_parents column in the item table
at line 676
array
get_all_tree_data(bool $order_asc = true)
Get all items from the tree
at line 705
protected null
remove_subset(array $subset_items, array $bounding_item, bool $set_subset_zero = true)
Remove a subset from the nested set
at line 747
protected int
prepare_adding_subset(array $subset_items, array $new_parent)
Prepare adding a subset to the nested set
at line 771
protected array
reset_nestedset_values(array $item)
Resets values required for the nested set system
at line 805
int
regenerate_left_right_ids(int $new_id, int $parent_id = 0, 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.