expression.class.inc.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. <?php
  2. // Copyright (C) 2010-2017 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * General definition of an expression tree (could be OQL, SQL or whatever)
  20. *
  21. * @copyright Copyright (C) 2010-2017 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. class MissingQueryArgument extends CoreException
  25. {
  26. }
  27. abstract class Expression
  28. {
  29. /**
  30. * Perform a deep clone (as opposed to "clone" which does copy a reference to the underlying objects)
  31. **/
  32. public function DeepClone()
  33. {
  34. return unserialize(serialize($this));
  35. }
  36. // recursive translation of identifiers
  37. abstract public function GetUnresolvedFields($sAlias, &$aUnresolved);
  38. abstract public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true);
  39. // recursive rendering (aArgs used as input by default, or used as output if bRetrofitParams set to True
  40. abstract public function Render(&$aArgs = null, $bRetrofitParams = false);
  41. /**
  42. * Recursively browse the expression tree
  43. * @param Closure $callback
  44. * @return mixed
  45. */
  46. abstract public function Browse(Closure $callback);
  47. abstract public function ApplyParameters($aArgs);
  48. // recursively builds an array of class => fieldname
  49. abstract public function ListRequiredFields();
  50. // recursively list field parents ($aTable = array of sParent => dummy)
  51. abstract public function CollectUsedParents(&$aTable);
  52. abstract public function IsTrue();
  53. // recursively builds an array of [classAlias][fieldName] => value
  54. abstract public function ListConstantFields();
  55. public function RequiresField($sClass, $sFieldName)
  56. {
  57. // #@# todo - optimize : this is called quite often when building a single query !
  58. $aRequired = $this->ListRequiredFields();
  59. if (!in_array($sClass.'.'.$sFieldName, $aRequired)) return false;
  60. return true;
  61. }
  62. public function serialize()
  63. {
  64. return base64_encode($this->Render());
  65. }
  66. static public function unserialize($sValue)
  67. {
  68. return self::FromOQL(base64_decode($sValue));
  69. }
  70. /**
  71. * @param $sConditionExpr
  72. * @return Expression
  73. */
  74. static public function FromOQL($sConditionExpr)
  75. {
  76. $oOql = new OqlInterpreter($sConditionExpr);
  77. $oExpression = $oOql->ParseExpression();
  78. return $oExpression;
  79. }
  80. static public function FromSQL($sSQL)
  81. {
  82. $oSql = new SQLExpression($sSQL);
  83. return $oSql;
  84. }
  85. public function LogAnd($oExpr)
  86. {
  87. if ($this->IsTrue()) return clone $oExpr;
  88. if ($oExpr->IsTrue()) return clone $this;
  89. return new BinaryExpression($this, 'AND', $oExpr);
  90. }
  91. public function LogOr($oExpr)
  92. {
  93. return new BinaryExpression($this, 'OR', $oExpr);
  94. }
  95. abstract public function RenameParam($sOldName, $sNewName);
  96. abstract public function RenameAlias($sOldName, $sNewName);
  97. /**
  98. * Make the most relevant label, given the value of the expression
  99. *
  100. * @param DBSearch oFilter The context in which this expression has been used
  101. * @param string sValue The value returned by the query, for this expression
  102. * @param string sDefault The default value if no relevant label could be computed
  103. * @return The label
  104. */
  105. public function MakeValueLabel($oFilter, $sValue, $sDefault)
  106. {
  107. return $sDefault;
  108. }
  109. }
  110. class SQLExpression extends Expression
  111. {
  112. protected $m_sSQL;
  113. public function __construct($sSQL)
  114. {
  115. $this->m_sSQL = $sSQL;
  116. }
  117. public function IsTrue()
  118. {
  119. return false;
  120. }
  121. // recursive rendering
  122. public function Render(&$aArgs = null, $bRetrofitParams = false)
  123. {
  124. return $this->m_sSQL;
  125. }
  126. public function Browse(Closure $callback)
  127. {
  128. $callback($this);
  129. }
  130. public function ApplyParameters($aArgs)
  131. {
  132. }
  133. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  134. {
  135. }
  136. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  137. {
  138. return clone $this;
  139. }
  140. public function ListRequiredFields()
  141. {
  142. return array();
  143. }
  144. public function CollectUsedParents(&$aTable)
  145. {
  146. }
  147. public function ListConstantFields()
  148. {
  149. return array();
  150. }
  151. public function RenameParam($sOldName, $sNewName)
  152. {
  153. // Do nothing, since there is nothing to rename
  154. }
  155. public function RenameAlias($sOldName, $sNewName)
  156. {
  157. // Do nothing, since there is nothing to rename
  158. }
  159. }
  160. class BinaryExpression extends Expression
  161. {
  162. protected $m_oLeftExpr; // filter code or an SQL expression (later?)
  163. protected $m_oRightExpr;
  164. protected $m_sOperator;
  165. public function __construct($oLeftExpr, $sOperator, $oRightExpr)
  166. {
  167. if (!is_object($oLeftExpr))
  168. {
  169. throw new CoreException('Expecting an Expression object on the left hand', array('found_type' => gettype($oLeftExpr)));
  170. }
  171. if (!is_object($oRightExpr))
  172. {
  173. throw new CoreException('Expecting an Expression object on the right hand', array('found_type' => gettype($oRightExpr)));
  174. }
  175. if (!$oLeftExpr instanceof Expression)
  176. {
  177. throw new CoreException('Expecting an Expression object on the left hand', array('found_class' => get_class($oLeftExpr)));
  178. }
  179. if (!$oRightExpr instanceof Expression)
  180. {
  181. throw new CoreException('Expecting an Expression object on the right hand', array('found_class' => get_class($oRightExpr)));
  182. }
  183. $this->m_oLeftExpr = $oLeftExpr;
  184. $this->m_oRightExpr = $oRightExpr;
  185. $this->m_sOperator = $sOperator;
  186. }
  187. public function IsTrue()
  188. {
  189. // return true if we are certain that it will be true
  190. if ($this->m_sOperator == 'AND')
  191. {
  192. if ($this->m_oLeftExpr->IsTrue() && $this->m_oRightExpr->IsTrue()) return true;
  193. }
  194. elseif ($this->m_sOperator == 'OR')
  195. {
  196. if ($this->m_oLeftExpr->IsTrue() || $this->m_oRightExpr->IsTrue()) return true;
  197. }
  198. return false;
  199. }
  200. public function GetLeftExpr()
  201. {
  202. return $this->m_oLeftExpr;
  203. }
  204. public function GetRightExpr()
  205. {
  206. return $this->m_oRightExpr;
  207. }
  208. public function GetOperator()
  209. {
  210. return $this->m_sOperator;
  211. }
  212. // recursive rendering
  213. public function Render(&$aArgs = null, $bRetrofitParams = false)
  214. {
  215. $sOperator = $this->GetOperator();
  216. $sLeft = $this->GetLeftExpr()->Render($aArgs, $bRetrofitParams);
  217. $sRight = $this->GetRightExpr()->Render($aArgs, $bRetrofitParams);
  218. return "($sLeft $sOperator $sRight)";
  219. }
  220. public function Browse(Closure $callback)
  221. {
  222. $callback($this);
  223. $this->m_oLeftExpr->Browse($callback);
  224. $this->m_oRightExpr->Browse($callback);
  225. }
  226. public function ApplyParameters($aArgs)
  227. {
  228. if ($this->m_oLeftExpr instanceof VariableExpression)
  229. {
  230. $this->m_oLeftExpr = $this->m_oLeftExpr->GetAsScalar($aArgs);
  231. }
  232. else //if ($this->m_oLeftExpr instanceof Expression)
  233. {
  234. $this->m_oLeftExpr->ApplyParameters($aArgs);
  235. }
  236. if ($this->m_oRightExpr instanceof VariableExpression)
  237. {
  238. $this->m_oRightExpr = $this->m_oRightExpr->GetAsScalar($aArgs);
  239. }
  240. else //if ($this->m_oRightExpr instanceof Expression)
  241. {
  242. $this->m_oRightExpr->ApplyParameters($aArgs);
  243. }
  244. }
  245. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  246. {
  247. $this->GetLeftExpr()->GetUnresolvedFields($sAlias, $aUnresolved);
  248. $this->GetRightExpr()->GetUnresolvedFields($sAlias, $aUnresolved);
  249. }
  250. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  251. {
  252. $oLeft = $this->GetLeftExpr()->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  253. $oRight = $this->GetRightExpr()->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  254. return new BinaryExpression($oLeft, $this->GetOperator(), $oRight);
  255. }
  256. public function ListRequiredFields()
  257. {
  258. $aLeft = $this->GetLeftExpr()->ListRequiredFields();
  259. $aRight = $this->GetRightExpr()->ListRequiredFields();
  260. return array_merge($aLeft, $aRight);
  261. }
  262. public function CollectUsedParents(&$aTable)
  263. {
  264. $this->GetLeftExpr()->CollectUsedParents($aTable);
  265. $this->GetRightExpr()->CollectUsedParents($aTable);
  266. }
  267. /**
  268. * List all constant expression of the form <field> = <scalar> or <field> = :<variable>
  269. * Could be extended to support <field> = <function><constant_expression>
  270. */
  271. public function ListConstantFields()
  272. {
  273. $aResult = array();
  274. if ($this->m_sOperator == '=')
  275. {
  276. if (($this->m_oLeftExpr instanceof FieldExpression) && ($this->m_oRightExpr instanceof ScalarExpression))
  277. {
  278. $aResult[$this->m_oLeftExpr->GetParent()][$this->m_oLeftExpr->GetName()] = $this->m_oRightExpr;
  279. }
  280. else if (($this->m_oRightExpr instanceof FieldExpression) && ($this->m_oLeftExpr instanceof ScalarExpression))
  281. {
  282. $aResult[$this->m_oRightExpr->GetParent()][$this->m_oRightExpr->GetName()] = $this->m_oLeftExpr;
  283. }
  284. else if (($this->m_oLeftExpr instanceof FieldExpression) && ($this->m_oRightExpr instanceof VariableExpression))
  285. {
  286. $aResult[$this->m_oLeftExpr->GetParent()][$this->m_oLeftExpr->GetName()] = $this->m_oRightExpr;
  287. }
  288. else if (($this->m_oRightExpr instanceof FieldExpression) && ($this->m_oLeftExpr instanceof VariableExpression))
  289. {
  290. $aResult[$this->m_oRightExpr->GetParent()][$this->m_oRightExpr->GetName()] = $this->m_oLeftExpr;
  291. }
  292. }
  293. else if ($this->m_sOperator == 'AND')
  294. {
  295. // Strictly, this should be done only for the AND operator
  296. $aResult = array_merge_recursive($this->m_oRightExpr->ListConstantFields(), $this->m_oLeftExpr->ListConstantFields());
  297. }
  298. return $aResult;
  299. }
  300. public function RenameParam($sOldName, $sNewName)
  301. {
  302. $this->GetLeftExpr()->RenameParam($sOldName, $sNewName);
  303. $this->GetRightExpr()->RenameParam($sOldName, $sNewName);
  304. }
  305. public function RenameAlias($sOldName, $sNewName)
  306. {
  307. $this->GetLeftExpr()->RenameAlias($sOldName, $sNewName);
  308. $this->GetRightExpr()->RenameAlias($sOldName, $sNewName);
  309. }
  310. }
  311. class UnaryExpression extends Expression
  312. {
  313. protected $m_value;
  314. public function __construct($value)
  315. {
  316. $this->m_value = $value;
  317. }
  318. public function IsTrue()
  319. {
  320. // return true if we are certain that it will be true
  321. return ($this->m_value == 1);
  322. }
  323. public function GetValue()
  324. {
  325. return $this->m_value;
  326. }
  327. // recursive rendering
  328. public function Render(&$aArgs = null, $bRetrofitParams = false)
  329. {
  330. return CMDBSource::Quote($this->m_value);
  331. }
  332. public function Browse(Closure $callback)
  333. {
  334. $callback($this);
  335. }
  336. public function ApplyParameters($aArgs)
  337. {
  338. }
  339. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  340. {
  341. }
  342. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  343. {
  344. return clone $this;
  345. }
  346. public function ListRequiredFields()
  347. {
  348. return array();
  349. }
  350. public function CollectUsedParents(&$aTable)
  351. {
  352. }
  353. public function ListConstantFields()
  354. {
  355. return array();
  356. }
  357. public function RenameParam($sOldName, $sNewName)
  358. {
  359. // Do nothing
  360. // really ? what about :param{$iParamIndex} ??
  361. }
  362. public function RenameAlias($sOldName, $sNewName)
  363. {
  364. // Do nothing
  365. }
  366. }
  367. class ScalarExpression extends UnaryExpression
  368. {
  369. public function __construct($value)
  370. {
  371. if (!is_scalar($value) && !is_null($value) && (!$value instanceof OqlHexValue))
  372. {
  373. throw new CoreException('Attempt to create a scalar expression from a non scalar', array('var_type'=>gettype($value)));
  374. }
  375. parent::__construct($value);
  376. }
  377. // recursive rendering
  378. public function Render(&$aArgs = null, $bRetrofitParams = false)
  379. {
  380. if (is_null($this->m_value))
  381. {
  382. $sRet = 'NULL';
  383. }
  384. else
  385. {
  386. $sRet = CMDBSource::Quote($this->m_value);
  387. }
  388. return $sRet;
  389. }
  390. public function GetAsScalar($aArgs)
  391. {
  392. return clone $this;
  393. }
  394. }
  395. class TrueExpression extends ScalarExpression
  396. {
  397. public function __construct()
  398. {
  399. parent::__construct(1);
  400. }
  401. public function IsTrue()
  402. {
  403. return true;
  404. }
  405. }
  406. class FalseExpression extends ScalarExpression
  407. {
  408. public function __construct()
  409. {
  410. parent::__construct(0);
  411. }
  412. public function IsTrue()
  413. {
  414. return false;
  415. }
  416. }
  417. class FieldExpression extends UnaryExpression
  418. {
  419. protected $m_sParent;
  420. protected $m_sName;
  421. public function __construct($sName, $sParent = '')
  422. {
  423. parent::__construct("$sParent.$sName");
  424. $this->m_sParent = $sParent;
  425. $this->m_sName = $sName;
  426. }
  427. public function IsTrue()
  428. {
  429. // return true if we are certain that it will be true
  430. return false;
  431. }
  432. public function GetParent() {return $this->m_sParent;}
  433. public function GetName() {return $this->m_sName;}
  434. public function SetParent($sParent)
  435. {
  436. $this->m_sParent = $sParent;
  437. $this->m_value = $sParent.'.'.$this->m_sName;
  438. }
  439. // recursive rendering
  440. public function Render(&$aArgs = null, $bRetrofitParams = false)
  441. {
  442. if (empty($this->m_sParent))
  443. {
  444. return "`{$this->m_sName}`";
  445. }
  446. return "`{$this->m_sParent}`.`{$this->m_sName}`";
  447. }
  448. public function ListRequiredFields()
  449. {
  450. return array($this->m_sParent.'.'.$this->m_sName);
  451. }
  452. public function CollectUsedParents(&$aTable)
  453. {
  454. $aTable[$this->m_sParent] = true;
  455. }
  456. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  457. {
  458. if ($this->m_sParent == $sAlias)
  459. {
  460. // Add a reference to the field
  461. $aUnresolved[$this->m_sName] = $this;
  462. }
  463. elseif ($sAlias == '')
  464. {
  465. // An empty alias means "any alias"
  466. // In such a case, the results are indexed differently
  467. $aUnresolved[$this->m_sParent][$this->m_sName] = $this;
  468. }
  469. }
  470. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  471. {
  472. if (!array_key_exists($this->m_sParent, $aTranslationData))
  473. {
  474. if ($bMatchAll) throw new CoreException('Unknown parent id in translation table', array('parent_id' => $this->m_sParent, 'translation_table' => array_keys($aTranslationData)));
  475. return clone $this;
  476. }
  477. if (!array_key_exists($this->m_sName, $aTranslationData[$this->m_sParent]))
  478. {
  479. if (!array_key_exists('*', $aTranslationData[$this->m_sParent]))
  480. {
  481. // #@# debug - if ($bMatchAll) MyHelpers::var_dump_html($aTranslationData, true);
  482. if ($bMatchAll) throw new CoreException('Unknown name in translation table', array('name' => $this->m_sName, 'parent_id' => $this->m_sParent, 'translation_table' => array_keys($aTranslationData[$this->m_sParent])));
  483. return clone $this;
  484. }
  485. $sNewParent = $aTranslationData[$this->m_sParent]['*'];
  486. $sNewName = $this->m_sName;
  487. if ($bMarkFieldsAsResolved)
  488. {
  489. $oRet = new FieldExpressionResolved($sNewName, $sNewParent);
  490. }
  491. else
  492. {
  493. $oRet = new FieldExpression($sNewName, $sNewParent);
  494. }
  495. }
  496. else
  497. {
  498. $oRet = $aTranslationData[$this->m_sParent][$this->m_sName];
  499. }
  500. return $oRet;
  501. }
  502. /**
  503. * Make the most relevant label, given the value of the expression
  504. *
  505. * @param DBSearch oFilter The context in which this expression has been used
  506. * @param string sValue The value returned by the query, for this expression
  507. * @param string sDefault The default value if no relevant label could be computed
  508. * @return The label
  509. */
  510. public function MakeValueLabel($oFilter, $sValue, $sDefault)
  511. {
  512. $sAttCode = $this->GetName();
  513. $sParentAlias = $this->GetParent();
  514. $aSelectedClasses = $oFilter->GetSelectedClasses();
  515. $sClass = $aSelectedClasses[$sParentAlias];
  516. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  517. // Set a default value for the general case
  518. $sRes = $oAttDef->GetAsHtml($sValue);
  519. // Exceptions...
  520. if ($oAttDef->IsExternalKey())
  521. {
  522. $sObjClass = $oAttDef->GetTargetClass();
  523. $iObjKey = (int)$sValue;
  524. if ($iObjKey > 0)
  525. {
  526. $oObject = MetaModel::GetObjectWithArchive($sObjClass, $iObjKey);
  527. $sRes = $oObject->GetHyperlink();
  528. }
  529. else
  530. {
  531. // Undefined
  532. $sRes = DBObject::MakeHyperLink($sObjClass, 0);
  533. }
  534. }
  535. elseif ($oAttDef->IsExternalField())
  536. {
  537. if (is_null($sValue))
  538. {
  539. $sRes = Dict::S('UI:UndefinedObject');
  540. }
  541. }
  542. return $sRes;
  543. }
  544. public function RenameAlias($sOldName, $sNewName)
  545. {
  546. if ($this->m_sParent == $sOldName)
  547. {
  548. $this->m_sParent = $sNewName;
  549. }
  550. }
  551. }
  552. // Has been resolved into an SQL expression
  553. class FieldExpressionResolved extends FieldExpression
  554. {
  555. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  556. {
  557. }
  558. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  559. {
  560. return clone $this;
  561. }
  562. }
  563. class VariableExpression extends UnaryExpression
  564. {
  565. protected $m_sName;
  566. public function __construct($sName)
  567. {
  568. parent::__construct($sName);
  569. $this->m_sName = $sName;
  570. }
  571. public function IsTrue()
  572. {
  573. // return true if we are certain that it will be true
  574. return false;
  575. }
  576. public function GetName() {return $this->m_sName;}
  577. // recursive rendering
  578. public function Render(&$aArgs = null, $bRetrofitParams = false)
  579. {
  580. if (is_null($aArgs))
  581. {
  582. return ':'.$this->m_sName;
  583. }
  584. elseif (array_key_exists($this->m_sName, $aArgs))
  585. {
  586. $res = CMDBSource::Quote($aArgs[$this->m_sName]);
  587. if (is_array($res))
  588. {
  589. $res = implode(', ', $res);
  590. }
  591. return $res;
  592. }
  593. elseif (($iPos = strpos($this->m_sName, '->')) !== false)
  594. {
  595. $sParamName = substr($this->m_sName, 0, $iPos);
  596. if (array_key_exists($sParamName.'->object()', $aArgs))
  597. {
  598. $sAttCode = substr($this->m_sName, $iPos + 2);
  599. $oObj = $aArgs[$sParamName.'->object()'];
  600. if ($sAttCode == 'id')
  601. {
  602. return CMDBSource::Quote($oObj->GetKey());
  603. }
  604. return CMDBSource::Quote($oObj->Get($sAttCode));
  605. }
  606. }
  607. if ($bRetrofitParams)
  608. {
  609. $aArgs[$this->m_sName] = null;
  610. return ':'.$this->m_sName;
  611. }
  612. else
  613. {
  614. throw new MissingQueryArgument('Missing query argument', array('expecting'=>$this->m_sName, 'available'=>array_keys($aArgs)));
  615. }
  616. }
  617. public function RenameParam($sOldName, $sNewName)
  618. {
  619. if ($this->m_sName == $sOldName)
  620. {
  621. $this->m_sName = $sNewName;
  622. }
  623. }
  624. public function GetAsScalar($aArgs)
  625. {
  626. $oRet = null;
  627. if (array_key_exists($this->m_sName, $aArgs))
  628. {
  629. $oRet = new ScalarExpression($aArgs[$this->m_sName]);
  630. }
  631. elseif (($iPos = strpos($this->m_sName, '->')) !== false)
  632. {
  633. $sParamName = substr($this->m_sName, 0, $iPos);
  634. if (array_key_exists($sParamName.'->object()', $aArgs))
  635. {
  636. $sAttCode = substr($this->m_sName, $iPos + 2);
  637. $oObj = $aArgs[$sParamName.'->object()'];
  638. if ($sAttCode == 'id')
  639. {
  640. $oRet = new ScalarExpression($oObj->GetKey());
  641. }
  642. elseif (MetaModel::IsValidAttCode(get_class($oObj), $sAttCode))
  643. {
  644. $oRet = new ScalarExpression($oObj->Get($sAttCode));
  645. }
  646. else
  647. {
  648. throw new CoreException("Query argument {$this->m_sName} not matching any attribute of class ".get_class($oObj));
  649. }
  650. }
  651. }
  652. if (is_null($oRet))
  653. {
  654. throw new MissingQueryArgument('Missing query argument', array('expecting'=>$this->m_sName, 'available'=>array_keys($aArgs)));
  655. }
  656. return $oRet;
  657. }
  658. }
  659. // Temporary, until we implement functions and expression casting!
  660. // ... or until we implement a real full text search based in the MATCH() expression
  661. class ListExpression extends Expression
  662. {
  663. protected $m_aExpressions;
  664. public function __construct($aExpressions)
  665. {
  666. $this->m_aExpressions = $aExpressions;
  667. }
  668. public static function FromScalars($aScalars)
  669. {
  670. $aExpressions = array();
  671. foreach($aScalars as $value)
  672. {
  673. $aExpressions[] = new ScalarExpression($value);
  674. }
  675. return new ListExpression($aExpressions);
  676. }
  677. public function IsTrue()
  678. {
  679. // return true if we are certain that it will be true
  680. return false;
  681. }
  682. public function GetItems()
  683. {
  684. return $this->m_aExpressions;
  685. }
  686. // recursive rendering
  687. public function Render(&$aArgs = null, $bRetrofitParams = false)
  688. {
  689. $aRes = array();
  690. foreach ($this->m_aExpressions as $oExpr)
  691. {
  692. $aRes[] = $oExpr->Render($aArgs, $bRetrofitParams);
  693. }
  694. return '('.implode(', ', $aRes).')';
  695. }
  696. public function Browse(Closure $callback)
  697. {
  698. $callback($this);
  699. foreach ($this->m_aExpressions as $oExpr)
  700. {
  701. $oExpr->Browse($callback);
  702. }
  703. }
  704. public function ApplyParameters($aArgs)
  705. {
  706. $aRes = array();
  707. foreach ($this->m_aExpressions as $idx => $oExpr)
  708. {
  709. if ($oExpr instanceof VariableExpression)
  710. {
  711. $this->m_aExpressions[$idx] = $oExpr->GetAsScalar();
  712. }
  713. else
  714. {
  715. $oExpr->ApplyParameters($aArgs);
  716. }
  717. }
  718. }
  719. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  720. {
  721. foreach ($this->m_aExpressions as $oExpr)
  722. {
  723. $oExpr->GetUnresolvedFields($sAlias, $aUnresolved);
  724. }
  725. }
  726. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  727. {
  728. $aRes = array();
  729. foreach ($this->m_aExpressions as $oExpr)
  730. {
  731. $aRes[] = $oExpr->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  732. }
  733. return new ListExpression($aRes);
  734. }
  735. public function ListRequiredFields()
  736. {
  737. $aRes = array();
  738. foreach ($this->m_aExpressions as $oExpr)
  739. {
  740. $aRes = array_merge($aRes, $oExpr->ListRequiredFields());
  741. }
  742. return $aRes;
  743. }
  744. public function CollectUsedParents(&$aTable)
  745. {
  746. foreach ($this->m_aExpressions as $oExpr)
  747. {
  748. $oExpr->CollectUsedParents($aTable);
  749. }
  750. }
  751. public function ListConstantFields()
  752. {
  753. $aRes = array();
  754. foreach ($this->m_aExpressions as $oExpr)
  755. {
  756. $aRes = array_merge($aRes, $oExpr->ListConstantFields());
  757. }
  758. return $aRes;
  759. }
  760. public function RenameParam($sOldName, $sNewName)
  761. {
  762. $aRes = array();
  763. foreach ($this->m_aExpressions as $key => $oExpr)
  764. {
  765. $this->m_aExpressions[$key] = $oExpr->RenameParam($sOldName, $sNewName);
  766. }
  767. }
  768. public function RenameAlias($sOldName, $sNewName)
  769. {
  770. $aRes = array();
  771. foreach ($this->m_aExpressions as $key => $oExpr)
  772. {
  773. $oExpr->RenameAlias($sOldName, $sNewName);
  774. }
  775. }
  776. }
  777. class FunctionExpression extends Expression
  778. {
  779. protected $m_sVerb;
  780. protected $m_aArgs; // array of expressions
  781. public function __construct($sVerb, $aArgExpressions)
  782. {
  783. $this->m_sVerb = $sVerb;
  784. $this->m_aArgs = $aArgExpressions;
  785. }
  786. public function IsTrue()
  787. {
  788. // return true if we are certain that it will be true
  789. return false;
  790. }
  791. public function GetVerb()
  792. {
  793. return $this->m_sVerb;
  794. }
  795. public function GetArgs()
  796. {
  797. return $this->m_aArgs;
  798. }
  799. // recursive rendering
  800. public function Render(&$aArgs = null, $bRetrofitParams = false)
  801. {
  802. $aRes = array();
  803. foreach ($this->m_aArgs as $iPos => $oExpr)
  804. {
  805. $aRes[] = $oExpr->Render($aArgs, $bRetrofitParams);
  806. }
  807. return $this->m_sVerb.'('.implode(', ', $aRes).')';
  808. }
  809. public function Browse(Closure $callback)
  810. {
  811. $callback($this);
  812. foreach ($this->m_aArgs as $iPos => $oExpr)
  813. {
  814. $oExpr->Browse($callback);
  815. }
  816. }
  817. public function ApplyParameters($aArgs)
  818. {
  819. $aRes = array();
  820. foreach ($this->m_aArgs as $idx => $oExpr)
  821. {
  822. if ($oExpr instanceof VariableExpression)
  823. {
  824. $this->m_aArgs[$idx] = $oExpr->GetAsScalar($aArgs);
  825. }
  826. else
  827. {
  828. $oExpr->ApplyParameters($aArgs);
  829. }
  830. }
  831. }
  832. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  833. {
  834. foreach ($this->m_aArgs as $oExpr)
  835. {
  836. $oExpr->GetUnresolvedFields($sAlias, $aUnresolved);
  837. }
  838. }
  839. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  840. {
  841. $aRes = array();
  842. foreach ($this->m_aArgs as $oExpr)
  843. {
  844. $aRes[] = $oExpr->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  845. }
  846. return new FunctionExpression($this->m_sVerb, $aRes);
  847. }
  848. public function ListRequiredFields()
  849. {
  850. $aRes = array();
  851. foreach ($this->m_aArgs as $oExpr)
  852. {
  853. $aRes = array_merge($aRes, $oExpr->ListRequiredFields());
  854. }
  855. return $aRes;
  856. }
  857. public function CollectUsedParents(&$aTable)
  858. {
  859. foreach ($this->m_aArgs as $oExpr)
  860. {
  861. $oExpr->CollectUsedParents($aTable);
  862. }
  863. }
  864. public function ListConstantFields()
  865. {
  866. $aRes = array();
  867. foreach ($this->m_aArgs as $oExpr)
  868. {
  869. $aRes = array_merge($aRes, $oExpr->ListConstantFields());
  870. }
  871. return $aRes;
  872. }
  873. public function RenameParam($sOldName, $sNewName)
  874. {
  875. foreach ($this->m_aArgs as $key => $oExpr)
  876. {
  877. $this->m_aArgs[$key] = $oExpr->RenameParam($sOldName, $sNewName);
  878. }
  879. }
  880. public function RenameAlias($sOldName, $sNewName)
  881. {
  882. foreach ($this->m_aArgs as $key => $oExpr)
  883. {
  884. $oExpr->RenameAlias($sOldName, $sNewName);
  885. }
  886. }
  887. /**
  888. * Make the most relevant label, given the value of the expression
  889. *
  890. * @param DBSearch oFilter The context in which this expression has been used
  891. * @param string sValue The value returned by the query, for this expression
  892. * @param string sDefault The default value if no relevant label could be computed
  893. * @return The label
  894. */
  895. public function MakeValueLabel($oFilter, $sValue, $sDefault)
  896. {
  897. static $aWeekDayToString = null;
  898. if (is_null($aWeekDayToString))
  899. {
  900. // Init the correspondance table
  901. $aWeekDayToString = array(
  902. 0 => Dict::S('DayOfWeek-Sunday'),
  903. 1 => Dict::S('DayOfWeek-Monday'),
  904. 2 => Dict::S('DayOfWeek-Tuesday'),
  905. 3 => Dict::S('DayOfWeek-Wednesday'),
  906. 4 => Dict::S('DayOfWeek-Thursday'),
  907. 5 => Dict::S('DayOfWeek-Friday'),
  908. 6 => Dict::S('DayOfWeek-Saturday')
  909. );
  910. }
  911. static $aMonthToString = null;
  912. if (is_null($aMonthToString))
  913. {
  914. // Init the correspondance table
  915. $aMonthToString = array(
  916. 1 => Dict::S('Month-01'),
  917. 2 => Dict::S('Month-02'),
  918. 3 => Dict::S('Month-03'),
  919. 4 => Dict::S('Month-04'),
  920. 5 => Dict::S('Month-05'),
  921. 6 => Dict::S('Month-06'),
  922. 7 => Dict::S('Month-07'),
  923. 8 => Dict::S('Month-08'),
  924. 9 => Dict::S('Month-09'),
  925. 10 => Dict::S('Month-10'),
  926. 11 => Dict::S('Month-11'),
  927. 12 => Dict::S('Month-12'),
  928. );
  929. }
  930. $sRes = $sDefault;
  931. if (strtolower($this->m_sVerb) == 'date_format')
  932. {
  933. $oFormatExpr = $this->m_aArgs[1];
  934. if ($oFormatExpr->Render() == "'%w'")
  935. {
  936. if (isset($aWeekDayToString[(int)$sValue]))
  937. {
  938. $sRes = $aWeekDayToString[(int)$sValue];
  939. }
  940. }
  941. elseif ($oFormatExpr->Render() == "'%Y-%m'")
  942. {
  943. // yyyy-mm => "yyyy month"
  944. $iMonth = (int) substr($sValue, -2); // the two last chars
  945. $sRes = substr($sValue, 0, 4).' '.$aMonthToString[$iMonth];
  946. }
  947. elseif ($oFormatExpr->Render() == "'%Y-%m-%d'")
  948. {
  949. // yyyy-mm-dd => "month d"
  950. $iMonth = (int) substr($sValue, 5, 2);
  951. $sRes = $aMonthToString[$iMonth].' '.(int)substr($sValue, -2);
  952. }
  953. }
  954. return $sRes;
  955. }
  956. }
  957. class IntervalExpression extends Expression
  958. {
  959. protected $m_oValue; // expression
  960. protected $m_sUnit;
  961. public function __construct($oValue, $sUnit)
  962. {
  963. $this->m_oValue = $oValue;
  964. $this->m_sUnit = $sUnit;
  965. }
  966. public function IsTrue()
  967. {
  968. // return true if we are certain that it will be true
  969. return false;
  970. }
  971. public function GetValue()
  972. {
  973. return $this->m_oValue;
  974. }
  975. public function GetUnit()
  976. {
  977. return $this->m_sUnit;
  978. }
  979. // recursive rendering
  980. public function Render(&$aArgs = null, $bRetrofitParams = false)
  981. {
  982. return 'INTERVAL '.$this->m_oValue->Render($aArgs, $bRetrofitParams).' '.$this->m_sUnit;
  983. }
  984. public function Browse(Closure $callback)
  985. {
  986. $callback($this);
  987. $this->m_oValue->Browse($callback);
  988. }
  989. public function ApplyParameters($aArgs)
  990. {
  991. if ($this->m_oValue instanceof VariableExpression)
  992. {
  993. $this->m_oValue = $this->m_oValue->GetAsScalar($aArgs);
  994. }
  995. else
  996. {
  997. $this->m_oValue->ApplyParameters($aArgs);
  998. }
  999. }
  1000. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  1001. {
  1002. $this->m_oValue->GetUnresolvedFields($sAlias, $aUnresolved);
  1003. }
  1004. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  1005. {
  1006. return new IntervalExpression($this->m_oValue->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved), $this->m_sUnit);
  1007. }
  1008. public function ListRequiredFields()
  1009. {
  1010. return array();
  1011. }
  1012. public function CollectUsedParents(&$aTable)
  1013. {
  1014. }
  1015. public function ListConstantFields()
  1016. {
  1017. return array();
  1018. }
  1019. public function RenameParam($sOldName, $sNewName)
  1020. {
  1021. $this->m_oValue->RenameParam($sOldName, $sNewName);
  1022. }
  1023. public function RenameAlias($sOldName, $sNewName)
  1024. {
  1025. $this->m_oValue->RenameAlias($sOldName, $sNewName);
  1026. }
  1027. }
  1028. class CharConcatExpression extends Expression
  1029. {
  1030. protected $m_aExpressions;
  1031. public function __construct($aExpressions)
  1032. {
  1033. $this->m_aExpressions = $aExpressions;
  1034. }
  1035. public function IsTrue()
  1036. {
  1037. // return true if we are certain that it will be true
  1038. return false;
  1039. }
  1040. public function GetItems()
  1041. {
  1042. return $this->m_aExpressions;
  1043. }
  1044. // recursive rendering
  1045. public function Render(&$aArgs = null, $bRetrofitParams = false)
  1046. {
  1047. $aRes = array();
  1048. foreach ($this->m_aExpressions as $oExpr)
  1049. {
  1050. $sCol = $oExpr->Render($aArgs, $bRetrofitParams);
  1051. // Concat will be globally NULL if one single argument is null !
  1052. $aRes[] = "COALESCE($sCol, '')";
  1053. }
  1054. return "CAST(CONCAT(".implode(', ', $aRes).") AS CHAR)";
  1055. }
  1056. public function Browse(Closure $callback)
  1057. {
  1058. $callback($this);
  1059. foreach ($this->m_aExpressions as $oExpr)
  1060. {
  1061. $oExpr->Browse($callback);
  1062. }
  1063. }
  1064. public function ApplyParameters($aArgs)
  1065. {
  1066. $aRes = array();
  1067. foreach ($this->m_aExpressions as $idx => $oExpr)
  1068. {
  1069. if ($oExpr instanceof VariableExpression)
  1070. {
  1071. $this->m_aExpressions[$idx] = $oExpr->GetAsScalar();
  1072. }
  1073. else
  1074. {
  1075. $this->m_aExpressions->ApplyParameters($aArgs);
  1076. }
  1077. }
  1078. }
  1079. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  1080. {
  1081. foreach ($this->m_aExpressions as $oExpr)
  1082. {
  1083. $oExpr->GetUnresolvedFields($sAlias, $aUnresolved);
  1084. }
  1085. }
  1086. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  1087. {
  1088. $aRes = array();
  1089. foreach ($this->m_aExpressions as $oExpr)
  1090. {
  1091. $aRes[] = $oExpr->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  1092. }
  1093. return new CharConcatExpression($aRes);
  1094. }
  1095. public function ListRequiredFields()
  1096. {
  1097. $aRes = array();
  1098. foreach ($this->m_aExpressions as $oExpr)
  1099. {
  1100. $aRes = array_merge($aRes, $oExpr->ListRequiredFields());
  1101. }
  1102. return $aRes;
  1103. }
  1104. public function CollectUsedParents(&$aTable)
  1105. {
  1106. foreach ($this->m_aExpressions as $oExpr)
  1107. {
  1108. $oExpr->CollectUsedParents($aTable);
  1109. }
  1110. }
  1111. public function ListConstantFields()
  1112. {
  1113. $aRes = array();
  1114. foreach ($this->m_aExpressions as $oExpr)
  1115. {
  1116. $aRes = array_merge($aRes, $oExpr->ListConstantFields());
  1117. }
  1118. return $aRes;
  1119. }
  1120. public function RenameParam($sOldName, $sNewName)
  1121. {
  1122. foreach ($this->m_aExpressions as $key => $oExpr)
  1123. {
  1124. $this->m_aExpressions[$key] = $oExpr->RenameParam($sOldName, $sNewName);
  1125. }
  1126. }
  1127. public function RenameAlias($sOldName, $sNewName)
  1128. {
  1129. foreach ($this->m_aExpressions as $key => $oExpr)
  1130. {
  1131. $oExpr->RenameAlias($sOldName, $sNewName);
  1132. }
  1133. }
  1134. }
  1135. class CharConcatWSExpression extends CharConcatExpression
  1136. {
  1137. protected $m_separator;
  1138. public function __construct($separator, $aExpressions)
  1139. {
  1140. $this->m_separator = $separator;
  1141. parent::__construct($aExpressions);
  1142. }
  1143. // recursive rendering
  1144. public function Render(&$aArgs = null, $bRetrofitParams = false)
  1145. {
  1146. $aRes = array();
  1147. foreach ($this->m_aExpressions as $oExpr)
  1148. {
  1149. $sCol = $oExpr->Render($aArgs, $bRetrofitParams);
  1150. // Concat will be globally NULL if one single argument is null !
  1151. $aRes[] = "COALESCE($sCol, '')";
  1152. }
  1153. $sSep = CMDBSource::Quote($this->m_separator);
  1154. return "CAST(CONCAT_WS($sSep, ".implode(', ', $aRes).") AS CHAR)";
  1155. }
  1156. public function Browse(Closure $callback)
  1157. {
  1158. $callback($this);
  1159. foreach ($this->m_aExpressions as $oExpr)
  1160. {
  1161. $oExpr->Browse($callback);
  1162. }
  1163. }
  1164. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  1165. {
  1166. $aRes = array();
  1167. foreach ($this->m_aExpressions as $oExpr)
  1168. {
  1169. $aRes[] = $oExpr->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  1170. }
  1171. return new CharConcatWSExpression($this->m_separator, $aRes);
  1172. }
  1173. }
  1174. class QueryBuilderExpressions
  1175. {
  1176. protected $m_oConditionExpr;
  1177. protected $m_aSelectExpr;
  1178. protected $m_aGroupByExpr;
  1179. protected $m_aJoinFields;
  1180. protected $m_aClassIds;
  1181. public function __construct($oSearch, $aGroupByExpr = null)
  1182. {
  1183. $this->m_oConditionExpr = $oSearch->GetCriteria();
  1184. $this->m_aSelectExpr = array();
  1185. $this->m_aGroupByExpr = $aGroupByExpr;
  1186. $this->m_aJoinFields = array();
  1187. $this->m_aClassIds = array();
  1188. foreach($oSearch->GetJoinedClasses() as $sClassAlias => $sClass)
  1189. {
  1190. $this->m_aClassIds[$sClassAlias] = new FieldExpression('id', $sClassAlias);
  1191. }
  1192. }
  1193. public function GetSelect()
  1194. {
  1195. return $this->m_aSelectExpr;
  1196. }
  1197. public function GetGroupBy()
  1198. {
  1199. return $this->m_aGroupByExpr;
  1200. }
  1201. public function GetCondition()
  1202. {
  1203. return $this->m_oConditionExpr;
  1204. }
  1205. public function PopJoinField()
  1206. {
  1207. return array_pop($this->m_aJoinFields);
  1208. }
  1209. public function AddSelect($sAttAlias, $oExpression)
  1210. {
  1211. $this->m_aSelectExpr[$sAttAlias] = $oExpression;
  1212. }
  1213. //$oConditionTree = $oConditionTree->LogAnd($oFinalClassRestriction);
  1214. public function AddCondition($oExpression)
  1215. {
  1216. $this->m_oConditionExpr = $this->m_oConditionExpr->LogAnd($oExpression);
  1217. }
  1218. public function PushJoinField($oExpression)
  1219. {
  1220. array_push($this->m_aJoinFields, $oExpression);
  1221. }
  1222. /**
  1223. * Get tables representing the queried objects
  1224. * Could be further optimized: when the first join is an outer join, then the rest can be omitted
  1225. */
  1226. public function GetMandatoryTables(&$aTables = null)
  1227. {
  1228. if (is_null($aTables)) $aTables = array();
  1229. foreach($this->m_aClassIds as $sClass => $oExpression)
  1230. {
  1231. $oExpression->CollectUsedParents($aTables);
  1232. }
  1233. }
  1234. public function GetUnresolvedFields($sAlias, &$aUnresolved)
  1235. {
  1236. $this->m_oConditionExpr->GetUnresolvedFields($sAlias, $aUnresolved);
  1237. foreach($this->m_aSelectExpr as $sColAlias => $oExpr)
  1238. {
  1239. $oExpr->GetUnresolvedFields($sAlias, $aUnresolved);
  1240. }
  1241. if ($this->m_aGroupByExpr)
  1242. {
  1243. foreach($this->m_aGroupByExpr as $sColAlias => $oExpr)
  1244. {
  1245. $oExpr->GetUnresolvedFields($sAlias, $aUnresolved);
  1246. }
  1247. }
  1248. foreach($this->m_aJoinFields as $oExpression)
  1249. {
  1250. $oExpression->GetUnresolvedFields($sAlias, $aUnresolved);
  1251. }
  1252. }
  1253. public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true)
  1254. {
  1255. $this->m_oConditionExpr = $this->m_oConditionExpr->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  1256. foreach($this->m_aSelectExpr as $sColAlias => $oExpr)
  1257. {
  1258. $this->m_aSelectExpr[$sColAlias] = $oExpr->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  1259. }
  1260. if ($this->m_aGroupByExpr)
  1261. {
  1262. foreach($this->m_aGroupByExpr as $sColAlias => $oExpr)
  1263. {
  1264. $this->m_aGroupByExpr[$sColAlias] = $oExpr->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  1265. }
  1266. }
  1267. foreach($this->m_aJoinFields as $index => $oExpression)
  1268. {
  1269. $this->m_aJoinFields[$index] = $oExpression->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  1270. }
  1271. foreach($this->m_aClassIds as $sClass => $oExpression)
  1272. {
  1273. $this->m_aClassIds[$sClass] = $oExpression->Translate($aTranslationData, $bMatchAll, $bMarkFieldsAsResolved);
  1274. }
  1275. }
  1276. public function RenameParam($sOldName, $sNewName)
  1277. {
  1278. $this->m_oConditionExpr->RenameParam($sOldName, $sNewName);
  1279. foreach($this->m_aSelectExpr as $sColAlias => $oExpr)
  1280. {
  1281. $this->m_aSelectExpr[$sColAlias] = $oExpr->RenameParam($sOldName, $sNewName);
  1282. }
  1283. if ($this->m_aGroupByExpr)
  1284. {
  1285. foreach($this->m_aGroupByExpr as $sColAlias => $oExpr)
  1286. {
  1287. $this->m_aGroupByExpr[$sColAlias] = $oExpr->RenameParam($sOldName, $sNewName);
  1288. }
  1289. }
  1290. foreach($this->m_aJoinFields as $index => $oExpression)
  1291. {
  1292. $this->m_aJoinFields[$index] = $oExpression->RenameParam($sOldName, $sNewName);
  1293. }
  1294. }
  1295. }