dbobjectsearch.class.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Define filters for a given class of objects (formerly named "filter")
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. define('TREE_OPERATOR_EQUALS', 0);
  25. define('TREE_OPERATOR_BELOW', 1);
  26. define('TREE_OPERATOR_BELOW_STRICT', 2);
  27. define('TREE_OPERATOR_NOT_BELOW', 3);
  28. define('TREE_OPERATOR_NOT_BELOW_STRICT', 4);
  29. class DBObjectSearch
  30. {
  31. private $m_aClasses; // queried classes (alias => class name), the first item is the class corresponding to this filter (the rest is coming from subfilters)
  32. private $m_aSelectedClasses; // selected for the output (alias => class name)
  33. private $m_oSearchCondition;
  34. private $m_aParams;
  35. private $m_aFullText;
  36. private $m_aPointingTo;
  37. private $m_aReferencedBy;
  38. private $m_aRelatedTo;
  39. // By default, some information may be hidden to the current user
  40. // But it may happen that we need to disable that feature
  41. private $m_bAllowAllData = false;
  42. public function __construct($sClass, $sClassAlias = null)
  43. {
  44. if (is_null($sClassAlias)) $sClassAlias = $sClass;
  45. assert('is_string($sClass)');
  46. assert('MetaModel::IsValidClass($sClass)'); // #@# could do better than an assert, or at least give the caller's reference
  47. // => idee d'un assert avec call stack (autre utilisation = echec sur query SQL)
  48. $this->m_aSelectedClasses = array($sClassAlias => $sClass);
  49. $this->m_aClasses = array($sClassAlias => $sClass);
  50. $this->m_oSearchCondition = new TrueExpression;
  51. $this->m_aParams = array();
  52. $this->m_aFullText = array();
  53. $this->m_aPointingTo = array();
  54. $this->m_aReferencedBy = array();
  55. $this->m_aRelatedTo = array();
  56. }
  57. public function AllowAllData() {$this->m_bAllowAllData = true;}
  58. public function IsAllDataAllowed() {return $this->m_bAllowAllData;}
  59. public function GetClassName($sAlias) {return $this->m_aClasses[$sAlias];}
  60. public function GetJoinedClasses() {return $this->m_aClasses;}
  61. public function GetClass()
  62. {
  63. return reset($this->m_aSelectedClasses);
  64. }
  65. public function GetClassAlias()
  66. {
  67. reset($this->m_aSelectedClasses);
  68. return key($this->m_aSelectedClasses);
  69. }
  70. public function GetFirstJoinedClass()
  71. {
  72. return reset($this->m_aClasses);
  73. }
  74. public function GetFirstJoinedClassAlias()
  75. {
  76. reset($this->m_aClasses);
  77. return key($this->m_aClasses);
  78. }
  79. public function SetSelectedClasses($aNewSet)
  80. {
  81. $this->m_aSelectedClasses = array();
  82. foreach ($aNewSet as $sAlias => $sClass)
  83. {
  84. if (!array_key_exists($sAlias, $this->m_aClasses))
  85. {
  86. throw new CoreException('Unexpected class alias', array('alias'=>$sAlias, 'expected'=>$this->m_aClasses));
  87. }
  88. $this->m_aSelectedClasses[$sAlias] = $sClass;
  89. }
  90. }
  91. public function GetSelectedClasses()
  92. {
  93. return $this->m_aSelectedClasses;
  94. }
  95. public function IsAny()
  96. {
  97. // #@# todo - if (!$this->m_oSearchCondition->IsTrue()) return false;
  98. if (count($this->m_aFullText) > 0) return false;
  99. if (count($this->m_aPointingTo) > 0) return false;
  100. if (count($this->m_aReferencedBy) > 0) return false;
  101. if (count($this->m_aRelatedTo) > 0) return false;
  102. if (count($this->m_aParentConditions) > 0) return false;
  103. return true;
  104. }
  105. public function Describe()
  106. {
  107. // To replace __Describe
  108. }
  109. public function DescribeConditionPointTo($sExtKeyAttCode, $aPointingTo)
  110. {
  111. if (empty($aPointingTo)) return "";
  112. foreach($aPointingTo as $iOperatorCode => $oFilter)
  113. {
  114. if ($oFilter->IsAny()) break;
  115. $oAtt = MetaModel::GetAttributeDef($this->GetClass(), $sExtKeyAttCode);
  116. $sOperator = '';
  117. switch($iOperatorCode)
  118. {
  119. case TREE_OPERATOR_EQUALS:
  120. $sOperator = 'having';
  121. break;
  122. case TREE_OPERATOR_BELOW:
  123. $sOperator = 'below';
  124. break;
  125. case TREE_OPERATOR_BELOW_STRICT:
  126. $sOperator = 'strictly below';
  127. break;
  128. case TREE_OPERATOR_NOT_BELOW:
  129. $sOperator = 'not below';
  130. break;
  131. case TREE_OPERATOR_NOT_BELOW_STRICT:
  132. $sOperator = 'strictly not below';
  133. break;
  134. }
  135. $aDescription[] = $oAtt->GetLabel()."$sOperator ({$oFilter->DescribeConditions()})";
  136. }
  137. return implode(' and ', $aDescription);
  138. }
  139. public function DescribeConditionRefBy($sForeignClass, $sForeignExtKeyAttCode)
  140. {
  141. if (!isset($this->m_aReferencedBy[$sForeignClass][$sForeignExtKeyAttCode])) return "";
  142. $oFilter = $this->m_aReferencedBy[$sForeignClass][$sForeignExtKeyAttCode];
  143. if ($oFilter->IsAny()) return "";
  144. $oAtt = MetaModel::GetAttributeDef($sForeignClass, $sForeignExtKeyAttCode);
  145. return "being ".$oAtt->GetLabel()." for ".$sForeignClass."s in ({$oFilter->DescribeConditions()})";
  146. }
  147. public function DescribeConditionRelTo($aRelInfo)
  148. {
  149. $oFilter = $aRelInfo['flt'];
  150. $sRelCode = $aRelInfo['relcode'];
  151. $iMaxDepth = $aRelInfo['maxdepth'];
  152. return "related ($sRelCode... peut mieux faire !, $iMaxDepth dig depth) to a {$oFilter->GetClass()} ({$oFilter->DescribeConditions()})";
  153. }
  154. public function DescribeConditions()
  155. {
  156. $aConditions = array();
  157. $aCondFT = array();
  158. foreach($this->m_aFullText as $sFullText)
  159. {
  160. $aCondFT[] = " contain word(s) '$sFullText'";
  161. }
  162. if (count($aCondFT) > 0)
  163. {
  164. $aConditions[] = "which ".implode(" and ", $aCondFT);
  165. }
  166. // #@# todo - review textual description of the JOIN and search condition (is that still feasible?)
  167. $aConditions[] = $this->RenderCondition();
  168. $aCondPoint = array();
  169. foreach($this->m_aPointingTo as $sExtKeyAttCode => $aPointingTo)
  170. {
  171. $aCondPoint[] = $this->DescribeConditionPointTo($sExtKeyAttCode, $aPointingTo);
  172. }
  173. if (count($aCondPoint) > 0)
  174. {
  175. $aConditions[] = implode(" and ", $aCondPoint);
  176. }
  177. $aCondReferred= array();
  178. foreach($this->m_aReferencedBy as $sForeignClass=>$aReferences)
  179. {
  180. foreach($aReferences as $sForeignExtKeyAttCode=>$oForeignFilter)
  181. {
  182. if ($oForeignFilter->IsAny()) continue;
  183. $aCondReferred[] = $this->DescribeConditionRefBy($sForeignClass, $sForeignExtKeyAttCode);
  184. }
  185. }
  186. foreach ($this->m_aRelatedTo as $aRelInfo)
  187. {
  188. $aCondReferred[] = $this->DescribeConditionRelTo($aRelInfo);
  189. }
  190. if (count($aCondReferred) > 0)
  191. {
  192. $aConditions[] = implode(" and ", $aCondReferred);
  193. }
  194. foreach ($this->m_aParentConditions as $aRelInfo)
  195. {
  196. $aCondReferred[] = $this->DescribeConditionParent($aRelInfo);
  197. }
  198. return implode(" and ", $aConditions);
  199. }
  200. public function __DescribeHTML()
  201. {
  202. try
  203. {
  204. $sConditionDesc = $this->DescribeConditions();
  205. }
  206. catch (MissingQueryArgument $e)
  207. {
  208. $sConditionDesc = '?missing query argument?';
  209. }
  210. if (!empty($sConditionDesc))
  211. {
  212. return "Objects of class '".$this->GetClass()."', $sConditionDesc";
  213. }
  214. return "Any object of class '".$this->GetClass()."'";
  215. }
  216. protected function TransferConditionExpression($oFilter, $aTranslation)
  217. {
  218. $oTranslated = $oFilter->GetCriteria()->Translate($aTranslation, false, false /* leave unresolved fields */);
  219. //echo "<p>TransferConditionExpression:<br/>";
  220. //echo "Adding Conditions:<br/><pre>".print_r($oTranslated, true)."</pre>\n";
  221. //echo "</p>";
  222. $this->AddConditionExpression($oTranslated);
  223. // #@# what about collisions in parameter names ???
  224. $this->m_aParams = array_merge($this->m_aParams, $oFilter->m_aParams);
  225. }
  226. public function ResetCondition()
  227. {
  228. $this->m_oSearchCondition = new TrueExpression();
  229. $this->m_aParentConditions = array();
  230. // ? is that usefull/enough, do I need to rebuild the list after the subqueries ?
  231. }
  232. public function MergeConditionExpression($oExpression)
  233. {
  234. $this->m_oSearchCondition = $this->m_oSearchCondition->LogOr($oExpression);
  235. }
  236. public function AddConditionExpression($oExpression)
  237. {
  238. $this->m_oSearchCondition = $this->m_oSearchCondition->LogAnd($oExpression);
  239. }
  240. public function AddNameCondition($sName)
  241. {
  242. $oValueExpr = new ScalarExpression($sName);
  243. $oNameExpr = new FieldExpression('friendlyname', $this->GetClassAlias());
  244. $oNewCondition = new BinaryExpression($oNameExpr, '=', $oValueExpr);
  245. $this->AddConditionExpression($oNewCondition);
  246. }
  247. public function AddCondition($sFilterCode, $value, $sOpCode = null)
  248. {
  249. MyHelpers::CheckKeyInArray('filter code', $sFilterCode, MetaModel::GetClassFilterDefs($this->GetClass()));
  250. $oFilterDef = MetaModel::GetClassFilterDef($this->GetClass(), $sFilterCode);
  251. $oField = new FieldExpression($sFilterCode, $this->GetClassAlias());
  252. if (empty($sOpCode))
  253. {
  254. if ($sFilterCode == 'id')
  255. {
  256. $sOpCode = '=';
  257. }
  258. else
  259. {
  260. $oAttDef = MetaModel::GetAttributeDef($this->GetClass(), $sFilterCode);
  261. $oNewCondition = $oAttDef->GetSmartConditionExpression($value, $oField, $this->m_aParams);
  262. $this->AddConditionExpression($oNewCondition);
  263. return;
  264. }
  265. }
  266. MyHelpers::CheckKeyInArray('operator', $sOpCode, $oFilterDef->GetOperators());
  267. // Preserve backward compatibility - quick n'dirty way to change that API semantic
  268. //
  269. switch($sOpCode)
  270. {
  271. case 'SameDay':
  272. case 'SameMonth':
  273. case 'SameYear':
  274. case 'Today':
  275. case '>|':
  276. case '<|':
  277. case '=|':
  278. throw new CoreException('Deprecated operator, please consider using OQL (SQL) expressions like "(TO_DAYS(NOW()) - TO_DAYS(x)) AS AgeDays"', array('operator' => $sOpCode));
  279. break;
  280. case "IN":
  281. if (!is_array($value)) $value = array($value);
  282. $sListExpr = '('.implode(', ', CMDBSource::Quote($value)).')';
  283. $sOQLCondition = $oField->Render()." IN $sListExpr";
  284. break;
  285. case "NOTIN":
  286. if (!is_array($value)) $value = array($value);
  287. $sListExpr = '('.implode(', ', CMDBSource::Quote($value)).')';
  288. $sOQLCondition = $oField->Render()." NOT IN $sListExpr";
  289. break;
  290. case 'Contains':
  291. $this->m_aParams[$sFilterCode] = "%$value%";
  292. $sOperator = 'LIKE';
  293. break;
  294. case 'Begins with':
  295. $this->m_aParams[$sFilterCode] = "$value%";
  296. $sOperator = 'LIKE';
  297. break;
  298. case 'Finishes with':
  299. $this->m_aParams[$sFilterCode] = "%$value";
  300. $sOperator = 'LIKE';
  301. break;
  302. default:
  303. $this->m_aParams[$sFilterCode] = $value;
  304. $sOperator = $sOpCode;
  305. }
  306. switch($sOpCode)
  307. {
  308. case "IN":
  309. case "NOTIN":
  310. $oNewCondition = Expression::FromOQL($sOQLCondition);
  311. break;
  312. case 'Contains':
  313. case 'Begins with':
  314. case 'Finishes with':
  315. default:
  316. $oRightExpr = new VariableExpression($sFilterCode);
  317. $oNewCondition = new BinaryExpression($oField, $sOperator, $oRightExpr);
  318. }
  319. $this->AddConditionExpression($oNewCondition);
  320. }
  321. /**
  322. * Specify a condition on external keys or link sets
  323. * @param sAttSpec Can be either an attribute code or extkey->[sAttSpec] or linkset->[sAttSpec] and so on, recursively
  324. * Example: infra_list->ci_id->location_id->country
  325. * @param value The value to match
  326. * @return void
  327. */
  328. public function AddConditionAdvanced($sAttSpec, $value)
  329. {
  330. $sClass = $this->GetClass();
  331. $iPos = strpos($sAttSpec, '->');
  332. if ($iPos !== false)
  333. {
  334. $sAttCode = substr($sAttSpec, 0, $iPos);
  335. $sSubSpec = substr($sAttSpec, $iPos + 2);
  336. if (!MetaModel::IsValidAttCode($sClass, $sAttCode))
  337. {
  338. throw new Exception("Invalid attribute code '$sClass/$sAttCode' in condition specification '$sAttSpec'");
  339. }
  340. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  341. if ($oAttDef->IsLinkSet())
  342. {
  343. $sTargetClass = $oAttDef->GetLinkedClass();
  344. $sExtKeyToMe = $oAttDef->GetExtKeyToMe();
  345. $oNewFilter = new DBObjectSearch($sTargetClass);
  346. $oNewFilter->AddConditionAdvanced($sSubSpec, $value);
  347. $this->AddCondition_ReferencedBy($oNewFilter, $sExtKeyToMe);
  348. }
  349. elseif ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE))
  350. {
  351. $sTargetClass = $oAttDef->GetTargetClass(EXTKEY_ABSOLUTE);
  352. $oNewFilter = new DBObjectSearch($sTargetClass);
  353. $oNewFilter->AddConditionAdvanced($sSubSpec, $value);
  354. $this->AddCondition_PointingTo($oNewFilter, $sAttCode);
  355. }
  356. else
  357. {
  358. throw new Exception("Attribute specification '$sAttSpec', '$sAttCode' should be either a link set or an external key");
  359. }
  360. }
  361. else
  362. {
  363. // $sAttSpec is an attribute code
  364. //
  365. $this->AddCondition($sAttSpec, $value);
  366. }
  367. }
  368. public function AddCondition_FullText($sFullText)
  369. {
  370. $this->m_aFullText[] = $sFullText;
  371. }
  372. public function AddCondition_Parent($sAttCode, $iOperatorCode, $oExpression)
  373. {
  374. $oAttDef = MetaModel::GetAttributeDef($this->GetClass(), $sAttCode);
  375. if (!$oAttDef instanceof AttributeHierarchicalKey)
  376. {
  377. throw new Exception("AddCondition_Parent can only be used on hierarchical keys. '$sAttCode' is not a hierarchical key.");
  378. }
  379. $this->m_aParentConditions[] = array(
  380. 'attCode' => $sAttCode,
  381. 'operator' => $iOperatorCode,
  382. 'expression' => $oExpression,
  383. );
  384. }
  385. protected function AddToNameSpace(&$aClassAliases, &$aAliasTranslation)
  386. {
  387. $sOrigAlias = $this->GetClassAlias();
  388. if (array_key_exists($sOrigAlias, $aClassAliases))
  389. {
  390. $sNewAlias = MetaModel::GenerateUniqueAlias($aClassAliases, $sOrigAlias, $this->GetClass());
  391. //echo "<h1>Generating a new alias for $sOrigAlias (already used). It is now: $sNewAlias</h1>\n";
  392. $this->m_aSelectedClasses[$sNewAlias] = $this->GetClass();
  393. unset($this->m_aSelectedClasses[$sOrigAlias]);
  394. $this->m_aClasses[$sNewAlias] = $this->GetClass();
  395. unset($this->m_aClasses[$sOrigAlias]);
  396. // Translate the condition expression with the new alias
  397. $aAliasTranslation[$sOrigAlias]['*'] = $sNewAlias;
  398. }
  399. //echo "<h1>Adding the alias for ".$this->GetClass().". as ".$this->GetClassAlias()."</h1>\n";
  400. // add the alias into the filter aliases list
  401. $aClassAliases[$this->GetClassAlias()] = $this->GetClass();
  402. foreach($this->m_aPointingTo as $sExtKeyAttCode=>$aPointingTo)
  403. {
  404. foreach($aPointingTo as $iOperatorCode => $oFilter)
  405. {
  406. $oFilter->AddToNameSpace($aClassAliases, $aAliasTranslation);
  407. }
  408. }
  409. foreach($this->m_aReferencedBy as $sForeignClass=>$aReferences)
  410. {
  411. foreach($aReferences as $sForeignExtKeyAttCode=>$oForeignFilter)
  412. {
  413. $oForeignFilter->AddToNameSpace($aClassAliases, $aAliasTranslation);
  414. }
  415. }
  416. }
  417. public function AddCondition_PointingTo(DBObjectSearch $oFilter, $sExtKeyAttCode, $iOperatorCode = TREE_OPERATOR_EQUALS)
  418. {
  419. $aAliasTranslation = array();
  420. $res = $this->AddCondition_PointingTo_InNameSpace($oFilter, $sExtKeyAttCode, $this->m_aClasses, $aAliasTranslation, $iOperatorCode);
  421. $this->TransferConditionExpression($oFilter, $aAliasTranslation);
  422. return $res;
  423. }
  424. protected function AddCondition_PointingTo_InNameSpace(DBObjectSearch $oFilter, $sExtKeyAttCode, &$aClassAliases, &$aAliasTranslation, $iOperatorCode)
  425. {
  426. //echo "<p style=\"color:green\">Calling: AddCondition_PointingTo_InNameSpace([".implode(',', $aClassAliases)."], [".implode(',', $aAliasTranslation)."]);</p>";
  427. if (!MetaModel::IsValidKeyAttCode($this->GetClass(), $sExtKeyAttCode))
  428. {
  429. throw new CoreWarning("The attribute code '$sExtKeyAttCode' is not an external key of the class '{$this->GetClass()}' - the condition will be ignored");
  430. }
  431. $oAttExtKey = MetaModel::GetAttributeDef($this->GetClass(), $sExtKeyAttCode);
  432. if(!MetaModel::IsSameFamilyBranch($oFilter->GetClass(), $oAttExtKey->GetTargetClass()))
  433. {
  434. throw new CoreException("The specified filter (pointing to {$oFilter->GetClass()}) is not compatible with the key '{$this->GetClass()}::$sExtKeyAttCode', which is pointing to {$oAttExtKey->GetTargetClass()}");
  435. }
  436. if(($iOperatorCode != TREE_OPERATOR_EQUALS) && !($oAttExtKey instanceof AttributeHierarchicalKey))
  437. {
  438. throw new CoreException("The specified tree operator $isOperatorCode is not applicable to the key '{$this->GetClass()}::$sExtKeyAttCode', which is not a HierarchicalKey");
  439. }
  440. if (array_key_exists($sExtKeyAttCode, $this->m_aPointingTo))
  441. {
  442. if (array_key_exists($iOperatorCode, $this->m_aPointingTo[$sExtKeyAttCode]))
  443. {
  444. // Same ext key and same operator, merge the filters together
  445. $this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode]->MergeWith_InNamespace($oFilter, $aClassAliases, $aAliasTranslation);
  446. }
  447. else
  448. {
  449. //echo "<p style=\"color:red\">Calling: AddToNameSpace([".implode(',', $aClassAliases)."], [".implode(',', $aAliasTranslation)."]);</p>";
  450. $oFilter->AddToNamespace($aClassAliases, $aAliasTranslation);
  451. $this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode] = $oFilter;
  452. }
  453. }
  454. else
  455. {
  456. //echo "<p style=\"color:red\">Calling: AddToNameSpace([".implode(',', $aClassAliases)."], [".implode(',', $aAliasTranslation)."]);</p>";
  457. $oFilter->AddToNamespace($aClassAliases, $aAliasTranslation);
  458. // #@# The condition expression found in that filter should not be used - could be another kind of structure like a join spec tree !!!!
  459. // $oNewFilter = clone $oFilter;
  460. // $oNewFilter->ResetCondition();
  461. $this->m_aPointingTo[$sExtKeyAttCode][$iOperatorCode] = $oFilter;
  462. }
  463. }
  464. public function AddCondition_ReferencedBy(DBObjectSearch $oFilter, $sForeignExtKeyAttCode)
  465. {
  466. $aAliasTranslation = array();
  467. $res = $this->AddCondition_ReferencedBy_InNameSpace($oFilter, $sForeignExtKeyAttCode, $this->m_aClasses, $aAliasTranslation);
  468. $this->TransferConditionExpression($oFilter, $aAliasTranslation);
  469. return $res;
  470. }
  471. protected function AddCondition_ReferencedBy_InNameSpace(DBObjectSearch $oFilter, $sForeignExtKeyAttCode, &$aClassAliases, &$aAliasTranslation)
  472. {
  473. $sForeignClass = $oFilter->GetClass();
  474. $sForeignClassAlias = $oFilter->GetClassAlias();
  475. if (!MetaModel::IsValidKeyAttCode($sForeignClass, $sForeignExtKeyAttCode))
  476. {
  477. throw new CoreException("The attribute code '$sForeignExtKeyAttCode' is not an external key of the class '{$sForeignClass}' - the condition will be ignored");
  478. }
  479. $oAttExtKey = MetaModel::GetAttributeDef($sForeignClass, $sForeignExtKeyAttCode);
  480. if(!MetaModel::IsSameFamilyBranch($this->GetClass(), $oAttExtKey->GetTargetClass()))
  481. {
  482. throw new CoreException("The specified filter (objects referencing an object of class {$this->GetClass()}) is not compatible with the key '{$sForeignClass}::$sForeignExtKeyAttCode', which is pointing to {$oAttExtKey->GetTargetClass()}");
  483. }
  484. if (array_key_exists($sForeignClass, $this->m_aReferencedBy) && array_key_exists($sForeignExtKeyAttCode, $this->m_aReferencedBy[$sForeignClass]))
  485. {
  486. $this->m_aReferencedBy[$sForeignClass][$sForeignExtKeyAttCode]->MergeWith_InNamespace($oFilter, $aClassAliases, $aAliasTranslation);
  487. }
  488. else
  489. {
  490. $oFilter->AddToNamespace($aClassAliases, $aAliasTranslation);
  491. // #@# The condition expression found in that filter should not be used - could be another kind of structure like a join spec tree !!!!
  492. //$oNewFilter = clone $oFilter;
  493. //$oNewFilter->ResetCondition();
  494. $this->m_aReferencedBy[$sForeignClass][$sForeignExtKeyAttCode]= $oFilter;
  495. }
  496. }
  497. public function AddCondition_LinkedTo(DBObjectSearch $oLinkFilter, $sExtKeyAttCodeToMe, $sExtKeyAttCodeTarget, DBObjectSearch $oFilterTarget)
  498. {
  499. $oLinkFilterFinal = clone $oLinkFilter;
  500. // todo : new function prototype
  501. $oLinkFilterFinal->AddCondition_PointingTo($sExtKeyAttCodeToMe);
  502. $this->AddCondition_ReferencedBy($oLinkFilterFinal, $sExtKeyAttCodeToMe);
  503. }
  504. public function AddCondition_RelatedTo(DBObjectSearch $oFilter, $sRelCode, $iMaxDepth)
  505. {
  506. MyHelpers::CheckValueInArray('relation code', $sRelCode, MetaModel::EnumRelations());
  507. $this->m_aRelatedTo[] = array('flt'=>$oFilter, 'relcode'=>$sRelCode, 'maxdepth'=>$iMaxDepth);
  508. }
  509. public function MergeWith($oFilter)
  510. {
  511. $aAliasTranslation = array();
  512. $res = $this->MergeWith_InNamespace($oFilter, $this->m_aClasses, $aAliasTranslation);
  513. $this->TransferConditionExpression($oFilter, $aAliasTranslation);
  514. return $res;
  515. }
  516. protected function MergeWith_InNamespace($oFilter, &$aClassAliases, &$aAliasTranslation)
  517. {
  518. if ($this->GetClass() != $oFilter->GetClass())
  519. {
  520. throw new CoreException("Attempting to merge a filter of class '{$this->GetClass()}' with a filter of class '{$oFilter->GetClass()}'");
  521. }
  522. // Translate search condition into our aliasing scheme
  523. $aAliasTranslation[$oFilter->GetClassAlias()]['*'] = $this->GetClassAlias();
  524. $this->m_aFullText = array_merge($this->m_aFullText, $oFilter->m_aFullText);
  525. $this->m_aRelatedTo = array_merge($this->m_aRelatedTo, $oFilter->m_aRelatedTo);
  526. foreach($oFilter->m_aPointingTo as $sExtKeyAttCode=>$aPointingTo)
  527. {
  528. foreach($aPointingTo as $iOperatorCode => $oExtFilter)
  529. {
  530. $this->AddCondition_PointingTo_InNamespace($oExtFilter, $sExtKeyAttCode, $aClassAliases, $aAliasTranslation, $iOperatorCode);
  531. }
  532. }
  533. foreach($oFilter->m_aReferencedBy as $sForeignClass => $aReferences)
  534. {
  535. foreach($aReferences as $sForeignExtKeyAttCode => $oForeignFilter)
  536. {
  537. $this->AddCondition_ReferencedBy_InNamespace($oForeignFilter, $sForeignExtKeyAttCode, $aClassAliases, $aAliasTranslation);
  538. }
  539. }
  540. }
  541. public function GetCriteria() {return $this->m_oSearchCondition;}
  542. public function GetCriteria_FullText() {return $this->m_aFullText;}
  543. public function GetCriteria_PointingTo($sKeyAttCode = "")
  544. {
  545. if (empty($sKeyAttCode))
  546. {
  547. return $this->m_aPointingTo;
  548. }
  549. if (!array_key_exists($sKeyAttCode, $this->m_aPointingTo)) return array();
  550. return $this->m_aPointingTo[$sKeyAttCode];
  551. }
  552. public function GetCriteria_ReferencedBy($sRemoteClass = "", $sForeignExtKeyAttCode = "")
  553. {
  554. if (empty($sRemoteClass))
  555. {
  556. return $this->m_aReferencedBy;
  557. }
  558. if (!array_key_exists($sRemoteClass, $this->m_aReferencedBy)) return null;
  559. if (empty($sForeignExtKeyAttCode))
  560. {
  561. return $this->m_aReferencedBy[$sRemoteClass];
  562. }
  563. if (!array_key_exists($sForeignExtKeyAttCode, $this->m_aReferencedBy[$sRemoteClass])) return null;
  564. return $this->m_aReferencedBy[$sRemoteClass][$sForeignExtKeyAttCode];
  565. }
  566. public function GetCriteria_RelatedTo()
  567. {
  568. return $this->m_aRelatedTo;
  569. }
  570. public function GetInternalParams()
  571. {
  572. return $this->m_aParams;
  573. }
  574. public function RenderCondition()
  575. {
  576. return $this->m_oSearchCondition->Render($this->m_aParams, false);
  577. }
  578. public function serialize($bDevelopParams = false, $aContextParams = null)
  579. {
  580. $sOql = $this->ToOql($bDevelopParams, $aContextParams);
  581. return base64_encode(serialize(array($sOql, $this->m_aParams)));
  582. }
  583. static public function unserialize($sValue)
  584. {
  585. $aData = unserialize(base64_decode($sValue));
  586. $sOql = $aData[0];
  587. $aParams = $aData[1];
  588. // We've tried to use gzcompress/gzuncompress, but for some specific queries
  589. // it was not working at all (See Trac #193)
  590. // gzuncompress was issuing a warning "data error" and the return object was null
  591. return self::FromOQL($sOql, $aParams);
  592. }
  593. // SImple BUt Structured Query Languag - SubuSQL
  594. //
  595. static private function Value2Expression($value)
  596. {
  597. $sRet = $value;
  598. if (is_array($value))
  599. {
  600. $sRet = VS_START.implode(', ', $value).VS_END;
  601. }
  602. else if (!is_numeric($value))
  603. {
  604. $sRet = "'".addslashes($value)."'";
  605. }
  606. return $sRet;
  607. }
  608. static private function Expression2Value($sExpr)
  609. {
  610. $retValue = $sExpr;
  611. if ((substr($sExpr, 0, 1) == "'") && (substr($sExpr, -1, 1) == "'"))
  612. {
  613. $sNoQuotes = substr($sExpr, 1, -1);
  614. return stripslashes($sNoQuotes);
  615. }
  616. if ((substr($sExpr, 0, 1) == VS_START) && (substr($sExpr, -1, 1) == VS_END))
  617. {
  618. $sNoBracket = substr($sExpr, 1, -1);
  619. $aRetValue = array();
  620. foreach (explode(",", $sNoBracket) as $sItem)
  621. {
  622. $aRetValue[] = self::Expression2Value(trim($sItem));
  623. }
  624. return $aRetValue;
  625. }
  626. return $retValue;
  627. }
  628. // Alternative to object mapping: the data are transfered directly into an array
  629. // This is 10 times faster than creating a set of objects, and makes sense when optimization is required
  630. public function ToDataArray($aColumns = array(), $aOrderBy = array(), $aArgs = array())
  631. {
  632. $sSQL = MetaModel::MakeSelectQuery($this, $aOrderBy, $aArgs);
  633. $resQuery = CMDBSource::Query($sSQL);
  634. if (!$resQuery) return;
  635. if (count($aColumns) == 0)
  636. {
  637. $aColumns = array_keys(MetaModel::ListAttributeDefs($this->GetClass()));
  638. // Add the standard id (as first column)
  639. array_unshift($aColumns, 'id');
  640. }
  641. $aQueryCols = CMDBSource::GetColumns($resQuery);
  642. $sClassAlias = $this->GetClassAlias();
  643. $aColMap = array();
  644. foreach ($aColumns as $sAttCode)
  645. {
  646. $sColName = $sClassAlias.$sAttCode;
  647. if (in_array($sColName, $aQueryCols))
  648. {
  649. $aColMap[$sAttCode] = $sColName;
  650. }
  651. }
  652. $aRes = array();
  653. while ($aRow = CMDBSource::FetchArray($resQuery))
  654. {
  655. $aMappedRow = array();
  656. foreach ($aColMap as $sAttCode => $sColName)
  657. {
  658. $aMappedRow[$sAttCode] = $aRow[$sColName];
  659. }
  660. $aRes[] = $aMappedRow;
  661. }
  662. CMDBSource::FreeResult($resQuery);
  663. return $aRes;
  664. }
  665. public function ToOQL($bDevelopParams = false, $aContextParams = null)
  666. {
  667. // Currently unused, but could be useful later
  668. $bRetrofitParams = false;
  669. if ($bDevelopParams)
  670. {
  671. if (is_null($aContextParams))
  672. {
  673. $aParams = array_merge($this->m_aParams);
  674. }
  675. else
  676. {
  677. $aParams = array_merge($aContextParams, $this->m_aParams);
  678. }
  679. }
  680. else
  681. {
  682. // Leave it as is, the rendering will be made with parameters in clear
  683. $aParams = null;
  684. }
  685. $sSelectedClasses = implode(', ', array_keys($this->m_aSelectedClasses));
  686. $sRes = 'SELECT '.$sSelectedClasses.' FROM';
  687. $sRes .= ' '.$this->GetClass().' AS '.$this->GetClassAlias();
  688. $sRes .= $this->ToOQL_Joins();
  689. $sRes .= " WHERE ".$this->m_oSearchCondition->Render($aParams, $bRetrofitParams);
  690. // Temporary: add more info about other conditions, necessary to avoid strange behaviors with the cache
  691. foreach($this->m_aFullText as $sFullText)
  692. {
  693. $sRes .= " AND MATCHES '$sFullText'";
  694. }
  695. return $sRes;
  696. }
  697. protected function ToOQL_Joins()
  698. {
  699. $sRes = '';
  700. foreach($this->m_aPointingTo as $sExtKey => $aPointingTo)
  701. {
  702. foreach($aPointingTo as $iOperatorCode => $oFilter)
  703. {
  704. switch($iOperatorCode)
  705. {
  706. case TREE_OPERATOR_EQUALS:
  707. $sOperator = ' = ';
  708. break;
  709. case TREE_OPERATOR_BELOW:
  710. $sOperator = ' BELOW ';
  711. break;
  712. case TREE_OPERATOR_BELOW_STRICT:
  713. $sOperator = ' BELOW STRICT ';
  714. break;
  715. case TREE_OPERATOR_NOT_BELOW:
  716. $sOperator = ' NOT BELOW ';
  717. break;
  718. case TREE_OPERATOR_NOT_BELOW_STRICT:
  719. $sOperator = ' NOT BELOW STRICT ';
  720. break;
  721. }
  722. $sRes .= ' JOIN '.$oFilter->GetClass().' AS '.$oFilter->GetClassAlias().' ON '.$this->GetClassAlias().'.'.$sExtKey.$sOperator.$oFilter->GetClassAlias().'.id';
  723. $sRes .= $oFilter->ToOQL_Joins();
  724. }
  725. }
  726. foreach($this->m_aReferencedBy as $sForeignClass=>$aReferences)
  727. {
  728. foreach($aReferences as $sForeignExtKeyAttCode=>$oForeignFilter)
  729. {
  730. $sRes .= ' JOIN '.$oForeignFilter->GetClass().' AS '.$oForeignFilter->GetClassAlias().' ON '.$oForeignFilter->GetClassAlias().'.'.$sForeignExtKeyAttCode.' = '.$this->GetClassAlias().'.id';
  731. $sRes .= $oForeignFilter->ToOQL_Joins();
  732. }
  733. }
  734. return $sRes;
  735. }
  736. protected function OQLExpressionToCondition($sQuery, $oExpression, $aClassAliases)
  737. {
  738. if ($oExpression instanceof BinaryOqlExpression)
  739. {
  740. $sOperator = $oExpression->GetOperator();
  741. $oLeft = $this->OQLExpressionToCondition($sQuery, $oExpression->GetLeftExpr(), $aClassAliases);
  742. $oRight = $this->OQLExpressionToCondition($sQuery, $oExpression->GetRightExpr(), $aClassAliases);
  743. return new BinaryExpression($oLeft, $sOperator, $oRight);
  744. }
  745. elseif ($oExpression instanceof FieldOqlExpression)
  746. {
  747. $sClassAlias = $oExpression->GetParent();
  748. $sFltCode = $oExpression->GetName();
  749. if (empty($sClassAlias))
  750. {
  751. // Try to find an alias
  752. // Build an array of field => array of aliases
  753. $aFieldClasses = array();
  754. foreach($aClassAliases as $sAlias => $sReal)
  755. {
  756. foreach(MetaModel::GetFiltersList($sReal) as $sAnFltCode)
  757. {
  758. $aFieldClasses[$sAnFltCode][] = $sAlias;
  759. }
  760. }
  761. if (!array_key_exists($sFltCode, $aFieldClasses))
  762. {
  763. throw new OqlNormalizeException('Unknown filter code', $sQuery, $oExpression->GetNameDetails(), array_keys($aFieldClasses));
  764. }
  765. if (count($aFieldClasses[$sFltCode]) > 1)
  766. {
  767. throw new OqlNormalizeException('Ambiguous filter code', $sQuery, $oExpression->GetNameDetails());
  768. }
  769. $sClassAlias = $aFieldClasses[$sFltCode][0];
  770. }
  771. else
  772. {
  773. if (!array_key_exists($sClassAlias, $aClassAliases))
  774. {
  775. throw new OqlNormalizeException('Unknown class [alias]', $sQuery, $oExpression->GetParentDetails(), array_keys($aClassAliases));
  776. }
  777. $sClass = $aClassAliases[$sClassAlias];
  778. if (!MetaModel::IsValidFilterCode($sClass, $sFltCode))
  779. {
  780. throw new OqlNormalizeException('Unknown filter code', $sQuery, $oExpression->GetNameDetails(), MetaModel::GetFiltersList($sClass));
  781. }
  782. }
  783. return new FieldExpression($sFltCode, $sClassAlias);
  784. }
  785. elseif ($oExpression instanceof VariableOqlExpression)
  786. {
  787. return new VariableExpression($oExpression->GetName());
  788. }
  789. elseif ($oExpression instanceof TrueOqlExpression)
  790. {
  791. return new TrueExpression;
  792. }
  793. elseif ($oExpression instanceof ScalarOqlExpression)
  794. {
  795. return new ScalarExpression($oExpression->GetValue());
  796. }
  797. elseif ($oExpression instanceof ListOqlExpression)
  798. {
  799. $aItems = array();
  800. foreach ($oExpression->GetItems() as $oItemExpression)
  801. {
  802. $aItems[] = $this->OQLExpressionToCondition($sQuery, $oItemExpression, $aClassAliases);
  803. }
  804. return new ListExpression($aItems);
  805. }
  806. elseif ($oExpression instanceof FunctionOqlExpression)
  807. {
  808. $aArgs = array();
  809. foreach ($oExpression->GetArgs() as $oArgExpression)
  810. {
  811. $aArgs[] = $this->OQLExpressionToCondition($sQuery, $oArgExpression, $aClassAliases);
  812. }
  813. return new FunctionExpression($oExpression->GetVerb(), $aArgs);
  814. }
  815. elseif ($oExpression instanceof IntervalOqlExpression)
  816. {
  817. return new IntervalExpression($oExpression->GetValue(), $oExpression->GetUnit());
  818. }
  819. else
  820. {
  821. throw new CoreException('Unknown expression type', array('class'=>get_class($oExpression), 'query'=>$sQuery));
  822. }
  823. }
  824. // Create a search definition that leads to 0 result, still a valid search object
  825. static public function FromEmptySet($sClass)
  826. {
  827. $oResultFilter = new DBObjectSearch($sClass);
  828. $oResultFilter->m_oSearchCondition = new FalseExpression;
  829. return $oResultFilter;
  830. }
  831. static protected $m_aOQLQueries = array();
  832. // Do not filter out depending on user rights
  833. // In particular when we are currently in the process of evaluating the user rights...
  834. static public function FromOQL_AllData($sQuery, $aParams = null)
  835. {
  836. $oRes = self::FromOQL($sQuery, $aParams);
  837. $oRes->AllowAllData();
  838. return $oRes;
  839. }
  840. static public function FromOQL($sQuery, $aParams = null)
  841. {
  842. if (empty($sQuery)) return null;
  843. // Query caching
  844. $bOQLCacheEnabled = true;
  845. if ($bOQLCacheEnabled && array_key_exists($sQuery, self::$m_aOQLQueries))
  846. {
  847. // hit!
  848. return clone self::$m_aOQLQueries[$sQuery];
  849. }
  850. $oOql = new OqlInterpreter($sQuery);
  851. $oOqlQuery = $oOql->ParseObjectQuery();
  852. $sClass = $oOqlQuery->GetClass();
  853. $sClassAlias = $oOqlQuery->GetClassAlias();
  854. if (!MetaModel::IsValidClass($sClass))
  855. {
  856. throw new OqlNormalizeException('Unknown class', $sQuery, $oOqlQuery->GetClassDetails(), MetaModel::GetClasses());
  857. }
  858. $oResultFilter = new DBObjectSearch($sClass, $sClassAlias);
  859. $aAliases = array($sClassAlias => $sClass);
  860. // Maintain an array of filters, because the flat list is in fact referring to a tree
  861. // And this will be an easy way to dispatch the conditions
  862. // $oResultFilter will be referenced by the other filters, or the other way around...
  863. $aJoinItems = array($sClassAlias => $oResultFilter);
  864. $aJoinSpecs = $oOqlQuery->GetJoins();
  865. if (is_array($aJoinSpecs))
  866. {
  867. foreach ($aJoinSpecs as $oJoinSpec)
  868. {
  869. $sJoinClass = $oJoinSpec->GetClass();
  870. $sJoinClassAlias = $oJoinSpec->GetClassAlias();
  871. if (!MetaModel::IsValidClass($sJoinClass))
  872. {
  873. throw new OqlNormalizeException('Unknown class', $sQuery, $oJoinSpec->GetClassDetails(), MetaModel::GetClasses());
  874. }
  875. if (array_key_exists($sJoinClassAlias, $aAliases))
  876. {
  877. if ($sJoinClassAlias != $sJoinClass)
  878. {
  879. throw new OqlNormalizeException('Duplicate class alias', $sQuery, $oJoinSpec->GetClassAliasDetails());
  880. }
  881. else
  882. {
  883. throw new OqlNormalizeException('Duplicate class name', $sQuery, $oJoinSpec->GetClassDetails());
  884. }
  885. }
  886. // Assumption: ext key on the left only !!!
  887. // normalization should take care of this
  888. $oLeftField = $oJoinSpec->GetLeftField();
  889. $sFromClass = $oLeftField->GetParent();
  890. $sExtKeyAttCode = $oLeftField->GetName();
  891. $oRightField = $oJoinSpec->GetRightField();
  892. $sToClass = $oRightField->GetParent();
  893. $sPKeyDescriptor = $oRightField->GetName();
  894. if ($sPKeyDescriptor != 'id')
  895. {
  896. throw new OqlNormalizeException('Wrong format for Join clause (right hand), expecting an id', $sQuery, $oRightField->GetNameDetails(), array('id'));
  897. }
  898. $aAliases[$sJoinClassAlias] = $sJoinClass;
  899. $aJoinItems[$sJoinClassAlias] = new DBObjectSearch($sJoinClass, $sJoinClassAlias);
  900. if (!array_key_exists($sFromClass, $aJoinItems))
  901. {
  902. throw new OqlNormalizeException('Unknown class in join condition (left expression)', $sQuery, $oLeftField->GetParentDetails(), array_keys($aJoinItems));
  903. }
  904. if (!array_key_exists($sToClass, $aJoinItems))
  905. {
  906. throw new OqlNormalizeException('Unknown class in join condition (right expression)', $sQuery, $oRightField->GetParentDetails(), array_keys($aJoinItems));
  907. }
  908. $aExtKeys = array_keys(MetaModel::GetExternalKeys($aAliases[$sFromClass]));
  909. if (!in_array($sExtKeyAttCode, $aExtKeys))
  910. {
  911. throw new OqlNormalizeException('Unknown external key in join condition (left expression)', $sQuery, $oLeftField->GetNameDetails(), $aExtKeys);
  912. }
  913. if ($sFromClass == $sJoinClassAlias)
  914. {
  915. $aJoinItems[$sToClass]->AddCondition_ReferencedBy($aJoinItems[$sFromClass], $sExtKeyAttCode);
  916. }
  917. else
  918. {
  919. $sOperator = $oJoinSpec->GetOperator();
  920. switch($sOperator)
  921. {
  922. case '=':
  923. $iOperatorCode = TREE_OPERATOR_EQUALS;
  924. break;
  925. case 'BELOW':
  926. $iOperatorCode = TREE_OPERATOR_BELOW;
  927. break;
  928. case 'BELOW_STRICT':
  929. $iOperatorCode = TREE_OPERATOR_BELOW_STRICT;
  930. break;
  931. case 'NOT_BELOW':
  932. $iOperatorCode = TREE_OPERATOR_NOT_BELOW;
  933. break;
  934. case 'NOT_BELOW_STRICT':
  935. $iOperatorCode = TREE_OPERATOR_NOT_BELOW_STRICT;
  936. break;
  937. }
  938. $aJoinItems[$sFromClass]->AddCondition_PointingTo($aJoinItems[$sToClass], $sExtKeyAttCode, $iOperatorCode);
  939. }
  940. }
  941. }
  942. // Check and prepare the select information
  943. $aSelected = array();
  944. foreach ($oOqlQuery->GetSelectedClasses() as $oClassDetails)
  945. {
  946. $sClassToSelect = $oClassDetails->GetValue();
  947. if (!array_key_exists($sClassToSelect, $aAliases))
  948. {
  949. throw new OqlNormalizeException('Unknown class [alias]', $sQuery, $oClassDetails, array_keys($aAliases));
  950. }
  951. $aSelected[$sClassToSelect] = $aAliases[$sClassToSelect];
  952. }
  953. $oResultFilter->m_aClasses = $aAliases;
  954. $oResultFilter->SetSelectedClasses($aSelected);
  955. $oConditionTree = $oOqlQuery->GetCondition();
  956. if ($oConditionTree instanceof Expression)
  957. {
  958. $oResultFilter->m_oSearchCondition = $oResultFilter->OQLExpressionToCondition($sQuery, $oConditionTree, $aAliases);
  959. }
  960. if (!is_null($aParams))
  961. {
  962. $oResultFilter->m_aParams = $aParams;
  963. }
  964. if ($bOQLCacheEnabled)
  965. {
  966. self::$m_aOQLQueries[$sQuery] = clone $oResultFilter;
  967. }
  968. return $oResultFilter;
  969. }
  970. public function toxpath()
  971. {
  972. // #@# a voir...
  973. }
  974. static public function fromxpath()
  975. {
  976. // #@# a voir...
  977. }
  978. }
  979. ?>