19 require_once(BASE.
"wcmf/lib/core/class.WCMFException.php");
20 require_once(BASE.
"wcmf/lib/util/class.Message.php");
21 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceFacade.php");
22 require_once(BASE.
"wcmf/lib/persistence/class.ObjectQuery.php");
23 require_once(BASE.
"wcmf/lib/model/class.NodeUtil.php");
24 require_once(BASE.
"wcmf/lib/util/class.StringUtil.php");
61 function execute($type, $queryString, $buildDepth, $orderby=null, &$pagingInfo, $attribs=null)
68 $this->_queryString = $queryString;
78 $this->_query = $this->
buildQuery($buildDepth, $attribs);
91 if ($this->_typeNode == null)
94 return $this->
buildQuery($buildDepth, $attribs);
110 $tableArray = array($table);
111 $relationArray = array();
116 if ($buildDepth ===
false)
118 $select = $mapper->getSelectSQL(
'', null, $attribs,
true);
119 $attributeStr = $select[
'attributeStr'];
126 $operators = array(
'and',
'or',
'not',
'like',
'is',
'null');
127 $typeArray = array();
128 foreach ($tokens as $token)
130 if (strlen($token) > 0)
132 if (!in_array(strtolower($token), $operators))
138 if (!preg_match(
'/^\'|^"|^[0-9]/', $token))
141 $token = str_replace(
'`',
'', $token);
142 $pos = strpos($token,
'.');
146 $type = substr($token, 0, $pos);
147 $attribute = substr($token, $pos+1, strlen($token));
151 $queryString = str_replace($type.
'.'.$attribute, $table.
'.'.$column, $queryString);
153 if ($type != $this->_typeNode->getType())
155 array_push($typeArray, $type);
156 array_push($tableArray, $table);
163 WCMFException::throwEx(
"Please specify the type to that the attribute '".$token.
"' belongs: e.g. Author.name.", __FILE__, __LINE__);
170 $typeArray = array_unique($typeArray);
171 foreach ($typeArray as $type)
173 if ($type != $this->_typeNode->getType())
177 if ($parents != null &&
sizeof($parents) > 0)
179 array_push($parents, $this->_typeNode);
180 for ($i=0; $i<
sizeof($parents)-1; $i++)
183 array_push($relationArray, $relationStr);
190 if ($children != null &&
sizeof($children) > 0)
192 array_unshift($children, $this->_typeNode);
193 for ($i=0; $i<
sizeof($children)-1; $i++)
196 array_push($relationArray, $relationStr);
200 WCMFException::throwEx(
"There is no connection between '".$this->_typeNode->getType().
"' and '".$type.
"'.", __FILE__, __LINE__);
206 $tableStr = $select[
'tableStr'];
207 foreach ($tableArray as $table)
209 if (preg_match(
'/\b'.$table.
'\b/', $tableStr) == 0)
210 $tableStr = $table.
", ".$tableStr;
214 $query =
'SELECT DISTINCT '.$attributeStr.
' FROM '.$tableStr;
215 if (strlen($queryString) > 0)
216 $query .=
' WHERE '.$queryString;
218 $query .=
' WHERE 1';
219 if (
sizeof($relationArray) > 0)
220 $query .=
' AND '.join(
' AND ', array_unique($relationArray));
236 $table = $mapper->getTableName();
237 $column = $mapper->getColumnName($valueName);
238 return array($table, $column);
executeString($type, $query, $buildDepth, $orderby=null, &$pagingInfo)
get($message, $parameters=null, $domain='', $lang='')
getRelationCondition(&$parentTpl, &$childTpl)
throwEx($message, $file='', $line='')
getConnectionToAncestor(&$tplNode, $ancestorType, $nodes=null)
buildQuery($buildDepth, $attribs=null)
execute($type, $queryString, $buildDepth, $orderby=null, &$pagingInfo, $attribs=null)
mapToDatabase($type, $valueName)
getTableName(&$tpl, $asAliasString=false)
splitQuoted($str, $delim='//', $quoteChr='"', $preserve=false)
StringQuery executes queries from a string representation. Queries are constructed like WHERE clauses...
getConnectionToDescendant(&$tplNode, $descendantType, $nodes=null)
toString($buildDepth=BUILDDEPTH_SINGLE, $attribs=null)