querybuildercontext.class.inc.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * Associated with the metamodel -> MakeQuery/MakeQuerySingleTable
  20. *
  21. * @copyright Copyright (C) 2010-2017 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. class QueryBuilderContext
  25. {
  26. protected $m_oRootFilter;
  27. protected $m_aClassAliases;
  28. protected $m_aTableAliases;
  29. protected $m_aModifierProperties;
  30. protected $m_aSelectedClasses;
  31. protected $m_aFilteredTables;
  32. public $m_oQBExpressions;
  33. public function __construct($oFilter, $aModifierProperties, $aGroupByExpr = null, $aSelectedClasses = null)
  34. {
  35. $this->m_oRootFilter = $oFilter;
  36. $this->m_oQBExpressions = new QueryBuilderExpressions($oFilter, $aGroupByExpr);
  37. $this->m_aClassAliases = $oFilter->GetJoinedClasses();
  38. $this->m_aTableAliases = array();
  39. $this->m_aFilteredTables = array();
  40. $this->m_aModifierProperties = $aModifierProperties;
  41. if (is_null($aSelectedClasses))
  42. {
  43. $this->m_aSelectedClasses = $oFilter->GetSelectedClasses();
  44. }
  45. else
  46. {
  47. // For the unions, the selected classes can be upper in the hierarchy (lowest common ancestor)
  48. $this->m_aSelectedClasses = $aSelectedClasses;
  49. }
  50. }
  51. public function GetRootFilter()
  52. {
  53. return $this->m_oRootFilter;
  54. }
  55. public function GenerateTableAlias($sNewName, $sRealName)
  56. {
  57. return MetaModel::GenerateUniqueAlias($this->m_aTableAliases, $sNewName, $sRealName);
  58. }
  59. public function GenerateClassAlias($sNewName, $sRealName)
  60. {
  61. return MetaModel::GenerateUniqueAlias($this->m_aClassAliases, $sNewName, $sRealName);
  62. }
  63. public function GetModifierProperties($sPluginClass)
  64. {
  65. if (array_key_exists($sPluginClass, $this->m_aModifierProperties))
  66. {
  67. return $this->m_aModifierProperties[$sPluginClass];
  68. }
  69. else
  70. {
  71. return array();
  72. }
  73. }
  74. public function GetSelectedClass($sAlias)
  75. {
  76. return $this->m_aSelectedClasses[$sAlias];
  77. }
  78. public function AddFilteredTable($sTableAlias, $oCondition)
  79. {
  80. if (array_key_exists($sTableAlias, $this->m_aFilteredTables))
  81. {
  82. $this->m_aFilteredTables[$sTableAlias][] = $oCondition;
  83. }
  84. else
  85. {
  86. $this->m_aFilteredTables[$sTableAlias] = array($oCondition);
  87. }
  88. }
  89. public function GetFilteredTables()
  90. {
  91. return $this->m_aFilteredTables;
  92. }
  93. }