Properties

$idColumnName

$idColumnName : integer

Type

integer — Identity column name in the table. This column should be primary key.

$parentIdColumnName

$parentIdColumnName : integer

Type

integer — Parent ID that refer to the ID column.

$leftColumnName

$leftColumnName : string

Type

string — Left column name in the table.

$rightColumnName

$rightColumnName : string

Type

string — Right column name in the table.

$levelColumnName

$levelColumnName : string

Type

string — Level column name in the table. The root item will be start at level 1, the sub items of the root will be increase their level.

$positionColumnName

$positionColumnName : string

Type

string — Position column name in the table. The position will be start at 1 for each level, it means the different level always start at 1.

$tableName

$tableName : string

Type

string — Table name.

$PDO

$PDO : \PDO

Type

\PDO — The PDO class instance.

Methods

__construct()

__construct(\PDO  $PDO) 

NestedSet class constructor.

Parameters

\PDO $PDO

The PDO class object.

deletePullUpChildren()

deletePullUpChildren(integer  $taxonomy_id, array  $where = array()) : boolean

Delete the selected taxonomy ID and pull children's parent ID to the same as selected one.<br> Example: selected taxonomy ID is 4, its parent ID is 2. This method will be pull all children that has parent ID = 4 to 2 and delete the taxonomy ID 4.<br> Always run <code>$NestedSet->rebuild()</code> after insert, update, delete to rebuild the correctly level, left, right data.

Parameters

integer $taxonomy_id

The selected taxonomy ID.

array $where

Where array structure will be like this.

array(
    'whereString' => '(`columnName` = :value1 AND `columnName2` = :value2)',
    'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'),
)

Returns

boolean —

Return true on success, false for otherwise.

deleteWithChildren()

deleteWithChildren(integer  $taxonomy_id, array  $where = array()) : mixed

Delete the selected taxonomy ID with its ALL children.<br> Always run <code>$NestedSet->rebuild()</code> after insert, update, delete to rebuild the correctly level, left, right data.

The columns left, right must have been built before using this method, otherwise the result will be incorrect.

Parameters

integer $taxonomy_id

The taxonomy ID to delete.

array $where

Where array structure will be like this.
parent or child is required if there are ambugious error.

array(
    'whereString' => '(`parent`.`columnName` = :value1 AND `parent`.`columnName2` = :value2)',
    'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'),
)

Returns

mixed —

Return number on success, return false for otherwise.

getNewPosition()

getNewPosition(integer  $parent_id, array  $where = array()) : integer

Get new position for taxonomy in the selected parent.

Parameters

integer $parent_id

The parent ID. If root, set this to 0.

array $where

Where array structure will be like this.

array(
    'whereString' => '(`columnName` = :value1 AND `columnName2` = :value2)',
    'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'),
)

Returns

integer —

Return the new position in the same parent.
WARNING! If there are no results or the results according to the conditions cannot be found. It always returns 1.

getTaxonomyWithChildren()

getTaxonomyWithChildren(array  $options = array()) : mixed

Get taxonomy from selected item and fetch its ALL children.<br> Example: There are taxonomy tree like this. Root 1 > 1.1 > 1.1.1, Root 2, Root 3 > 3.1, Root 3 > 3.2 > 3.2.1, Root 3 > 3.2 > 3.2.2, Root 3 > 3.3<br> Assume that selected item is Root 3. So, the result will be Root 3 > 3.1, 3.2 > 3.2.1, 3.2.2, 3.3<br>

Warning! Even this method has options for search, custom where conditions but it is recommended that you should set the option to select only specific item.
This method is intended to show results from a single target.

The columns left, right must have been built before using this method, otherwise the result will be incorrect.

Parameters

array $options

Available options:
filter_taxonomy_id (int) The filter taxonomy ID.
search (array) The search array format is..
array('columns' => array('name', 'column2', 'column3'), 'searchValue' => 'search string')
where (array) The custom where conditions. The array format is..
array('whereString' => '(`parent`.`columnName` = :value1 AND `child`.`columnName2` = :value2)', 'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'))
or just only whereString.
array('whereString' => '(`parent`.`columnName` = \'value\'))
unlimited (bool) Set to true to do not limit the result.
offset (number) The offset in the query.
limit (number) The limit number in the query.

Returns

mixed —

Return array object of taxonomy data if found, return null if not found.

getTaxonomyWithParents()

getTaxonomyWithParents(array  $options = array()) : mixed

Get taxonomy from selected item and fetch its parent in a line until root item.<br> Example: There are taxonomy tree like this. Root1 > 1.1 > 1.1.1 > 1.1.1.1<br> Assume that you selected at 1.1.1. So, the result will be Root1 > 1.1 > 1.1.1<br> But if you set 'skipCurrent' to true the result will be Root1 > 1.1

Warning! Even this method has options for search, custom where conditions but it is recommended that you should set the option to select only specific item.
This method is intended to show results from a single target.

The columns left, right must have been built before using this method, otherwise the result will be incorrect.

Parameters

array $options

Available options:
filter_taxonomy_id (int) The filter taxonomy ID.
search (array) The search array format is..
array('columns' => array('name', 'column2', 'column3'), 'searchValue' => 'search string')
where (array) The custom where conditions. The array format is..
array('whereString' => '(`node`.`columnName` = :value1 AND `node`.`columnName2` = :value2)', 'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'))
or just only whereString.
array('whereString' => '(`node`.`columnName` = \'value\'))
skipCurrent (bool) Set to true to skip currently selected item.

Returns

mixed —

Return array object of taxonomy data if found, return null if not found.

isParentUnderMyChildren()

isParentUnderMyChildren(integer  $taxonomy_id, integer  $parent_id, array  $where = array()) : boolean

Detect that is this taxonomy's parent setting to be under this taxonomy's children or not.<br> For example: Root 1 > 1.1 > 1.1.1 > 1.1.1.1 > 1.1.1.1.1<br> Assume that you editing 1.1.1 and its parent is 1.1. Now you change its parent to 1.1.1.1.1 which is under its children.<br> The parent of 1.1.1 must be root, Root 1, 1.1 and never go under that.

Parameters

integer $taxonomy_id

The taxonomy ID that is chaging the parent.

integer $parent_id

The selected parent ID to check.

array $where

Where array structure will be like this.

array(
    'whereString' => '(`node`.`columnName` = :value1 AND `node`.`columnName2` = :value2)',
    'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'),
)

Returns

boolean —

Return true if its parent is under its children (INCORRECT changes).
Return true if search result was not found (INCORRECT changes).
Return false if its parent is not under its children (CORRECT changes).

listTaxonomy()

listTaxonomy(array  $options = array()) : array

List taxonomy.

The columns left, right must have been built before using this method, otherwise the result will be incorrect.

Parameters

array $options

Available options:
filter_taxonomy_id (int) The filter taxonomy ID.
filter_parent_id (int) The filter parent ID.
search (array) The search array format is..
array('columns' => array('name', 'column2', 'column3'), 'searchValue' => 'search string')
taxonomy_id_in (array) The taxonomy ID to look with IN() MySQL function.
The array values must be integer, example array(1,3,4,5).
This will be flatten the result even list_flatten was not set.
where (array) The custom where conditions. The array format is..
array('whereString' => '(`parent`.`columnName` = :value1 AND `parent`.`columnName2` = :value2)', 'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'))
or just only whereString.
array('whereString' => '(`parent`.`columnName` = \'value\'))
no_sort_orders (bool) Set to true to do not sort order the result.
unlimited (bool) Set to true to do not limit the result.
offset (number) The offset in the query.
limit (number) The limit number in the query.
list_flatten (bool) Set to true to list the result flatten.

Returns

array —

Return array with 'total' and 'items' as keys.

listTaxonomyFlatten()

listTaxonomyFlatten(array  $options = array()) : array

List taxonomy as flatten not tree.<br> All parameters or arguments are same as `listTaxonomy()` method.

Parameters

array $options

Available options:
filter_taxonomy_id (int) The filter taxonomy ID.
filter_parent_id (int) The filter parent ID.
search (array) The search array format is..
array('columns' => array('name', 'column2', 'column3'), 'searchValue' => 'search string')
taxonomy_id_in (array) The taxonomy ID to look with IN() MySQL function.
The array values must be integer, example array(1,3,4,5).
This will be flatten the result even list_flatten was not set.
where (array) The custom where conditions. The array format is..
array('whereString' => '(`parent`.`columnName` = :value1 AND `parent`.`columnName2` = :value2)', 'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'))
or just only whereString.
array('whereString' => '(`parent`.`columnName` = \'value\'))
no_sort_orders (bool) Set to true to do not sort order the result.
unlimited (bool) Set to true to do not limit the result.
offset (number) The offset in the query.
limit (number) The limit number in the query.
list_flatten (bool) Set to true to list the result flatten.

Returns

array —

Return array with 'total' and 'items' as keys.

rebuild()

rebuild(array  $where = array()) 

Rebuilds the tree data and save it to the database.<br> This will be rebuild the level, left, right values.

The columns left, right must have been built before using this method, otherwise the result will be incorrect.

Parameters

array $where

Where array structure will be like this.

array(
    'whereString' => '(`columnName` = :value1 AND `columnName2` = :value2)',
    'whereValues' => array(':value1' => 'lookup value 1', ':value2' => 'lookup value2'),
)

restoreColumnsName()

restoreColumnsName() : void

Restore the columns name to its default property's value.