The Horde_DataTree_Sql class provides an SQL implementation of the Horde
DataTree system.
Required parameters:
'phptype' The database type (ie. 'pgsql', 'mysql', etc.).
'charset' The charset used by the database.
Optional parameters:
'table' The name of the data table in 'database'.
DEFAULT: 'horde_datatree'
Required by some database implementations:
'database' The name of the database.
'username' The username with which to connect to the database.
'password' The password associated with 'username'.
'hostspec' The hostname of the database server.
'protocol' The communication protocol ('tcp', 'unix', etc.).
'options' Additional options to pass to the database.
'port' The port on which to connect to the database.
'tty' The TTY on which to connect to the database.
Optional values when using separate reading and writing servers, for example
in replication settings:
'splitread' Boolean, whether to implement the separation or not.
'read' Array containing the parameters which are different for
the read database connection, currently supported
only 'hostspec' and 'port' parameters.
The table structure for the Horde_DataTree system is in
scripts/sql/horde_datatree.sql.
Copyright 1999-2012 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If
you did not receive this file, see
http://www.horde.org/licenses/lgpl21.
Methods summary
public
array
|
#
getGroups( )
Returns a list of all groups (root nodes) of the data tree.
Returns a list of all groups (root nodes) of the data tree.
Returns
array The the group IDs
Overrides
|
public
mixed
|
#
_load( string $root = DATATREE_ROOT, boolean $loadTree = false, boolean $reload = false, string $sortby_name = null, string $sortby_key = null, integer $direction = 0 )
Loads (a subset of) the datatree into the $_data array.
Loads (a subset of) the datatree into the $_data array.
Parameters
- $root
- <p>Which portion of the tree to load.
Defaults to all of it.</p>
- $loadTree
- <p>Load a tree starting at $root, or just the
requested level and direct parents?
Defaults to single level.</p>
- $reload
- Re-load already loaded values?
- $sortby_name
- Attribute name to use for sorting.
- $sortby_key
- Attribute key to use for sorting.
- $direction
- <p>Sort direction:
0 - ascending
1 - descending</p>
Returns
mixed True on success or a PEAR_Error on failure.
|
public
integer
|
#
_count( string $root = DATATREE_ROOT )
Counts (a subset of) the datatree which would be loaded into the $_data
array if _load() is called with the same value of $root.
Counts (a subset of) the datatree which would be loaded into the $_data
array if _load() is called with the same value of $root.
Parameters
- $root
- <p>Which portion of the tree to load. Defaults to all
of it.</p>
Returns
integer Number of objects
|
public
mixed
|
#
_buildLoadQuery( string $root = DATATREE_ROOT, boolean $loadTree = false, integer $operation = DATATREE_BUILD_SELECT, string $sortby_name = null, string $sortby_key = null, integer $direction = 0 )
Loads (a subset of) the datatree into the $_data array.
Loads (a subset of) the datatree into the $_data array.
Parameters
- $root
- <p>Which portion of the tree to load.
Defaults to all of it.</p>
- $loadTree
- <p>Load a tree starting at $root, or just the
requested level and direct parents?
Defaults to single level.</p>
- $operation
- Type of query to build
- $sortby_name
- Attribute name to use for sorting.
- $sortby_key
- Attribute key to use for sorting.
- $direction
- <p>Sort direction:
0 - ascending
1 - descending</p>
Returns
mixed True on success or a PEAR_Error on failure.
|
public
string
|
#
_buildParentIds( string $root, boolean $loadTree = false, string $join_name = '' )
Builds parent ID string for selecting trees.
Builds parent ID string for selecting trees.
Parameters
- $root
- Which portion of the tree to load.
- $loadTree
- <p>Load a tree starting at $root, or just the
requested level and direct parents?
Defaults to single level.</p>
- $join_name
- Table join name
Returns
string Id list.
|
public
mixed
|
#
_loadById( mixed $cids )
Loads a set of objects identified by their unique IDs, and their
parents, into the $_data array.
Loads a set of objects identified by their unique IDs, and their
parents, into the $_data array.
Parameters
- $cids
- <p>The unique ID of the object to load, or an array of
object ids.</p>
Returns
mixed True on success or a PEAR_Error on failure.
|
public
boolean
|
#
_exists( string $object_name )
Check for existance of an object in a backend-specific manner.
Check for existance of an object in a backend-specific manner.
Parameters
- $object_name
- Object name to check for.
Returns
boolean True if the object exists, false otherwise.
|
public
integer
|
#
_getId( string $name )
Look up a datatree id by name.
Look up a datatree id by name.
Parameters
Returns
integer Horde_DataTree id
|
public
string
|
#
_getName( integer $id )
Look up a datatree name by id.
Look up a datatree name by id.
Parameters
Returns
string Horde_DataTree name
|
public
array
|
#
getSortedTree( string $root, boolean $loadTree = false, string $sortby_name = null, string $sortby_key = null, integer $direction = 0 )
Returns a tree sorted by the specified attribute name and/or key.
Returns a tree sorted by the specified attribute name and/or key.
Parameters
- $root
- <p>Which portion of the tree to sort.
Defaults to all of it.</p>
- $loadTree
- <p>Sort the tree starting at $root, or just the
requested level and direct parents?
Defaults to single level.</p>
- $sortby_name
- Attribute name to use for sorting.
- $sortby_key
- Attribute key to use for sorting.
- $direction
- <p>Sort direction:
0 - ascending
1 - descending</p>
Returns
array TODO
Overrides
|
public
TODO
|
#
add( mixed $object, boolean $id_as_name = false )
Adds an object.
Parameters
- $object
- <p>The object to add (string or
Horde_DataTreeObject).</p>
- $id_as_name
- <p>Whether the object ID is to be used as
object name. Used in situations where
there is no available unique input for
object name.</p>
Returns
TODO
Overrides
|
public
TODO
|
#
reorder( string $parent, mixed $order = null, integer $cid = null )
Changes the order of the children of an object.
Changes the order of the children of an object.
Parameters
- $parent
- The full id path of the parent object.
- $order
- <p>If an array it specifies the new positions for
all child objects.
If an integer and $cid is specified, the position
where the child specified by $cid is inserted. If
$cid is not specified, the position gets deleted,
causing the following positions to shift up.</p>
- $cid
- See $order.
Returns
TODO
Overrides
|
public
TODO
|
#
setOrder( integer $id, integer $order )
Explicitly set the order for a datatree object.
Explicitly set the order for a datatree object.
Parameters
- $id
- The datatree object id to change.
- $order
- The new order.
Returns
TODO
Overrides
|
public
TODO
|
#
remove( mixed $object, boolean $force = false )
Removes an object.
Parameters
- $object
- The object to remove.
- $force
- Force removal of every child object?
Returns
TODO
Overrides
|
public
|
#
removeByIds( array $ids )
Removes one or more objects by id.
Removes one or more objects by id.
This function does not do the validation, reordering, etc. that
remove() does. If you need to check for children, re-do ordering, etc.,
then you must remove() objects one-by-one. This is for code that knows
it's dealing with single (non-parented) objects and needs to delete a
batch of them quickly.
Parameters
- $ids
- The objects to remove.
|
public
|
#
removeByNames( array $names )
Removes one or more objects by name.
Removes one or more objects by name.
This function does not do the validation, reordering, etc. that
remove() does. If you need to check for children, re-do ordering, etc.,
then you must remove() objects one-by-one. This is for code that knows
it's dealing with single (non-parented) objects and needs to delete a
batch of them quickly.
Parameters
- $names
- The objects to remove.
|
public
mixed
|
#
move( mixed $object, string $newparent = null )
Move an object to a new parent.
Move an object to a new parent.
Parameters
- $object
- The object to move.
- $newparent
- The new parent object. Defaults to the root.
Returns
mixed True on success, PEAR_Error on error.
Overrides
|
public
mixed
|
#
rename( mixed $old_object, string $new_object_name )
Change an object's name.
Parameters
- $old_object
- The old object.
- $new_object_name
- The new object name.
Returns
mixed True on success, PEAR_Error on error.
Overrides
|
public
TODO
|
#
getData( integer $cid )
Retrieves data for an object from the datatree_data field.
Retrieves data for an object from the datatree_data field.
Parameters
- $cid
- The object id to fetch, or an array of object ids.
Returns
TODO
Overrides
|
public
array
|
#
getAttributes( integer|array $cid, array $keys = false )
Retrieves data for an object from the horde_datatree_attributes table.
Retrieves data for an object from the horde_datatree_attributes table.
Parameters
- $cid
- <p>The object id to fetch, or an array of
object ids.</p>
- $keys
- The attributes keys to fetch.
Returns
array A hash of attributes, or a multi-level hash of object
ids => their attributes.
Overrides
|
public
TODO
|
#
countByAttributes( array $criteria, string $parent = DATATREE_ROOT, boolean $allLevels = true, string $restrict = 'name' )
Returns the number of objects matching a set of attribute criteria.
Returns the number of objects matching a set of attribute criteria.
Parameters
- $criteria
- The array of criteria.
- $parent
- The parent node to start searching from.
- $allLevels
- <p>Return all levels, or just the direct
children of $parent? Defaults to all levels.</p>
- $restrict
- <p>Only return attributes with the same
attribute_name or attribute_id.</p>
Returns
TODO
See
Overrides
|
public
TODO
|
#
getByAttributes( array $criteria, string $parent = DATATREE_ROOT, boolean $allLevels = true, string $restrict = 'name', integer $from = 0, integer $count = 0, string $sortby_name = null, string $sortby_key = null, integer $direction = 0 )
Returns a set of object ids based on a set of attribute criteria.
Returns a set of object ids based on a set of attribute criteria.
Parameters
- $criteria
- The array of criteria.
- $parent
- The parent node to start searching from.
- $allLevels
- <p>Return all levels, or just the direct
children of $parent? Defaults to all levels.</p>
- $restrict
- <p>Only return attributes with the same
attribute_name or attribute_id.</p>
- $from
- The object to start to fetching
- $count
- The number of objects to fetch
- $sortby_name
- Attribute name to use for sorting.
- $sortby_key
- Attribute key to use for sorting.
- $direction
- <p>Sort direction:
0 - ascending
1 - descending</p>
Returns
TODO
See
Overrides
|
public
array
|
#
sortByAttributes( array $unordered_ids, array $sortby_name = null, array $sortby_key = null, array $direction = 0 )
Sorts IDs by attribute values. IDs without attributes will be added to
the end of the sorted list.
Sorts IDs by attribute values. IDs without attributes will be added to
the end of the sorted list.
Parameters
- $unordered_ids
- Array of ids to sort.
- $sortby_name
- Attribute name to use for sorting.
- $sortby_key
- Attribute key to use for sorting.
- $direction
- <p>Sort direction:
0 - ascending
1 - descending</p>
Returns
array Sorted ids.
Overrides
|
public
|
#
countValuesByAttributes( array $criteria, string $parent = DATATREE_ROOT, boolean $allLevels = true, string $restrict = 'name', string $key = null, string $name = null )
Returns the number of all of the available values matching the
given criteria. Either attribute_name or attribute_key MUST be
supplied, and both MAY be supplied.
Returns the number of all of the available values matching the
given criteria. Either attribute_name or attribute_key MUST be
supplied, and both MAY be supplied.
Parameters
- $criteria
- The array of criteria.
- $parent
- The parent node to start searching from.
- $allLevels
- <p>Return all levels, or just the direct
children of $parent? Defaults to all levels.</p>
- $restrict
- <p>Only return attributes with the same
attribute_name or attribute_id.</p>
- $key
- $attribute_name The name of the attribute.
- $name
- $attribute_key The key value of the attribute.
See
|
public
|
#
getValuesByAttributes( array $criteria, string $parent = DATATREE_ROOT, boolean $allLevels = true, string $restrict = 'name', integer $from = 0, integer $count = 0, string $sortby_name = null, string $sortby_key = null, integer $direction = 0, string $key = null, string $name = null )
Returns a list of all of the available values of the given criteria
Either attribute_name or attribute_key MUST be
supplied, and both MAY be supplied.
Returns a list of all of the available values of the given criteria
Either attribute_name or attribute_key MUST be
supplied, and both MAY be supplied.
Parameters
- $criteria
- The array of criteria.
- $parent
- The parent node to start searching from.
- $allLevels
- <p>Return all levels, or just the direct
children of $parent? Defaults to all levels.</p>
- $restrict
- <p>Only return attributes with the same
attribute_name or attribute_id.</p>
- $from
- The object to start to fetching
- $count
- The number of objects to fetch
- $sortby_name
- Attribute name to use for sorting.
- $sortby_key
- Attribute key to use for sorting.
- $direction
- <p>Sort direction:
0 - ascending
1 - descending</p>
- $key
- $attribute_name The name of the attribute.
- $name
- $attribute_key The key value of the attribute.
See
|
public
array
|
#
getAttributeValues( string $attribute_name = null, string $attribute_key = null, string $parent = DATATREE_ROOT, boolean $allLevels = true )
Returns a list of all of the available values of the given attribute
name/key combination. Either attribute_name or attribute_key MUST be
supplied, and both MAY be supplied.
Returns a list of all of the available values of the given attribute
name/key combination. Either attribute_name or attribute_key MUST be
supplied, and both MAY be supplied.
Parameters
- $attribute_name
- The name of the attribute.
- $attribute_key
- The key value of the attribute.
- $parent
- The parent node to start searching from.
- $allLevels
- <p>Return all levels, or just the direct
children of $parent? Defaults to all
levels.</p>
Returns
array An array of all of the available values.
|
public
array
|
#
buildAttributeQuery( array $criteria, string $parent = DATATREE_ROOT, boolean $allLevels = true, string $restrict = 'name', integer $operation = DATATREE_BUILD_SELECT, string $sortby_name = null, string $sortby_key = null, integer $direction = 0 )
Builds an attribute query. Here is an example $criteria array:
Builds an attribute query. Here is an example $criteria array:
$criteria['OR'] = array(
array('AND' => array(
array('field' => 'name',
'op' => '=',
'test' => 'foo'),
array('field' => 'key',
'op' => '=',
'test' => 'abc'))),
array('AND' => array(
array('field' => 'name',
'op' => '=',
'test' => 'bar'),
array('field' => 'key',
'op' => '=',
'test' => 'xyz'))));
This would fetch all object ids where attribute name is "foo" AND key
is "abc", OR "bar" AND "xyz".
Parameters
- $criteria
- The array of criteria.
- $parent
- The parent node to start searching from.
- $allLevels
- <p>Return all levels, or just the direct
children of $parent? Defaults to all levels.</p>
- $restrict
- <p>Only return attributes with the same
attribute_name or attribute_id.</p>
- $operation
- Type of query to build
- $sortby_name
- Attribute name to use for sorting.
- $sortby_key
- Attribute key to use for sorting.
- $direction
- <p>Sort direction:
0 - ascending
1 - descending</p>
Returns
array An SQL query and a list of values suitable for binding
as an array.
|
public
array
|
#
_buildAttributeQuery( string $glue, array $criteria, boolean $join = false )
Builds a piece of an attribute query.
Builds a piece of an attribute query.
Parameters
- $glue
- The glue to join the criteria (OR/AND).
- $criteria
- The array of criteria.
- $join
- <p>Should we join on a clean
horde_datatree_attributes table? Defaults to
false.</p>
Returns
array An SQL fragment and a list of values suitable for binding
as an array.
|
public
|
#
_getAlias( boolean $increment = false )
Get an alias to horde_datatree_attributes, incrementing it if
necessary.
Get an alias to horde_datatree_attributes, incrementing it if
necessary.
Parameters
- $increment
- Increment the alias count? Defaults to no.
|
public
TODO
|
#
updateData( Horde_DataTree $object )
Update the data in an object. Does not change the object's
parent or name, just serialized data or attributes.
Update the data in an object. Does not change the object's
parent or name, just serialized data or attributes.
Parameters
- $object
- A Horde_DataTree object.
Returns
TODO
Overrides
|
public
mixed
|
#
_init( )
Attempts to open a connection to the SQL server.
Attempts to open a connection to the SQL server.
Returns
mixed True or PEAR_Error.
|
public static
mixed
|
#
buildClause( DB $dbh, string $lhs, string $op, string $rhs, boolean $bind = false, array $params = array() )
Returns a boolean expression using the specified operator. Uses
database-specific casting, if necessary.
Returns a boolean expression using the specified operator. Uses
database-specific casting, if necessary.
Parameters
- $dbh
- The PEAR::DB database object.
- $lhs
- The column or expression to test.
- $op
- The operator.
- $rhs
- The comparison value.
- $bind
- <p>If true, the method returns the query and a list
of values suitable for binding as an array.</p>
- $params
- Any additional parameters for the operator.
Returns
mixed The SQL test fragment, or an array containing the query
and a list of values if $bind is true.
|
public static
string
|
#
escapePrepare( string $query )
Escapes all characters in a string that are placeholders for the
prepare/execute methods of the DB package.
Escapes all characters in a string that are placeholders for the
prepare/execute methods of the DB package.
Parameters
- $query
- A string to escape.
Returns
string The correctly escaped string.
|