Class DataTree_sql

Description

The 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 DataTree system is in scripts/sql/horde_datatree.sql.

$Horde: framework/DataTree/DataTree/sql.php,v 1.156.2.46 2010-10-21 20:02:46 jan Exp $

Copyright 1999-2009 The Horde Project (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.

Located in /DataTree/DataTree/sql.php (line 48)

DataTree
   |
   --DataTree_sql
Variable Summary
 DB $_db
 integer $_tableCount
Method Summary
 void add (mixed $object, [boolean $id_as_name = false])
 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])
 void countByAttributes (array $criteria, [string $parent = DATATREE_ROOT], [boolean $allLevels = true], [string $restrict = 'name'])
 void countValuesByAttributes (array $criteria, [string $parent = DATATREE_ROOT], [boolean $allLevels = true], [string $restrict = 'name'], [ $key = null], [ $name = null], string $attribute_name, string $attribute_key)
 array getAttributes (integer|array $cid, [array $keys = false])
 array getAttributeValues ([string $attribute_name = null], [string $attribute_key = null], [string $parent = DATATREE_ROOT], [boolean $allLevels = true])
 void 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])
 void getData (integer $cid)
 array getGroups ()
 array getSortedTree (string $root, [boolean $loadTree = false], [string $sortby_name = null], [string $sortby_key = null], [integer $direction = 0])
 void 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], [ $key = null], [ $name = null], string $attribute_name, string $attribute_key)
 void move (mixed $object, [string $newparent = null])
 void remove (mixed $object, [boolean $force = false])
 void removeByIds (array $ids)
 void removeByNames (array $names)
 void rename (mixed $old_object, string $new_object_name)
 void reorder (string $parent, [mixed $order = null], [integer $cid = null])
 void setOrder (integer $id, integer $order)
 array sortByAttributes (array $unordered_ids, [array $sortby_name = null], [array $sortby_key = null], [array $direction = 0])
 void updateData (DataTree $object)
 array _buildAttributeQuery (string $glue, array $criteria, [boolean $join = false])
 boolean _exists (string $object_name)
 void _getAlias ([boolean $increment = false])
 integer _getId (string $name)
 string _getName (integer $id)
 boolean _init ()
Variables
DB $_db (line 55)

Handle for the current database connection, used for reading.

integer $_tableCount = 1 (line 71)

The number of copies of the horde_datatree_attributes table that we need to join on in the current query.

DB $_write_db (line 63)

Handle for the current database connection, used for writing. Defaults to the same handle as $_db if a separate write database is not required.

Inherited Variables

Inherited from DataTree

DataTree::$_data
DataTree::$_nameMap
DataTree::$_params
DataTree::$_sortHash
Methods
add (line 515)

Adds an object.

void add (mixed $object, [boolean $id_as_name = false])
  • mixed $object: The object to add (string or DataTreeObject).
  • boolean $id_as_name: Whether the object ID is to be used as object name. Used in situations where there is no available unique input for object name.

Redefinition of:
DataTree::add()
Adds an object.
buildAttributeQuery (line 1544)

Builds an attribute query. Here is an example $criteria array:

  1.  $criteria['OR'array(
  2.      array('AND' => array(
  3.          array('field' => 'name',
  4.                'op'    => '=',
  5.                'test'  => 'foo'),
  6.          array('field' => 'key',
  7.                'op'    => '=',
  8.                'test'  => 'abc'))),
  9.          array('AND' => array(
  10.              array('field' => 'name',
  11.                    'op'    => '=',
  12.                    'test'  => 'bar'),
  13.              array('field' => 'key',
  14.                    'op'    => '=',
  15.                    'test'  => 'xyz'))));

This would fetch all object ids where attribute name is "foo" AND key is "abc", OR "bar" AND "xyz".

  • return: An SQL query and a list of values suitable for binding as an array.
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])
  • array $criteria: The array of criteria.
  • string $parent: The parent node to start searching from.
  • boolean $allLevels: Return all levels, or just the direct children of $parent? Defaults to all levels.
  • string $restrict: Only return attributes with the same attribute_name or attribute_id.
  • integer $operation: Type of query to build
  • string $sortby_name: Attribute name to use for sorting.
  • string $sortby_key: Attribute key to use for sorting.
  • integer $direction: Sort direction:
    1. - ascending
    2. - descending
countByAttributes (line 1132)

Returns the number of objects matching a set of attribute criteria.

void countByAttributes (array $criteria, [string $parent = DATATREE_ROOT], [boolean $allLevels = true], [string $restrict = 'name'])
  • array $criteria: The array of criteria.
  • string $parent: The parent node to start searching from.
  • boolean $allLevels: Return all levels, or just the direct children of $parent? Defaults to all levels.
  • string $restrict: Only return attributes with the same attribute_name or attribute_id.

Redefinition of:
DataTree::countByAttributes()
Returns the number of objects matching a set of attribute criteria.
countValuesByAttributes (line 1330)

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.

void countValuesByAttributes (array $criteria, [string $parent = DATATREE_ROOT], [boolean $allLevels = true], [string $restrict = 'name'], [ $key = null], [ $name = null], string $attribute_name, string $attribute_key)
  • array $criteria: The array of criteria.
  • string $parent: The parent node to start searching from.
  • boolean $allLevels: Return all levels, or just the direct children of $parent? Defaults to all levels.
  • string $restrict: Only return attributes with the same attribute_name or attribute_id.
  • string $attribute_name: The name of the attribute.
  • string $attribute_key: The key value of the attribute.
  • $key
  • $name
getAttributes (line 1068)

Retrieves data for an object from the horde_datatree_attributes table.

  • return: A hash of attributes, or a multi-level hash of object ids => their attributes.
array getAttributes (integer|array $cid, [array $keys = false])
  • integer|array $cid: The object id to fetch, or an array of object ids.
  • array $keys: The attributes keys to fetch.

Redefinition of:
DataTree::getAttributes()
Retrieve data for an object from the horde_datatree_attributes table.
getAttributeValues (line 1436)

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.

  • return: An array of all of the available values.
array getAttributeValues ([string $attribute_name = null], [string $attribute_key = null], [string $parent = DATATREE_ROOT], [boolean $allLevels = true])
  • string $attribute_name: The name of the attribute.
  • string $attribute_key: The key value of the attribute.
  • string $parent: The parent node to start searching from.
  • boolean $allLevels: Return all levels, or just the direct children of $parent? Defaults to all levels.
getByAttributes (line 1184)

Returns a set of object ids based on a set of attribute criteria.

void 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])
  • array $criteria: The array of criteria.
  • string $parent: The parent node to start searching from.
  • boolean $allLevels: Return all levels, or just the direct children of $parent? Defaults to all levels.
  • string $restrict: Only return attributes with the same attribute_name or attribute_id.
  • integer $from: The object to start to fetching
  • integer $count: The number of objects to fetch
  • string $sortby_name: Attribute name to use for sorting.
  • string $sortby_key: Attribute key to use for sorting.
  • integer $direction: Sort direction:
    1. - ascending
    2. - descending

Redefinition of:
DataTree::getByAttributes()
Returns a set of object ids based on a set of attribute criteria.
getData (line 1002)

Retrieves data for an object from the datatree_data field.

void getData (integer $cid)
  • integer $cid: The object id to fetch, or an array of object ids.

Redefinition of:
DataTree::getData()
Retrieve data for an object from the datatree_data field.
getGroups (line 78)

Returns a list of all groups (root nodes) of the data tree.

  • return: The the group IDs
array getGroups ()

Redefinition of:
DataTree::getGroups()
Returns a list of all groups (root nodes) of the data tree.
getSortedTree (line 489)

Returns a tree sorted by the specified attribute name and/or key.

  • return: TODO
  • since: Horde 3.1
array getSortedTree (string $root, [boolean $loadTree = false], [string $sortby_name = null], [string $sortby_key = null], [integer $direction = 0])
  • string $root: Which portion of the tree to sort. Defaults to all of it.
  • boolean $loadTree: Sort the tree starting at $root, or just the requested level and direct parents? Defaults to single level.
  • string $sortby_name: Attribute name to use for sorting.
  • string $sortby_key: Attribute key to use for sorting.
  • integer $direction: Sort direction:
    1. - ascending
    2. - descending

Redefinition of:
DataTree::getSortedTree()
Returns a tree sorted by the specified attribute name and/or key.
getValuesByAttributes (line 1384)

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.

void 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], [ $key = null], [ $name = null], string $attribute_name, string $attribute_key)
  • array $criteria: The array of criteria.
  • string $parent: The parent node to start searching from.
  • boolean $allLevels: Return all levels, or just the direct children of $parent? Defaults to all levels.
  • string $restrict: Only return attributes with the same attribute_name or attribute_id.
  • integer $from: The object to start to fetching
  • integer $count: The number of objects to fetch
  • string $sortby_name: Attribute name to use for sorting.
  • string $sortby_key: Attribute key to use for sorting.
  • integer $direction: Sort direction:
    1. - ascending
    2. - descending
  • string $attribute_name: The name of the attribute.
  • string $attribute_key: The key value of the attribute.
  • $key
  • $name
move (line 901)

Move an object to a new parent.

void move (mixed $object, [string $newparent = null])
  • mixed $object: The object to move.
  • string $newparent: The new parent object. Defaults to the root.

Redefinition of:
DataTree::move()
Move an object to a new parent.
remove (line 751)

Removes an object.

void remove (mixed $object, [boolean $force = false])
  • mixed $object: The object to remove.
  • boolean $force: Force removal of every child object?

Redefinition of:
DataTree::remove()
Removes an object.
removeByIds (line 827)

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.

void removeByIds (array $ids)
  • array $ids: The objects to remove.
removeByNames (line 871)

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.

void removeByNames (array $names)
  • array $names: The objects to remove.
rename (line 976)

Change an object's name.

void rename (mixed $old_object, string $new_object_name)
  • mixed $old_object: The old object.
  • string $new_object_name: The new object name.

Redefinition of:
DataTree::rename()
Change an object's name.
reorder (line 658)

Changes the order of the children of an object.

void reorder (string $parent, [mixed $order = null], [integer $cid = null])
  • string $parent: The full id path of the parent object.
  • mixed $order: 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.
  • integer $cid: See $order.

Redefinition of:
DataTree::reorder()
Changes the order of the children of an object.
setOrder (line 734)

Explicitly set the order for a datatree object.

void setOrder (integer $id, integer $order)
  • integer $id: The datatree object id to change.
  • integer $order: The new order.

Redefinition of:
DataTree::setOrder()
Explicitly set the order for a datatree object.
sortByAttributes (line 1279)

Sorts IDs by attribute values. IDs without attributes will be added to the end of the sorted list.

  • return: Sorted ids.
array sortByAttributes (array $unordered_ids, [array $sortby_name = null], [array $sortby_key = null], [array $direction = 0])
  • array $unordered_ids: Array of ids to sort.
  • array $sortby_name: Attribute name to use for sorting.
  • array $sortby_key: Attribute key to use for sorting.
  • array $direction: Sort direction:
    1. - ascending
    2. - descending

Redefinition of:
DataTree::sortByAttributes()
Sorts IDs by attribute values. IDs without attributes will be added to the end of the sorted list.
updateData (line 1768)

Update the data in an object. Does not change the object's parent or name, just serialized data or attributes.

void updateData (DataTree $object)
  • DataTree $object: A DataTree object.

Redefinition of:
DataTree::updateData()
Update the data in an object. Does not change the object's parent or name, just serialized data or attributes.
_buildAttributeQuery (line 1695)

Builds a piece of an attribute query.

  • return: An SQL fragment and a list of values suitable for binding as an array.
array _buildAttributeQuery (string $glue, array $criteria, [boolean $join = false])
  • string $glue: The glue to join the criteria (OR/AND).
  • array $criteria: The array of criteria.
  • boolean $join: Should we join on a clean horde_datatree_attributes table? Defaults to false.
_exists (line 389)

Check for existance of an object in a backend-specific manner.

  • return: True if the object exists, false otherwise.
boolean _exists (string $object_name)
  • string $object_name: Object name to check for.
_getAlias (line 1750)

Get an alias to horde_datatree_attributes, incrementing it if necessary.

void _getAlias ([boolean $increment = false])
  • boolean $increment: Increment the alias count? Defaults to no.
_getId (line 419)

Look up a datatree id by name.

  • return: DataTree id
integer _getId (string $name)
  • string $name
_getName (line 447)

Look up a datatree name by id.

  • return: DataTree name
string _getName (integer $id)
  • integer $id
_init (line 1864)

Attempts to open a connection to the SQL server.

  • return: True.
boolean _init ()

Inherited Methods

Inherited From DataTree

 DataTree::DataTree()
 DataTree::add()
 DataTree::count()
 DataTree::countByAttributes()
 DataTree::encodeName()
 DataTree::exists()
 DataTree::factory()
 DataTree::get()
 DataTree::getAttributes()
 DataTree::getByAttributes()
 DataTree::getById()
 DataTree::getData()
 DataTree::getGroups()
 DataTree::getId()
 DataTree::getName()
 DataTree::getNumberOfChildren()
 DataTree::getObject()
 DataTree::getObjectById()
 DataTree::getObjects()
 DataTree::getOrder()
 DataTree::getParam()
 DataTree::getParent()
 DataTree::getParentById()
 DataTree::getParentIdString()
 DataTree::getParentList()
 DataTree::getParents()
 DataTree::getShortName()
 DataTree::getSortedTree()
 DataTree::move()
 DataTree::remove()
 DataTree::removeUserData()
 DataTree::rename()
 DataTree::reorder()
 DataTree::set()
 DataTree::setOrder()
 DataTree::singleton()
 DataTree::sortByAttributes()
 DataTree::sortHash()
 DataTree::updateData()
 DataTree::_add()
 DataTree::_cmp()
 DataTree::_cmpSorted()
 DataTree::_defineObjectClass()
 DataTree::_extractOneLevel()
 DataTree::_reorder()

Documentation generated on Sun, 30 Jan 2011 05:21:54 +0000 by phpDocumentor 1.4.3