wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
ObjectQuery Class Reference
+ Inheritance diagram for ObjectQuery:

Public Member Functions

 ObjectQuery ($type)
 
getObjectTemplate ($type, $preOperator=QUERYOP_AND, $interOperator=QUERYOP_AND)
 
 registerObjectTemplate (&$template, $preOperator=QUERYOP_AND, $interOperator=QUERYOP_AND)
 
 makeGroup ($templates, $preOperator=QUERYOP_AND, $interOperator=QUERYOP_OR)
 
 escapeValue ($value)
 
 execute ($buildDepth, $orderby=null, &$pagingInfo, $attribs=null)
 
 executeString ($type, $query, $buildDepth, $orderby=null, &$pagingInfo)
 
 toString ($buildDepth=BUILDDEPTH_SINGLE, $attribs=null)
 
 buildQuery ($buildDepth, $attribs=null)
 
 processObjectTemplate (&$tpl, &$tableArray, &$conditionStr, &$relationArray)
 
 getTableName (&$tpl, $asAliasString=false)
 
 getRelationCondition (&$parentTpl, &$childTpl)
 
 getOrderby ($type, $query, $orderby)
 
 makeConditionStr (&$node, $valueName, $dataType, $operator)
 
getConnection ($type)
 
getMapper (&$node)
 
 checkMapper (&$mapper)
 
 getId ()
 
 valueChanged (&$object, $name, $type, $oldValue, $newValue)
 
 propertyChanged (&$object, $name, $oldValue, $newValue)
 
 stateChanged (&$object, $oldValue, $newValue)
 
- Public Member Functions inherited from ChangeListener
 getId ()
 
 valueChanged (&$object, $name, $type, $oldValue, $newValue)
 
 propertyChanged (&$object, $name, $oldValue, $newValue)
 
 stateChanged (&$object, $oldValue, $newValue)
 

Public Attributes

 $_id = ''
 
 $_typeNode = null
 
 $_root = null
 
 $_conditions = array()
 
 $_groups = array()
 
 $_groupedOIDs = array()
 
 $_query = ''
 

Detailed Description

ObjectQuery is the base class for object queries. This class provides the user with object templates on which query conditions may be set. Object templates are Node instances whose attribute values are used as conditions on the appropriate attributes. A value inludes the operator to be applied to it. For example $authorTpl->setValue("name", "LIKE '%ingo%'") means searching for authors whose name contains 'ingo'. Operator and value should be separated by a space. If no operator is given LIKE '%...' is assumed.

All value conditions of one template are joined with the same operator ('AND', 'OR') given in the "inter_operator" (DATATYPE_IGNORE) value of the template. The set of conditions of a template is preceded by the operator ('AND', 'OR', 'NOT') given in the "pre_operator" (DATATYPE_IGNORE) value (default: 'AND') of the template (see ObjectQuery::getObjectTemplate()).

Multiple conditions for one value are built using different object templates of the same type. Conditions sets of different object templates are grouped with brackets if they are passed to ObjectQuery::makeGroup().

Note
: If there are two object templates of the same type as the query type linked in a parent child relation, than the nodes that are selected depend on the attributes of the first object template that is received by ObjectQuery::getObjectTemplate.

The following example shows the usage:

// The code builds the following query condition:
// WHERE (Author.name LIKE '%ingo%' AND Author.email LIKE '%wemove%') OR (Author.name LIKE '%herwig%') AND
// (Recipe.created >= '2004-01-01') AND (Recipe.created < '2005-01-01') AND ((Recipe.name LIKE '%Salat%') OR (Recipe.portions = 4))
// (Author.name LIKE '%ingo%' AND Author.email LIKE '%wemove%')
$authorTpl1 = &$query->getObjectTemplate('Author');
$authorTpl1->setValue("name", "ingo", DATATYPE_ATTRIBUTE);
$authorTpl1->setValue("email", "LIKE '%wemove%'", DATATYPE_ATTRIBUTE);
// OR Author.name LIKE '%herwig%'
$authorTpl2 = &$query->getObjectTemplate('Author', QUERYOP_OR);
$authorTpl2->setValue("name", "herwig", DATATYPE_ATTRIBUTE);
// Recipe.created >= '2004-01-01' AND Recipe.created < '2005-01-01'
$recipeTpl1 = &$query->getObjectTemplate('Recipe');
$recipeTpl1->setValue("created", ">= '2004-01-01'", DATATYPE_ATTRIBUTE);
$recipeTpl2 = &$query->getObjectTemplate('Recipe');
$recipeTpl2->setValue("created", "< '2005-01-01'", DATATYPE_ATTRIBUTE);
// AND (Recipe.name LIKE '%Salat%' OR Recipe.portions = 4)
// could have be built using one template, but this demonstrates the usage
// of the ObjectQuery::makeGroup() method
$recipeTpl3 = &$query->getObjectTemplate('Recipe');
$recipeTpl3->setValue("name", "Salat", DATATYPE_ATTRIBUTE);
$recipeTpl4 = &$query->getObjectTemplate('Recipe');
$recipeTpl4->setValue("portions", "= 4", DATATYPE_ATTRIBUTE);
$query->makeGroup(array(&$recipeTpl3, &$recipeTpl4), QUERYOP_AND, QUERYOP_OR);
$authorTpl1->addChild($recipeTpl1);
$authorTpl1->addChild($recipeTpl2);
$authorTpl1->addChild($recipeTpl3);
$authorTpl1->addChild($recipeTpl4);
$authorList = $query->execute(BUILDDEPTH_SINGLE);
Note
There are some limitations when using this class:
  • This class works only with Nodes as PersistentObjects
  • This class only works for Nodes mapped by NodeUnifiedRDBMapper subclasses.
  • All objects have to reside in the same datastore (the connection is taken from the first mapper)
  • Since the query values are set together with the operator in a single string, they must be converted to data store format already
Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 117 of file class.ObjectQuery.php.

Member Function Documentation

ObjectQuery::ObjectQuery (   $type)

Constructor.

Parameters
typeThe type to search for.

Definition at line 131 of file class.ObjectQuery.php.

References BUILDDEPTH_SINGLE, and PersistenceFacade\getInstance().

+ Here is the call graph for this function:

& ObjectQuery::getObjectTemplate (   $type,
  $preOperator = QUERYOP_AND,
  $interOperator = QUERYOP_AND 
)

Get an object template for a given type.

Parameters
typeThe type to query for
preOperatorOne of the QUERYOP constants that precedes the conditions described in the template [default: QUERYOP_AND]
interOperatorOne of the QUERYOP constants that is used to join the conditions described in the template [default: QUERYOP_AND]
Returns
A newly created instance of a Node subclass, that defines the requested type.

Definition at line 146 of file class.ObjectQuery.php.

References BUILDDEPTH_SINGLE, DATATYPE_IGNORE, and PersistenceFacade\getInstance().

+ Here is the call graph for this function:

ObjectQuery::registerObjectTemplate ( $template,
  $preOperator = QUERYOP_AND,
  $interOperator = QUERYOP_AND 
)

Register an object template at the query.

Parameters
templateA reference to the template to register (must be an instance of PersistentObject)
preOperatorOne of the QUERYOP constants that precedes the conditions described in the template [default: QUERYOP_AND]
interOperatorOne of the QUERYOP constants that is used to join the conditions described in the template [default: QUERYOP_AND]

Definition at line 162 of file class.ObjectQuery.php.

References DATATYPE_ATTRIBUTE, DATATYPE_IGNORE, PersistenceFacade\decomposeOID(), getMapper(), and PersistenceFacade\isDummyId().

+ Here is the call graph for this function:

ObjectQuery::makeGroup (   $templates,
  $preOperator = QUERYOP_AND,
  $interOperator = QUERYOP_OR 
)

Group different templates together to realize brackets in the query.

Note
Grouped templates will be ignored, when iterating over the object tree and appended at the end.
Parameters
templatesAn array of references to the templates contained in the group
preOperatorOne of the QUERYOP constants that precedes the group [default: QUERYOP_AND]
interOperatorOne of the QUERYOP constants that is used to join the conditions inside the group [default: QUERYOP_OR]

Definition at line 195 of file class.ObjectQuery.php.

References $_groupedOIDs, Message\get(), and WCMFException\throwEx().

+ Here is the call graph for this function:

ObjectQuery::escapeValue (   $value)

Escape a value for using it in a query.

Parameters
valueThe value.
Returns
The escaped value.

Definition at line 212 of file class.ObjectQuery.php.

ObjectQuery::execute (   $buildDepth,
  $orderby = null,
$pagingInfo,
  $attribs = null 
)

Execute the object query

Parameters
buildDepthOne of the BUILDDEPTH constants or a number describing the number of generations to load (except BUILDDEPTH_REQUIRED) or false if only oids should be returned
orderbyAn array holding names of attributes to ORDER by (maybe null). [default: null]
pagingInfoA reference paging info instance (optional, default null does not work in PHP4).
attribsAn array of attributes to load (null to load all, if buildDepth != false). [default: null]
Returns
A list of objects that match the given conditions or a list of oids

Definition at line 226 of file class.ObjectQuery.php.

References $_query, buildQuery(), and executeString().

+ Here is the call graph for this function:

ObjectQuery::executeString (   $type,
  $query,
  $buildDepth,
  $orderby = null,
$pagingInfo 
)

Execute a serialized object query

Note
This method maybe called staticly
Parameters
typeThe type to query
queryThe serialized query as string (as provided by ObjectQuery::toString)
buildDepthOne of the BUILDDEPTH constants or a number describing the number of generations to load (except BUILDDEPTH_REQUIRED) or false if only oids should be returned
orderbyAn array holding names of attributes to ORDER by (maybe null). [default: null]
pagingInfoA reference paging info instance (optional, default null does not work in PHP4).
Returns
A list of objects that match the given conditions or a list of oids

Definition at line 244 of file class.ObjectQuery.php.

References BUILDDEPTH_SINGLE, PersistenceFacade\getInstance(), getMapper(), and getOrderby().

Referenced by StringQuery\execute(), execute(), AsyncPagingController\getObjects(), and SortController\sortAll().

+ Here is the call graph for this function:

ObjectQuery::toString (   $buildDepth = BUILDDEPTH_SINGLE,
  $attribs = null 
)

Get the query serialized to a string.

Parameters
buildDepth
See Also
ObjectQuery::execute() [default: BUILDDEPTH_SINGLE]
Parameters
attribsAn array of attributes to load (null to load all, if buildDepth != false). [default: null]
Returns
The sql query string

Definition at line 285 of file class.ObjectQuery.php.

References buildQuery().

+ Here is the call graph for this function:

ObjectQuery::buildQuery (   $buildDepth,
  $attribs = null 
)

Build the query

Parameters
buildDepth
See Also
ObjectQuery::execute()
Parameters
attribsAn array of attributes to load (null to load all, if buildDepth != false). [default: null]
Returns
The sql query string

Definition at line 295 of file class.ObjectQuery.php.

References $_groupedOIDs, DATATYPE_IGNORE, getMapper(), getTableName(), and processObjectTemplate().

Referenced by execute(), and toString().

+ Here is the call graph for this function:

ObjectQuery::processObjectTemplate ( $tpl,
$tableArray,
$conditionStr,
$relationArray 
)

Process an object template

Parameters
tplThe object template
tableArrayAn array of table names, where the tablename of the templates will be added
conditionStrA string of conditions, where the conditions described in the template will be added
relationArrayAn array of relation strings, where the relations of the template will be added
Returns
An assoziative array with the following keys: 'attributes', 'table', 'conditions'

Definition at line 377 of file class.ObjectQuery.php.

References DATATYPE_IGNORE, getRelationCondition(), and getTableName().

Referenced by buildQuery().

+ Here is the call graph for this function:

ObjectQuery::getTableName ( $tpl,
  $asAliasString = false 
)

Get the table name for the template.

Parameters
tplThe object template
asAliasStringReturn the table name in the form 'table as alias' [default: false]
Returns
An table name

Definition at line 407 of file class.ObjectQuery.php.

References DATATYPE_IGNORE, and getMapper().

Referenced by StringQuery\buildQuery(), buildQuery(), getRelationCondition(), makeConditionStr(), and processObjectTemplate().

+ Here is the call graph for this function:

ObjectQuery::getRelationCondition ( $parentTpl,
$childTpl 
)

Get the relation condition between a parent and a child node.

Parameters
parentTplThe parent template node
childTplThe child template node
Returns
The condition string

Definition at line 444 of file class.ObjectQuery.php.

References getMapper(), and getTableName().

Referenced by StringQuery\buildQuery(), and processObjectTemplate().

+ Here is the call graph for this function:

ObjectQuery::getOrderby (   $type,
  $query,
  $orderby 
)

Get the order by string from given array of attribute names. If the orderby parameter is null, the default order is taken.

Parameters
typeThe node type to get the order by for
queryThe query to set the order by on
orderbyArray of attribute names

Definition at line 465 of file class.ObjectQuery.php.

References checkMapper(), and PersistenceFacade\getInstance().

Referenced by executeString().

+ Here is the call graph for this function:

ObjectQuery::makeConditionStr ( $node,
  $valueName,
  $dataType,
  $operator 
)

Build a condition string from an object template. Used as a callback for a NodeProcessor. Adds each value condition to the "query_condition" value (DATATYPE_IGNORE)

Parameters
nodeA reference to the Node the holds the value (the template)
valueNameThe name of the value
dataTypeThe dataType of the value
operatorThe operator to connect the value conditions with
See Also
NodeProcessor

Definition at line 502 of file class.ObjectQuery.php.

References DATATYPE_IGNORE, getMapper(), getTableName(), and QUERYOP_AND.

+ Here is the call graph for this function:

& ObjectQuery::getConnection (   $type)

Get the database connection of the given node type.

Parameters
typeThe node type to get the connection from connection
Returns
The connection

Definition at line 555 of file class.ObjectQuery.php.

References PersistenceFacade\getInstance().

+ Here is the call graph for this function:

& ObjectQuery::getMapper ( $node)

Get the mapper for a Node and check if it is a supported one.

Parameters
nodeA reference to the Node to get the mapper for
Returns
The mapper

Definition at line 567 of file class.ObjectQuery.php.

References checkMapper().

Referenced by StringQuery\buildQuery(), buildQuery(), StringQuery\execute(), executeString(), getRelationCondition(), getTableName(), makeConditionStr(), StringQuery\mapToDatabase(), and registerObjectTemplate().

+ Here is the call graph for this function:

ObjectQuery::checkMapper ( $mapper)

Check if a mapper is a supported one.

Parameters
mapperA reference to the PersistenceMapper
Returns
True/False, causes an error if false

Definition at line 582 of file class.ObjectQuery.php.

References Message\get(), and WCMFException\throwEx().

Referenced by getMapper(), and getOrderby().

+ Here is the call graph for this function:

ObjectQuery::getId ( )

ChangeListener interface implementation

See Also
ChangeListener::getId()

Definition at line 599 of file class.ObjectQuery.php.

References $_id.

ObjectQuery::valueChanged ( $object,
  $name,
  $type,
  $oldValue,
  $newValue 
)
See Also
ChangeListener::valueChanged()

Definition at line 606 of file class.ObjectQuery.php.

References $GLOBALS, and DATATYPE_IGNORE.

ObjectQuery::propertyChanged ( $object,
  $name,
  $oldValue,
  $newValue 
)
See Also
ChangeListener::propertyChanged()

Definition at line 623 of file class.ObjectQuery.php.

ObjectQuery::stateChanged ( $object,
  $oldValue,
  $newValue 
)
See Also
ChangeListener::stateChanged()

Definition at line 627 of file class.ObjectQuery.php.

Member Data Documentation

ObjectQuery::$_id = ''

Definition at line 119 of file class.ObjectQuery.php.

Referenced by getId().

ObjectQuery::$_typeNode = null

Definition at line 120 of file class.ObjectQuery.php.

ObjectQuery::$_root = null

Definition at line 121 of file class.ObjectQuery.php.

ObjectQuery::$_conditions = array()

Definition at line 122 of file class.ObjectQuery.php.

ObjectQuery::$_groups = array()

Definition at line 123 of file class.ObjectQuery.php.

ObjectQuery::$_groupedOIDs = array()

Definition at line 124 of file class.ObjectQuery.php.

Referenced by buildQuery(), and makeGroup().

ObjectQuery::$_query = ''

Definition at line 125 of file class.ObjectQuery.php.

Referenced by execute().


The documentation for this class was generated from the following file: