PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/modules/designer/rules/DesignerRules.php

https://bitbucket.org/zurmo/zurmo/
PHP | 320 lines | 200 code | 32 blank | 88 comment | 8 complexity | 4b80039c13151b0da12fde70e1e1e758 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. * Class to help the designer module editing understand
  38. * how to parse and handle the views it is editing.
  39. */
  40. abstract class DesignerRules
  41. {
  42. public function allowEditInLayoutTool()
  43. {
  44. return true;
  45. }
  46. public function canAddPanels()
  47. {
  48. return true;
  49. }
  50. public function canAddRows()
  51. {
  52. return true;
  53. }
  54. public function canMergeAndSplitCells()
  55. {
  56. return true;
  57. }
  58. public function canModifyCellSettings()
  59. {
  60. return true;
  61. }
  62. public function canModifyPanelSettings()
  63. {
  64. return true;
  65. }
  66. public function canMovePanels()
  67. {
  68. return true;
  69. }
  70. public function canMoveRows()
  71. {
  72. return true;
  73. }
  74. public function canRemovePanels()
  75. {
  76. return true;
  77. }
  78. public function canRemoveRows()
  79. {
  80. return true;
  81. }
  82. public function canConfigureLayoutPanelsType()
  83. {
  84. return false;
  85. }
  86. /**
  87. * Override to add special formatting to the savableMetadata
  88. */
  89. public function formatSavableMetadataFromLayout($metadata, $viewClassName)
  90. {
  91. assert('is_string($viewClassName)');
  92. $rules = $this->getSavableMetadataRules();
  93. foreach ($metadata['global']['panels'] as $panelKey => $panel)
  94. {
  95. foreach ($panel['rows'] as $rowKey => $row)
  96. {
  97. foreach ($row['cells'] as $cellKey => $cell)
  98. {
  99. if (is_array($cell['elements']))
  100. {
  101. foreach ($cell['elements'] as $elementKey => $elementInformation)
  102. {
  103. foreach ($rules as $rule)
  104. {
  105. if (static::doesRuleApplyToElement($rule, $elementInformation, $viewClassName))
  106. {
  107. $ruleClassName = $rule . 'ViewMetadataRules';
  108. $ruleClassName::resolveElementMetadata(
  109. $elementInformation,
  110. $metadata['global']['panels'][$panelKey]['rows'][$rowKey]['cells'][$cellKey]['elements'][$elementKey]
  111. );
  112. if (method_exists($ruleClassName, 'resolveCellMetadata'))
  113. {
  114. $ruleClassName::resolveCellMetadata(
  115. $elementInformation,
  116. $metadata['global']['panels'][$panelKey]['rows'][$rowKey]['cells'][$cellKey]
  117. );
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. return $metadata;
  127. }
  128. /**
  129. * @see formatSavableMetadataFromLayout. This method is if you just want to format a single element and return it.
  130. * @return formatted element
  131. */
  132. public function formatSavableElement($element, $viewClassName)
  133. {
  134. assert('is_array($element)');
  135. $rules = $this->getSavableMetadataRules();
  136. $finalElement = $element;
  137. foreach ($rules as $rule)
  138. {
  139. if (static::doesRuleApplyToElement($rule, $element, $viewClassName))
  140. {
  141. $ruleClassName = $rule . 'ViewMetadataRules';
  142. $ruleClassName::resolveElementMetadata(
  143. $element,
  144. $finalElement
  145. );
  146. }
  147. }
  148. return $finalElement;
  149. }
  150. /**
  151. * Override if special handling is required to ignore certain rules from applying to the element before
  152. * the metadata is saved. @see formatSavableMetadataFromLayout()
  153. * @param string $rule
  154. * @param array $elementInformation
  155. * @param string $viewClassName
  156. */
  157. protected static function doesRuleApplyToElement($rule, $elementInformation, $viewClassName)
  158. {
  159. return true;
  160. }
  161. public function getCellSettingsAttributes()
  162. {
  163. return array();
  164. }
  165. /**
  166. * Override if a rule requires that certain derived attributes
  167. * types be made not available for placement using the layout tool
  168. * @return array
  169. */
  170. public function getDerivedAttributeTypes()
  171. {
  172. return array();
  173. }
  174. public function getDisplayName()
  175. {
  176. }
  177. /**
  178. * Override if you need to return a different display name than what designer rules provides.
  179. */
  180. public function resolveDisplayNameByView($viewClassName)
  181. {
  182. return $this->getDisplayName();
  183. }
  184. public function getMetadataViewClassNames($viewClassName, $moduleClassName)
  185. {
  186. return array($viewClassName);
  187. }
  188. public function getPanelSettingsAttributes()
  189. {
  190. return array();
  191. }
  192. public function getSavableMetadataRules()
  193. {
  194. }
  195. public function mergeRowAndAttributePlacement()
  196. {
  197. return false;
  198. }
  199. public function requireAllRequiredFieldsInLayout()
  200. {
  201. return false;
  202. }
  203. /**
  204. * Override if a rule allows that certain required attributes
  205. * be not placed in layout since they are placed by default in edit view.
  206. */
  207. public function isRequiredAttributeExemptFromBeingPlacedInLayout($attributeName)
  208. {
  209. return false;
  210. }
  211. /**
  212. * Override if a rule allows that certain non-required derived attribute types
  213. * being actually required to be placed in layout.
  214. */
  215. public function areAllPseudoRequiredDerivedAttributeTypesPlacedInLayout($placedDerivedAttributeTypes)
  216. {
  217. return true;
  218. }
  219. public function requireOnlyUniqueFieldsInLayout()
  220. {
  221. return false;
  222. }
  223. /**
  224. * Override if a rule requires that certain attributes
  225. * be made not available for placement using the layout tool
  226. */
  227. public function getNonPlaceableLayoutAttributeNames()
  228. {
  229. return array();
  230. }
  231. /**
  232. * Override if a rule requires that certain attributes types
  233. * be made not available for placement using the layout tool
  234. */
  235. public function getNonPlaceableLayoutAttributeTypes()
  236. {
  237. return array();
  238. }
  239. /**
  240. * Adds an extra formatting to ensure uniformity
  241. * for layout parsing. Adds 'wide' => true if the
  242. * cell should span.
  243. */
  244. public function formatEditableMetadataForLayoutParsing($metadata)
  245. {
  246. assert('isset($metadata["global"]["panels"])');
  247. foreach ($metadata['global']['panels'] as $panelKey => $panel)
  248. {
  249. foreach ($panel['rows'] as $rowKey => $row)
  250. {
  251. foreach ($row['cells'] as $cellKey => $cell)
  252. {
  253. if (is_array($cell['elements']))
  254. {
  255. foreach ($cell['elements'] as $elementKey => $elementInformation)
  256. {
  257. if (count($row['cells']) == 1 && count($row['cells']) < $this->maxCellsPerRow())
  258. {
  259. $metadata['global']['panels'][$panelKey]['rows'][$rowKey]['cells'][$cellKey]['elements'][$elementKey]['wide'] = true;
  260. }
  261. }
  262. }
  263. }
  264. }
  265. }
  266. return $metadata;
  267. }
  268. public function maxCellsPerRow()
  269. {
  270. return 1;
  271. }
  272. /**
  273. * If an element is null, should we place it in the metadata.
  274. */
  275. public function shouldPlaceNullElement()
  276. {
  277. return true;
  278. }
  279. /**
  280. * Gets saved layout success message.
  281. * @return array
  282. */
  283. public static function getSavedLayoutSuccessMessage()
  284. {
  285. return Zurmo::t('DesignerModule', 'Layout saved successfully.');
  286. }
  287. }
  288. ?>