class NestedRecord extends Record (View source)

The NestedRecord class.

Constants

DUMP_ALL_DATA

UPDATE_NULLS

LOAD_DEFAULT

LOCATION_BEFORE

LOCATION_AFTER

LOCATION_FIRST_CHILD

LOCATION_LAST_CHILD

Methods

__construct(string $table = null, mixed $keys = 'id', AbstractDataMapper $mapper = null)

Object constructor to set table and key fields. In most cases this will be overridden by child classes to explicitly set the table and key fields for a particular database table.

from Record
bind(mixed $src, boolean $replaceNulls = false)

Method to bind an associative array or object to the AbstractTable instance. This method only binds properties that are publicly accessible and optionally takes an array of properties to ignore when binding.

from Record
set(string $key, mixed $value = null)

Magic setter to set a table field.

from Entity
mixed
get(string $key, mixed $default = null)

Magic getter to get a table field.

from Entity
boolean
exists(string $field)

Method to check a field exists.

from Entity
void
__set(string $field, mixed $value = null)

Set value.

from Entity
boolean
__isset(string $name)

__isset

from Entity
mixed
__get(string $field)

Get value.

from Entity
void
__unset(string $name)

__unset

from Entity
getIterator(bool $all = false)

Get an iterator object.

from Entity
boolean
offsetExists(mixed $offset)

Is a property exists or not.

from Entity
mixed
offsetGet(mixed $offset)

Get a property.

from Entity
void
offsetSet(mixed $offset, mixed $value)

Set a value to property.

from Entity
void
offsetUnset(mixed $offset)

Unset a property.

from Entity
int
count()

Count this object.

from Entity
boolean
isNull()

Is this object empty?

from Entity
boolean
notNull()

Is this object has properties?

from Data
array
dump(bool $all = false)

Dump all data as array

from Entity
map(callable $callback)

Mapping all elements.

from Data
walk(callable $callback, mixed $userdata = null)

Apply a user supplied function to every member of this object.

from Data
void
__clone()

Clone this object.

from Data
getFields(bool $reset = false)

loadFields

from Record
addField(string $field, string $default = null)

addField

from Entity
addFields(array $fields)

Add a field to this entity.

from Entity
removeField(string $field)

Remove field from this entity.

from Entity
boolean
hasField(string $name)

Method to check a field exists or not.

from Entity
setAlias(string $name, string $alias)

Set column alias.

from Entity
string
resolveAlias(string $name)

Resolve alias.

from Entity
reset(bool $loadDefault = true)

Method to reset class properties to the defaults set in the class definition. It will ignore the primary key as well as any private class properties (except $_errors).

$this
save(mixed $src, boolean $updateNulls = false)

Method to provide a shortcut to binding, checking and storing a AbstractTable instance to the database table. The method will check a row in once the data has been stored and if an ordering filter is present will attempt to reorder the table rows based on the filter. The ordering filter is an instance property name. The rows that will be reordered are those whose value matches the AbstractTable instance for the property specified.

from Record
load(mixed $keys = null, boolean $reset = true)

Method to load a row from the database by primary key and bind the fields to the AbstractTable instance properties.

from Record
delete(integer $pk = null, boolean $children = true)

Method to delete a node and, optionally, its child nodes from the table.

validate()

Checks that the object is valid and able to be stored.

store(boolean $updateNulls = false)

Method to store a node in the database table.

create()

create

from Record
update(bool $updateNulls = false)

update

from Record
string
getTableName()

Get the table name.

from Record
setTableName(string $table)

Method to set property table

from Record
array|mixed
getKeyName(boolean $multiple = false)

Method to get the primary key field name for the table.

from Record
boolean
hasPrimaryKey()

Validate that the primary key has been set.

from Record
bool
valueExists(string $field, null $value = null)

Check a field value exists in database or not, to keep a field unique.

from Record
triggerEvent(string|Event $event, array $args = array())

triggerEvent

from Record
getDispatcher()

Method to get property Dispatcher

from Record
setDispatcher(DispatcherInterface $dispatcher)

Method to set property dispatcher

from Record
loadDefault(bool $replace = false)

loadDefault

from Record
getDataMapper()

Method to get property Mapper

from Record
setDataMapper(AbstractDataMapper $mapper)

Method to set property mapper

from Record
mixed
getPath(integer $pk = null, boolean $allFields = false)

Method to get an array of nodes from a given node to its root.

mixed
getTree(integer $pk = null, boolean $allFields = false)

Method to get a node and all its child nodes.

boolean
isLeaf(integer $pk = null)

Method to determine if a node is a leaf node in the tree (has no children).

setLocation(integer $referenceId, integer $position = self::LOCATION_AFTER)

Method to set the location of a node in the tree object. This method does not save the new location to the database, but will set it in the object so that when the node is stored it will be stored in the new location.

mixed
move(integer $delta, string $where = '')

Method to move a row in the ordering sequence of a group of rows defined by an SQL WHERE clause.

boolean
moveByReference(integer $referenceId, integer $position = self::LOCATION_AFTER, integer $pk = null)

Method to move a node and its children to a new location in the tree.

mixed
getRootId()

Gets the ID of the root item in the tree

integer
rebuild(integer $parentId = null, integer $leftId, integer $level, string $path = '')

Method to recursively rebuild the whole nested set tree.

boolean
rebuildPath(integer $pk = null)

Method to rebuild the node's path field from the alias values of the nodes from the current node to the root node of the tree.

boolean
createRoot()

createRoot

Details

in Record at line line 118
__construct(string $table = null, mixed $keys = 'id', AbstractDataMapper $mapper = null)

Object constructor to set table and key fields. In most cases this will be overridden by child classes to explicitly set the table and key fields for a particular database table.

Parameters

string $table Name of the table to model.
mixed $keys Name of the primary key field in the table or array of field names that compose the primary key.
AbstractDataMapper $mapper The DataMapper Adapter to access database.

in Record at line line 185
Data bind(mixed $src, boolean $replaceNulls = false)

Method to bind an associative array or object to the AbstractTable instance. This method only binds properties that are publicly accessible and optionally takes an array of properties to ignore when binding.

Parameters

mixed $src An associative array or object to bind to the AbstractTable instance.
boolean $replaceNulls Replace null or not.

Return Value

Data Return self to support chaining.

in Entity at line line 291
Data set(string $key, mixed $value = null)

Magic setter to set a table field.

Parameters

string $key The key name.
mixed $value The value to set.

Return Value

Data Return self to support chaining.

Exceptions

InvalidArgumentException

in Entity at line line 310
mixed get(string $key, mixed $default = null)

Magic getter to get a table field.

Parameters

string $key The key name.
mixed $default The default value if not exists.

Return Value

mixed The value we want ot get.

in Entity at line line 391
boolean exists(string $field)

Method to check a field exists.

Parameters

string $field The field name to check.

Return Value

boolean True if exists.

in Entity at line line 250
void __set(string $field, mixed $value = null)

Set value.

Parameters

string $field The field to set.
mixed $value The value to set.

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 236
boolean __isset(string $name)

__isset

Parameters

string $name

Return Value

boolean

in Entity at line line 262
mixed __get(string $field)

Get value.

Parameters

string $field The field to get.

Return Value

mixed

in Entity at line line 275
void __unset(string $name)

__unset

Parameters

string $name

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 185
Traversable getIterator(bool $all = false)

Get an iterator object.

Parameters

bool $all

Return Value

Traversable An instance of an object implementing Iterator or Traversable

in Entity at line line 329
boolean offsetExists(mixed $offset)

Is a property exists or not.

Parameters

mixed $offset Offset key.

Return Value

boolean

in Entity at line line 342
mixed offsetGet(mixed $offset)

Get a property.

Parameters

mixed $offset Offset key.

Return Value

mixed The value to return.

Exceptions

InvalidArgumentException

in Entity at line line 356
void offsetSet(mixed $offset, mixed $value)

Set a value to property.

Parameters

mixed $offset Offset key.
mixed $value The value to set.

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 369
void offsetUnset(mixed $offset)

Unset a property.

Parameters

mixed $offset Offset key to unset.

Return Value

void

Exceptions

InvalidArgumentException

in Entity at line line 379
int count()

Count this object.

Return Value

int

in Entity at line line 401
boolean isNull()

Is this object empty?

Return Value

boolean

in Data at line line 281
boolean notNull()

Is this object has properties?

Return Value

boolean

in Entity at line line 421
array dump(bool $all = false)

Dump all data as array

Parameters

bool $all

Return Value

array

in Data at line line 305
Data map(callable $callback)

Mapping all elements.

Parameters

callable $callback Callback to handle every element.

Return Value

Data Support chaining.

in Data at line line 325
Data walk(callable $callback, mixed $userdata = null)

Apply a user supplied function to every member of this object.

Parameters

callable $callback Callback to handle every element.
mixed $userdata This will be passed as the third parameter to the callback.

Return Value

Data Support chaining.

in Data at line line 344
void __clone()

Clone this object.

Return Value

void

in Record at line line 486
stdClass[] getFields(bool $reset = false)

loadFields

Parameters

bool $reset

Return Value

stdClass[]

in Entity at line line 90
Entity addField(string $field, string $default = null)

addField

Parameters

string $field
string $default

Return Value

Entity

in Entity at line line 137
Entity addFields(array $fields)

Add a field to this entity.

Parameters

array $fields Fields array.

Return Value

Entity Return self to support chaining.

in Entity at line line 154
Entity removeField(string $field)

Remove field from this entity.

Parameters

string $field Field name.

Return Value

Entity Return self to support chaining.

in Entity at line line 170
boolean hasField(string $name)

Method to check a field exists or not.

Parameters

string $name

Return Value

boolean

in Entity at line line 198
Entity setAlias(string $name, string $alias)

Set column alias.

Parameters

string $name
string $alias

Return Value

Entity

in Entity at line line 219
string resolveAlias(string $name)

Resolve alias.

Parameters

string $name

Return Value

string

at line line 871
Entity reset(bool $loadDefault = true)

Method to reset class properties to the defaults set in the class definition. It will ignore the primary key as well as any private class properties (except $_errors).

Parameters

bool $loadDefault

Return Value

Entity

Exceptions

InvalidArgumentException

in Record at line line 162
$this save(mixed $src, boolean $updateNulls = false)

Method to provide a shortcut to binding, checking and storing a AbstractTable instance to the database table. The method will check a row in once the data has been stored and if an ordering filter is present will attempt to reorder the table rows based on the filter. The ordering filter is an instance property name. The rows that will be reordered are those whose value matches the AbstractTable instance for the property specified.

Parameters

mixed $src An associative array or object to bind to the AbstractTable instance.
boolean $updateNulls True to update fields even if they are null.

Return Value

$this Method allows chaining

in Record at line line 248
Record load(mixed $keys = null, boolean $reset = true)

Method to load a row from the database by primary key and bind the fields to the AbstractTable instance properties.

Parameters

mixed $keys An optional primary key value to load the row by, or an array of fields to match. If not set the instance property value is used.
boolean $reset True to reset the default values before loading the new row.

Return Value

Record Method allows chaining

Exceptions

RuntimeException
UnexpectedValueException
InvalidArgumentException

at line line 554
Record delete(integer $pk = null, boolean $children = true)

Method to delete a node and, optionally, its child nodes from the table.

Parameters

integer $pk The primary key of the node to delete.
boolean $children True to delete child nodes, false to move them up a level.

Return Value

Record Method allows chaining

at line line 175
Record validate()

Checks that the object is valid and able to be stored.

This method checks that the parentid is non-zero and exists in the database. Note that the root node (parentid = 0) cannot be manipulated with this class.

Return Value

Record Method allows chaining

Exceptions

Exception
RuntimeException on database error.
UnexpectedValueException

at line line 240
Record store(boolean $updateNulls = false)

Method to store a node in the database table.

Parameters

boolean $updateNulls True to update fields even if they are null.

Return Value

Record Method allows chaining

in Record at line line 404
Record create()

create

Return Value

Record

in Record at line line 429
Record update(bool $updateNulls = false)

update

Parameters

bool $updateNulls

Return Value

Record

in Record at line line 460
string getTableName()

Get the table name.

Return Value

string

in Record at line line 472
Record setTableName(string $table)

Method to set property table

Parameters

string $table

Return Value

Record Return self to support chaining.

in Record at line line 513
array|mixed getKeyName(boolean $multiple = false)

Method to get the primary key field name for the table.

Parameters

boolean $multiple True to return all primary keys (as an array) or false to return just the first one (as a string).

Return Value

array|mixed Array of primary key field names or string containing the first primary key field.

in Record at line line 532
boolean hasPrimaryKey()

Validate that the primary key has been set.

Return Value

boolean True if the primary key(s) have been set.

in Record at line line 565
bool valueExists(string $field, null $value = null)

Check a field value exists in database or not, to keep a field unique.

Parameters

string $field The field name to check.
null $value

Return Value

bool

in Record at line line 608
Event triggerEvent(string|Event $event, array $args = array())

triggerEvent

Parameters

string|Event $event
array $args

Return Value

Event

in Record at line line 638
DispatcherInterface getDispatcher()

Method to get property Dispatcher

Return Value

DispatcherInterface

in Record at line line 662
Record setDispatcher(DispatcherInterface $dispatcher)

Method to set property dispatcher

Parameters

DispatcherInterface $dispatcher

Return Value

Record Return self to support chaining.

in Record at line line 700
Record loadDefault(bool $replace = false)

loadDefault

Parameters

bool $replace

Return Value

Record

in Record at line line 718
AbstractDataMapper getDataMapper()

Method to get property Mapper

Return Value

AbstractDataMapper

in Record at line line 735
Record setDataMapper(AbstractDataMapper $mapper)

Method to set property mapper

Parameters

AbstractDataMapper $mapper

Return Value

Record Return self to support chaining.

at line line 83
mixed getPath(integer $pk = null, boolean $allFields = false)

Method to get an array of nodes from a given node to its root.

Parameters

integer $pk Primary key of the node for which to get the path.
boolean $allFields Get all fields.

Return Value

mixed An array of node objects including the start node.

at line line 114
mixed getTree(integer $pk = null, boolean $allFields = false)

Method to get a node and all its child nodes.

Parameters

integer $pk Primary key of the node for which to get the tree.
boolean $allFields Get all fields.

Return Value

mixed Boolean false on failure or array of node objects on success.

at line line 145
boolean isLeaf(integer $pk = null)

Method to determine if a node is a leaf node in the tree (has no children).

Parameters

integer $pk Primary key of the node to check.

Return Value

boolean True if a leaf node, false if not or null if the node does not exist.

Exceptions

RuntimeException on database error.

at line line 209
NestedRecord setLocation(integer $referenceId, integer $position = self::LOCATION_AFTER)

Method to set the location of a node in the tree object. This method does not save the new location to the database, but will set it in the object so that when the node is stored it will be stored in the new location.

Parameters

integer $referenceId The primary key of the node to reference new location by.
integer $position Location type string. ['before', 'after', 'first-child', 'last-child']

Return Value

NestedRecord

Exceptions

InvalidArgumentException

at line line 348
mixed move(integer $delta, string $where = '')

Method to move a row in the ordering sequence of a group of rows defined by an SQL WHERE clause.

Negative numbers move the row up in the sequence and positive numbers move it down.

Parameters

integer $delta The direction and magnitude to move the row in the ordering sequence.
string $where WHERE clause to use for limiting the selection of rows to compact the ordering values.

Return Value

mixed Boolean true on success.

at line line 401
boolean moveByReference(integer $referenceId, integer $position = self::LOCATION_AFTER, integer $pk = null)

Method to move a node and its children to a new location in the tree.

Parameters

integer $referenceId The primary key of the node to reference new location by.
integer $position Location type string. ['before', 'after', 'first-child', 'last-child']
integer $pk The primary key of the node to move.

Return Value

boolean True on success.

Exceptions

RuntimeException on database error.

at line line 654
mixed getRootId()

Gets the ID of the root item in the tree

Return Value

mixed The primary id of the root row, or false if not found and the internal error is set.

at line line 706
integer rebuild(integer $parentId = null, integer $leftId, integer $level, string $path = '')

Method to recursively rebuild the whole nested set tree.

Parameters

integer $parentId The root of the tree to rebuild.
integer $leftId The left id to start with in building the tree.
integer $level The level to assign to the current nodes.
string $path The path to the current nodes.

Return Value

integer 1 + value of root rgt on success, false on failure

Exceptions

RuntimeException on database error.

at line line 785
boolean rebuildPath(integer $pk = null)

Method to rebuild the node's path field from the alias values of the nodes from the current node to the root node of the tree.

Parameters

integer $pk Primary key of the node for which to get the path.

Return Value

boolean True on success.

at line line 838
boolean createRoot()

createRoot

Return Value

boolean