Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ExplicitReadWriteModelPermissionsElement.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 
47  {
48  protected function getExplicitReadWriteModelPermissions()
49  {
50  return $this->model->{$this->attribute};
51  }
52 
53  protected function getAttributeName()
54  {
55  return $this->attribute;
56  }
57 
63  protected function renderControlEditable()
64  {
65  $this->assertModelIsValid();
66  list($attributeName, $relationAttributeName) = $this->resolveAttributeNameAndRelatedAttributes();
67  list($data, $dataSelectOption) = $this->resolveData();
68  $content = ZurmoHtml::radioButtonList(
69  $this->getEditableInputName($attributeName, $relationAttributeName),
70  $this->resolveSelectedType(),
71  $data,
72  $this->getEditableHtmlOptions(),
73  $dataSelectOption);
74  return $content;
75  }
76 
77  protected function assertModelIsValid()
78  {
79  assert('$this->model instanceof ModelForm || $this->model instanceof ConfigurableMetadataModel ||
80  $this->model instanceof SecurableItem || $this->model instanceof CFormModel');
81  assert('$this->getExplicitReadWriteModelPermissions() instanceof ExplicitReadWriteModelPermissions');
82  assert('$this->getExplicitReadWriteModelPermissions()->getReadOnlyPermitablesCount() == 0');
83  assert('$this->getExplicitReadWriteModelPermissions()->getReadWritePermitablesCount() >= 0');
84  }
85 
86  protected function renderControlNonEditable()
87  {
88  $selectedType = $this->resolveSelectedType();
89  $permissionTypes = static::getPermissionTypes();
90  if ($selectedType == ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP)
91  {
92  $selectedGroups = static::getSelectableGroupsData();
93  $stringContent = ArrayUtil::getArrayValue($permissionTypes, $selectedType);
94  $stringContent .= '&#160;';
95  $stringContent = ArrayUtil::getArrayValue($selectedGroups, $this->resolveSelectedGroup());
96  }
97  else
98  {
99  $stringContent = ArrayUtil::getArrayValue($permissionTypes, $selectedType);
100  }
101  return Yii::app()->format->text($stringContent);
102  }
103 
108  protected function renderLabel()
109  {
110  if ($this->form === null)
111  {
112  throw new NotImplementedException();
113  }
114  return ZurmoHtml::label(Zurmo::t('ZurmoModule', 'Who can read and write'), false);
115  }
116 
121  protected function renderError()
122  {
123  return null;
124  }
125 
126  public function getEditableHtmlOptions()
127  {
128  list($attributeName, $relationAttributeName) = $this->resolveAttributeNameAndRelatedAttributes();
129  $htmlOptions = array(
130  'id' => $this->getEditableInputId($attributeName, $relationAttributeName),
131  );
132  $htmlOptions['template'] = '<div class="radio-input">{input}{label}</div>';
133  $htmlOptions['separator'] = '';
134  return $htmlOptions;
135  }
136 
140  protected function resolveData()
141  {
142  $selectableGroupsDropDownContent = $this->renderSelectableGroupsContent();
143  $data = static::getPermissionTypes();
144  $dataIndex = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP;
145  $dataSelectOption = array();
146  if ($selectableGroupsDropDownContent != null)
147  {
148  $dataSelectOption[$dataIndex] = '&#160;' . $selectableGroupsDropDownContent;
149  }
150  else
151  {
152  unset($data[$dataIndex]);
153  }
154  return array($data, $dataSelectOption);
155  }
156 
162  protected function resolveSelectedType()
163  {
164  $selectedType = null;
165  $firstGroupPermitable = $this->findFirstGroupPermitable();
166  if (isset($firstGroupPermitable))
167  {
168  if ($firstGroupPermitable->name == Group::EVERYONE_GROUP_NAME)
169  {
170  $selectedType = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP;
171  }
172  else
173  {
174  $selectedType = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP;
175  }
176  }
177  return $selectedType;
178  }
179 
185  protected function resolveSelectedGroup()
186  {
187  $selectedGroupId = null;
188  $firstGroupPermitable = $this->findFirstGroupPermitable();
189  if (isset($firstGroupPermitable) && $firstGroupPermitable->name != Group::EVERYONE_GROUP_NAME)
190  {
191  $selectedGroupId = $firstGroupPermitable->id;
192  }
193  return $selectedGroupId;
194  }
195 
196  protected static function getPermissionTypes()
197  {
198  return array(
199  null => Zurmo::t('ZurmoModule', 'Owner'),
200  ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP =>
201  Zurmo::t('ZurmoModule', 'Owner and users in'),
202  ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP =>
204  }
205 
206  protected function renderSelectableGroupsContent()
207  {
208  list($selectableAttributeName, $selectableRelationAttributeName) = $this->resolveSelectableAttributeNameAndRelatedAttributes();
209  $htmlOptions = array(
210  'id' => $this->getEditableInputId ($selectableAttributeName, $selectableRelationAttributeName),
211  'onclick' => 'document.getElementById("{bindId}").checked="checked";',
212  );
213  $name = $this->getEditableInputName($selectableAttributeName, $selectableRelationAttributeName);
214  $dropDownArray = static::getSelectableGroupsData();
215  if ($dropDownArray == null)
216  {
217  return null;
218  }
219  return ZurmoHtml::dropDownList($name, $this->resolveSelectedGroup(), $dropDownArray, $htmlOptions);
220  }
221 
222  public static function getSelectableGroupsData()
223  {
224  $groups = Group::getAll();
225  $groupsData = array();
226  foreach ($groups as $group)
227  {
228  if ($group->name != Group::EVERYONE_GROUP_NAME && $group->name != Group::SUPER_ADMINISTRATORS_GROUP_NAME)
229  {
230  $groupsData[$group->id] = strval($group);
231  }
232  }
233  return $groupsData;
234  }
235 
236  protected function resolveAttributeNameAndRelatedAttributes()
237  {
238  return array($this->getAttributeName(), 'type');
239  }
240 
241  protected function resolveSelectableAttributeNameAndRelatedAttributes()
242  {
243  return array($this->getSelectableAttributeName(), 'nonEveryoneGroup');
244  }
245 
246  protected function getSelectableAttributeName()
247  {
248  return $this->getAttributeName();
249  }
250 
251  protected function findFirstGroupPermitable()
252  {
253  $modelPermissions = $this->getExplicitReadWriteModelPermissions();
254  if ($modelPermissions === null)
255  {
256  return null;
257  }
258  $permitablesCount = $modelPermissions->getReadWritePermitablesCount();
259  if ($permitablesCount)
260  {
261  $permitables = $this->getExplicitReadWriteModelPermissions()->getReadWritePermitables();
262  foreach ($permitables as $permitable)
263  {
264  if (get_class($permitable) === 'Group')
265  {
266  return $permitable;
267  }
268  }
269  }
270  return null;
271  }
272 
273  public function resolveModelPermissionsArray()
274  {
275  $type = $this->resolveSelectedType();
276  $nonEveryoneGroup = $this->resolveSelectedGroup();
277  $explicitReadWriteModelPermissions = compact('type', 'nonEveryoneGroup');
278  $permissions = compact('explicitReadWriteModelPermissions');
279  if ($this->model instanceof OwnedSecurableItem)
280  {
281  $owner = array('id' => $this->model->owner->id);
282  $permissions = compact('owner', 'explicitReadWriteModelPermissions');
283  }
284  return $permissions;
285  }
286  }
287 ?>
static resolveEveryoneDisplayLabel()
static dropDownList($name, $select, $data, $htmlOptions=array())
Definition: ZurmoHtml.php:627
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static radioButtonList($name, $select, $data, $htmlOptions=array(), $dataSelectOptions=array(), $dataHtmlOptions=array())
Definition: ZurmoHtml.php:170
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Wed Oct 21 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.