PageRenderTime 27ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/app/protected/modules/zurmo/views/security/ModulePermissionsEditAndDetailsView.php

https://bitbucket.org/zurmo/zurmo/
PHP | 193 lines | 128 code | 9 blank | 56 comment | 4 complexity | be8b7107addede4ed010f7c03e9c6135 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. class ModulePermissionsEditAndDetailsView extends EditAndDetailsView
  37. {
  38. /**
  39. * View Metadata to be used.
  40. */
  41. private $metadata;
  42. /**
  43. * Constructs a module permissions view specifying the controller as
  44. * well as the model that will have its details displayed.
  45. */
  46. public function __construct($renderType, $controllerId, $moduleId, $model, $modelId, $metadata, $title = null)
  47. {
  48. assert('$renderType == "Edit" || $renderType == "Details"');
  49. assert('$controllerId != null');
  50. assert('$moduleId != null');
  51. assert('$model instanceof ModulePermissionsForm');
  52. assert('$modelId != null');
  53. assert('is_array($metadata) && !empty($metadata)');
  54. assert('is_string($title) || $title == null');
  55. $this->renderType = $renderType;
  56. $this->controllerId = $controllerId;
  57. $this->moduleId = $moduleId;
  58. $this->model = $model;
  59. $this->modelClassName = get_class($model);
  60. $this->modelId = $modelId;
  61. $this->metadata = $metadata;
  62. $this->title = $title;
  63. }
  64. public function getTitle()
  65. {
  66. return $this->title;
  67. }
  68. public static function getDefaultMetadata()
  69. {
  70. $metadata = array(
  71. 'global' => array(
  72. 'toolbar' => array(
  73. 'elements' => array(
  74. array('type' => 'CancelLink', 'renderType' => 'Edit'),
  75. array('type' => 'SaveButton', 'renderType' => 'Edit'),
  76. ),
  77. ),
  78. ),
  79. );
  80. return $metadata;
  81. }
  82. /**
  83. * Override to produce a form layout that does not follow the
  84. * standard form layout for EditView.
  85. */
  86. protected function renderFormLayout($form = null)
  87. {
  88. $content = '';
  89. $metadata = $this->getFormLayoutMetadata();
  90. $permissions = ModulePermissionsEditViewUtil::getPermissionsForView();
  91. assert('count($permissions) > 0');
  92. foreach ($metadata['global']['panels'] as $panel)
  93. {
  94. if (!empty($panel['title']))
  95. {
  96. $content .= '<div class="panelTitle">' . $panel['title'] . '</div>';
  97. }
  98. $content .= '<table>';
  99. $content .= '<colgroup>';
  100. $content .= '<col style="width:20%" />';
  101. $width = 80 / count($permissions);
  102. foreach ($permissions as $permission)
  103. {
  104. $content .= '<col style="width:' . $width . '%" />';
  105. }
  106. $content .= '</colgroup>';
  107. $content .= '<tbody>';
  108. $content .= '<tr>';
  109. $content .= '<th>&#160;</th>';
  110. $permissionNames = ModulePermissionsEditViewUtil::getPermissionNamesForView();
  111. $permissionLabels = ModulePermissionsEditViewUtil::getPermissionLabelsForView();
  112. foreach ($permissionNames as $permission)
  113. {
  114. $content .= '<th>' . $permissionLabels[$permission] . '</th>';
  115. }
  116. $content .= '</tr>';
  117. foreach ($panel['rows'] as $row)
  118. {
  119. assert('!empty($row["title"])');
  120. $title = Zurmo::t('ZurmoModule', $row['title']);
  121. $rowTitlesAndContent[$title] = '<th>' . $title . '</th>';
  122. foreach ($row['cells'] as $cell)
  123. {
  124. if (is_array($cell['elements']) && $this->shouldDisplayCell(ArrayUtil::getArrayValue($cell, 'detailViewOnly')))
  125. {
  126. foreach ($cell['elements'] as $elementInformation)
  127. {
  128. $editableTemplate = '<td colspan="{colspan}">{content}{error}</td>';
  129. $this->resolveElementInformationDuringFormLayoutRender($elementInformation);
  130. $elementclassname = $elementInformation['type'] . 'Element';
  131. $element = new $elementclassname(
  132. $this->model,
  133. $elementInformation['attributeName'],
  134. $form,
  135. array_slice($elementInformation, 2));
  136. $element->editableTemplate = $editableTemplate;
  137. $rowTitlesAndContent[$title] .= $element->render();
  138. }
  139. }
  140. }
  141. }
  142. ksort($rowTitlesAndContent);
  143. foreach ($rowTitlesAndContent as $rowcontent)
  144. {
  145. if (!empty($rowcontent))
  146. {
  147. $content .= '<tr>';
  148. $content .= $rowcontent;
  149. $content .= '</tr>';
  150. }
  151. }
  152. $content .= '</tbody>';
  153. $content .= '</table>';
  154. }
  155. return $content;
  156. }
  157. /**
  158. * This view is not editable in the designer tool.
  159. */
  160. public static function getDesignerRulesType()
  161. {
  162. return null;
  163. }
  164. /**
  165. * This ModelView metadata validity check is not valid on this view
  166. * because this view follows a different metadata structure.
  167. */
  168. protected static function assertMetadataIsValid(array $metadata)
  169. {
  170. }
  171. public function isUniqueToAPage()
  172. {
  173. return true;
  174. }
  175. /**
  176. * Merges view metadata with dynamically
  177. * generated metadata based on $model
  178. */
  179. protected function getFormLayoutMetadata()
  180. {
  181. return $this->metadata;
  182. }
  183. }
  184. ?>