PageRenderTime 30ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/core/utils/SearchAttributesDataCollection.php

https://bitbucket.org/zurmo/zurmo/
PHP | 246 lines | 181 code | 27 blank | 38 comment | 20 complexity | 675c965467676e01b554c6dde67e2892 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. /**
  37. * Base class for managing the source of search attributes. Attributes can be coming from a $_GET, a $_POST or
  38. * potentially a model as a saved search.
  39. */
  40. class SearchAttributesDataCollection
  41. {
  42. protected $sourceData;
  43. protected $model;
  44. public function __construct($model)
  45. {
  46. assert('$model instanceof RedBeanModel || $model instanceof SearchForm');
  47. $this->model = $model;
  48. }
  49. public function getModel()
  50. {
  51. return $this->model;
  52. }
  53. public function setSourceData($sourceData)
  54. {
  55. assert('is_array($sourceData)');
  56. $this->sourceData = $sourceData;
  57. }
  58. public function getSourceData()
  59. {
  60. if (isset($this->sourceData))
  61. {
  62. return $this->sourceData;
  63. }
  64. return $_GET;
  65. }
  66. public function getDynamicSearchAttributes()
  67. {
  68. $dynamicSearchAttributes = SearchUtil::
  69. getDynamicSearchAttributesFromArray(get_class($this->model), $this->getSourceData());
  70. if ($dynamicSearchAttributes == null)
  71. {
  72. return array();
  73. }
  74. return $dynamicSearchAttributes;
  75. }
  76. public function getSanitizedDynamicSearchAttributes()
  77. {
  78. $dynamicSearchAttributes = SearchUtil::
  79. getDynamicSearchAttributesFromArray(get_class($this->model), $this->getSourceData());
  80. if ($dynamicSearchAttributes == null)
  81. {
  82. return array();
  83. }
  84. return SearchUtil::
  85. sanitizeDynamicSearchAttributesByDesignerTypeForSavingModel($this->model, $dynamicSearchAttributes);
  86. }
  87. public function getDynamicStructure()
  88. {
  89. return SearchUtil::getDynamicSearchStructureFromArray(get_class($this->model), $this->getSourceData());
  90. }
  91. public function getAnyMixedAttributesScopeFromModel()
  92. {
  93. return $this->model->getAnyMixedAttributesScope();
  94. }
  95. public function getSelectedListAttributesFromModel()
  96. {
  97. if ($this->model->getListAttributesSelector() != null)
  98. {
  99. return $this->model->getListAttributesSelector()->getSelected();
  100. }
  101. }
  102. public function getFilterByStarred()
  103. {
  104. return SearchUtil::getFilterByStarredFromArray(get_class($this->model), $this->getSourceData());
  105. }
  106. public function getFilteredBy()
  107. {
  108. return SearchUtil::getFilteredByFromArray(get_class($this->model), $this->getSourceData());
  109. }
  110. public function hasKanbanBoard()
  111. {
  112. if ($this->model->getKanbanBoard() == null)
  113. {
  114. return false;
  115. }
  116. return true;
  117. }
  118. public function getKanbanBoard()
  119. {
  120. return $this->model->getKanbanBoard();
  121. }
  122. public function shouldClearStickyForKanbanBoard()
  123. {
  124. if ($this->model->getKanbanBoard() == null)
  125. {
  126. throw new NotSupportedException();
  127. }
  128. elseif ($this->model->getKanbanBoard()->getClearSticky())
  129. {
  130. return true;
  131. }
  132. return false;
  133. }
  134. public function getKanbanBoardGroupByAttributeVisibleValuesFromModel()
  135. {
  136. if ($this->model->getKanbanBoard() != null)
  137. {
  138. return $this->model->getKanbanBoard()->getGroupByAttributeVisibleValues();
  139. }
  140. }
  141. public function getKanbanBoardSelectedThemeFromModel()
  142. {
  143. if ($this->model->getKanbanBoard() != null)
  144. {
  145. return $this->model->getKanbanBoard()->getSelectedTheme();
  146. }
  147. }
  148. public function resolveSearchAttributesFromSourceData()
  149. {
  150. return SearchUtil::resolveSearchAttributesFromArray(get_class($this->model),
  151. get_class($this->model),
  152. $this->getSourceData());
  153. }
  154. public function resolveAnyMixedAttributesScopeForSearchModelFromSourceData()
  155. {
  156. return SearchUtil::resolveAnyMixedAttributesScopeForSearchModelFromArray($this->model,
  157. get_class($this->model),
  158. $this->getSourceData());
  159. }
  160. public function resolveSelectedListAttributesForSearchModelFromSourceData()
  161. {
  162. return SearchUtil::resolveSelectedListAttributesForSearchModelFromArray($this->model,
  163. get_class($this->model),
  164. $this->getSourceData());
  165. }
  166. public function resolveKanbanBoardOptionsForSearchModelFromSourceData()
  167. {
  168. return KanbanBoard::resolveKanbanBoardOptionsForSearchModelFromArray($this->model,
  169. get_class($this->model),
  170. $this->getSourceData());
  171. }
  172. public function resolveSortAttributeFromSourceData($name)
  173. {
  174. assert('is_string($name)');
  175. $sortAttribute = SearchUtil::resolveSortAttributeFromArray($name, $this->getSourceData());
  176. if ($sortAttribute == null)
  177. {
  178. if (!empty($this->model->sortAttribute))
  179. {
  180. $sortAttribute = $this->model->sortAttribute;
  181. }
  182. else
  183. {
  184. $sortAttribute = null;
  185. }
  186. }
  187. return $sortAttribute;
  188. }
  189. public function resolveSortDescendingFromSourceData($name)
  190. {
  191. assert('is_string($name)');
  192. $sortDescending = SearchUtil::resolveSortDescendingFromArray($name, $this->getSourceData());
  193. if (!isset($sortDescending))
  194. {
  195. if (!empty($this->model->sortDescending))
  196. {
  197. $sortDescending = true;
  198. }
  199. else
  200. {
  201. $sortDescending = false;
  202. }
  203. }
  204. return $sortDescending;
  205. }
  206. public function resolveFilterByStarredFromSourceData()
  207. {
  208. SearchUtil::resolveFilterByStarredFromArray($this->model,
  209. get_class($this->model),
  210. $this->getSourceData());
  211. }
  212. public function resolveFilteredByFromSourceData()
  213. {
  214. SearchUtil::resolveFilteredByFromArray($this->model,
  215. get_class($this->model),
  216. $this->getSourceData());
  217. }
  218. }
  219. ?>