querybuildercontext.class.inc.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // Copyright (C) 2010-2015 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-2015 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. public $m_oQBExpressions;
  32. public function __construct($oFilter, $aModifierProperties, $aGroupByExpr = null, $aSelectedClasses = null)
  33. {
  34. $this->m_oRootFilter = $oFilter;
  35. $this->m_oQBExpressions = new QueryBuilderExpressions($oFilter, $aGroupByExpr);
  36. $this->m_aClassAliases = $oFilter->GetJoinedClasses();
  37. $this->m_aTableAliases = array();
  38. $this->m_aModifierProperties = $aModifierProperties;
  39. if (is_null($aSelectedClasses))
  40. {
  41. $this->m_aSelectedClasses = $oFilter->GetSelectedClasses();
  42. }
  43. else
  44. {
  45. // For the unions, the selected classes can be upper in the hierarchy (lowest common ancestor)
  46. $this->m_aSelectedClasses = $aSelectedClasses;
  47. }
  48. }
  49. public function GetRootFilter()
  50. {
  51. return $this->m_oRootFilter;
  52. }
  53. public function GenerateTableAlias($sNewName, $sRealName)
  54. {
  55. return MetaModel::GenerateUniqueAlias($this->m_aTableAliases, $sNewName, $sRealName);
  56. }
  57. public function GenerateClassAlias($sNewName, $sRealName)
  58. {
  59. return MetaModel::GenerateUniqueAlias($this->m_aClassAliases, $sNewName, $sRealName);
  60. }
  61. public function GetModifierProperties($sPluginClass)
  62. {
  63. if (array_key_exists($sPluginClass, $this->m_aModifierProperties))
  64. {
  65. return $this->m_aModifierProperties[$sPluginClass];
  66. }
  67. else
  68. {
  69. return array();
  70. }
  71. }
  72. public function GetSelectedClass($sAlias)
  73. {
  74. return $this->m_aSelectedClasses[$sAlias];
  75. }
  76. }