All Data Structures Functions Variables Pages
ModulePermissionsEditAndDetailsView.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 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. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
42  private $metadata;
43 
48  public function __construct($renderType, $controllerId, $moduleId, $model, $modelId, $metadata, $title = null)
49  {
50  assert('$renderType == "Edit" || $renderType == "Details"');
51  assert('$controllerId != null');
52  assert('$moduleId != null');
53  assert('$model instanceof ModulePermissionsForm');
54  assert('$modelId != null');
55  assert('is_array($metadata) && !empty($metadata)');
56  assert('is_string($title) || $title == null');
57  $this->renderType = $renderType;
58  $this->controllerId = $controllerId;
59  $this->moduleId = $moduleId;
60  $this->model = $model;
61  $this->modelClassName = get_class($model);
62  $this->modelId = $modelId;
63  $this->metadata = $metadata;
64  $this->title = $title;
65  }
66 
67  public function getTitle()
68  {
69  return $this->title;
70  }
71 
72  public static function getDefaultMetadata()
73  {
74  $metadata = array(
75  'global' => array(
76  'toolbar' => array(
77  'elements' => array(
78  array('type' => 'CancelLink', 'renderType' => 'Edit'),
79  array('type' => 'SaveButton', 'renderType' => 'Edit'),
80  ),
81  ),
82  ),
83  );
84  return $metadata;
85  }
86 
91  protected function renderFormLayout($form = null)
92  {
93  $content = '';
94  $metadata = $this->getFormLayoutMetadata();
96  assert('count($permissions) > 0');
97  foreach ($metadata['global']['panels'] as $panel)
98  {
99  if (!empty($panel['title']))
100  {
101  $content .= '<div class="panelTitle">' . $panel['title'] . '</div>';
102  }
103  $content .= '<table>';
104  $content .= '<colgroup>';
105  $content .= '<col style="width:20%" />';
106  $width = 80 / count($permissions);
107  foreach ($permissions as $permission)
108  {
109  $content .= '<col style="width:' . $width . '%" />';
110  }
111  $content .= '</colgroup>';
112  $content .= '<tbody>';
113  $content .= '<tr>';
114  $content .= '<th>&#160;</th>';
117  foreach ($permissionNames as $permission)
118  {
119  $content .= '<th>' . $permissionLabels[$permission] . '</th>';
120  }
121  $content .= '</tr>';
122  foreach ($panel['rows'] as $row)
123  {
124  assert('!empty($row["title"])');
125  $title = Zurmo::t('ZurmoModule', $row['title']);
126  $rowTitlesAndContent[$title] = '<th>' . $title . '</th>';
127  foreach ($row['cells'] as $cell)
128  {
129  if (is_array($cell['elements']) && $this->shouldDisplayCell(ArrayUtil::getArrayValue($cell, 'detailViewOnly')))
130  {
131  foreach ($cell['elements'] as $elementInformation)
132  {
133  $editableTemplate = '<td colspan="{colspan}">{content}{error}</td>';
134  $this->resolveElementInformationDuringFormLayoutRender($elementInformation);
135  $elementclassname = $elementInformation['type'] . 'Element';
136  $element = new $elementclassname(
137  $this->model,
138  $elementInformation['attributeName'],
139  $form,
140  array_slice($elementInformation, 2));
141  $element->editableTemplate = $editableTemplate;
142  $rowTitlesAndContent[$title] .= $element->render();
143  }
144  }
145  }
146  }
147  ksort($rowTitlesAndContent);
148  foreach ($rowTitlesAndContent as $rowcontent)
149  {
150  if (!empty($rowcontent))
151  {
152  $content .= '<tr>';
153  $content .= $rowcontent;
154  $content .= '</tr>';
155  }
156  }
157  $content .= '</tbody>';
158  $content .= '</table>';
159  }
160  return $content;
161  }
162 
166  public static function getDesignerRulesType()
167  {
168  return null;
169  }
170 
175  protected static function assertMetadataIsValid(array $metadata)
176  {
177  }
178 
179  public function isUniqueToAPage()
180  {
181  return true;
182  }
183 
188  protected function getFormLayoutMetadata()
189  {
190  return $this->metadata;
191  }
192  }
193 ?>
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
__construct($renderType, $controllerId, $moduleId, $model, $modelId, $metadata, $title=null)
resolveElementInformationDuringFormLayoutRender(&$elementInformation)
Generated on Thu Apr 9 2020 07:10:46