oqlquery.class.inc.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. // Copyright (C) 2010-2012 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. * Classes defined for lexical analyze (see oql-parser.y)
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. // Position a string within an OQL query
  25. // This is a must if we want to be able to pinpoint an error at any stage of the query interpretation
  26. // In particular, the normalization phase requires this
  27. class OqlName
  28. {
  29. protected $m_sValue;
  30. protected $m_iPos;
  31. public function __construct($sValue, $iPos)
  32. {
  33. $this->m_iPos = $iPos;
  34. $this->m_sValue = $sValue;
  35. }
  36. public function GetValue()
  37. {
  38. return $this->m_sValue;
  39. }
  40. public function GetPos()
  41. {
  42. return $this->m_iPos;
  43. }
  44. public function __toString()
  45. {
  46. return $this->m_sValue;
  47. }
  48. }
  49. class OqlJoinSpec
  50. {
  51. protected $m_oClass;
  52. protected $m_oClassAlias;
  53. protected $m_oLeftField;
  54. protected $m_oRightField;
  55. protected $m_sOperator;
  56. protected $m_oNextJoinspec;
  57. public function __construct($oClass, $oClassAlias, BinaryExpression $oExpression)
  58. {
  59. $this->m_oClass = $oClass;
  60. $this->m_oClassAlias = $oClassAlias;
  61. $this->m_oLeftField = $oExpression->GetLeftExpr();
  62. $this->m_oRightField = $oExpression->GetRightExpr();
  63. $this->m_oRightField = $oExpression->GetRightExpr();
  64. $this->m_sOperator = $oExpression->GetOperator();
  65. }
  66. public function GetClass()
  67. {
  68. return $this->m_oClass->GetValue();
  69. }
  70. public function GetClassAlias()
  71. {
  72. return $this->m_oClassAlias->GetValue();
  73. }
  74. public function GetClassDetails()
  75. {
  76. return $this->m_oClass;
  77. }
  78. public function GetClassAliasDetails()
  79. {
  80. return $this->m_oClassAlias;
  81. }
  82. public function GetLeftField()
  83. {
  84. return $this->m_oLeftField;
  85. }
  86. public function GetRightField()
  87. {
  88. return $this->m_oRightField;
  89. }
  90. public function GetOperator()
  91. {
  92. return $this->m_sOperator;
  93. }
  94. }
  95. class BinaryOqlExpression extends BinaryExpression
  96. {
  97. }
  98. class ScalarOqlExpression extends ScalarExpression
  99. {
  100. }
  101. class FieldOqlExpression extends FieldExpression
  102. {
  103. protected $m_oParent;
  104. protected $m_oName;
  105. public function __construct($oName, $oParent = null)
  106. {
  107. if (is_null($oParent))
  108. {
  109. $oParent = new OqlName('', 0);
  110. }
  111. $this->m_oParent = $oParent;
  112. $this->m_oName = $oName;
  113. parent::__construct($oName->GetValue(), $oParent->GetValue());
  114. }
  115. public function GetParentDetails()
  116. {
  117. return $this->m_oParent;
  118. }
  119. public function GetNameDetails()
  120. {
  121. return $this->m_oName;
  122. }
  123. }
  124. class VariableOqlExpression extends VariableExpression
  125. {
  126. }
  127. class ListOqlExpression extends ListExpression
  128. {
  129. }
  130. class FunctionOqlExpression extends FunctionExpression
  131. {
  132. }
  133. class IntervalOqlExpression extends IntervalExpression
  134. {
  135. }
  136. abstract class OqlQuery
  137. {
  138. protected $m_aJoins; // array of OqlJoinSpec
  139. protected $m_oCondition; // condition tree (expressions)
  140. public function __construct($oCondition = null, $aJoins = null)
  141. {
  142. $this->m_aJoins = $aJoins;
  143. $this->m_oCondition = $oCondition;
  144. }
  145. public function GetJoins()
  146. {
  147. return $this->m_aJoins;
  148. }
  149. public function GetCondition()
  150. {
  151. return $this->m_oCondition;
  152. }
  153. }
  154. class OqlObjectQuery extends OqlQuery
  155. {
  156. protected $m_aSelect; // array of selected classes
  157. protected $m_oClass;
  158. protected $m_oClassAlias;
  159. public function __construct($oClass, $oClassAlias, $oCondition = null, $aJoins = null, $aSelect = null)
  160. {
  161. $this->m_aSelect = $aSelect;
  162. $this->m_oClass = $oClass;
  163. $this->m_oClassAlias = $oClassAlias;
  164. parent::__construct($oCondition, $aJoins);
  165. }
  166. public function GetSelectedClasses()
  167. {
  168. return $this->m_aSelect;
  169. }
  170. public function GetClass()
  171. {
  172. return $this->m_oClass->GetValue();
  173. }
  174. public function GetClassAlias()
  175. {
  176. return $this->m_oClassAlias->GetValue();
  177. }
  178. public function GetClassDetails()
  179. {
  180. return $this->m_oClass;
  181. }
  182. public function GetClassAliasDetails()
  183. {
  184. return $this->m_oClassAlias;
  185. }
  186. }
  187. ?>