Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ListAttributesSelector.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 
42  {
43  private $designerLayoutAttributes;
44 
45  private $selectedValues;
46 
47  private $layoutMetadataAdapter;
48 
49  private $viewClassName;
50 
51  private $editableMetadata;
52 
53  public function __construct($viewClassName, $moduleClassName, $modelClassName = null)
54  {
55  assert('is_string($viewClassName)');
56  assert('is_string($moduleClassName)');
57  assert('$modelClassName == null || is_string($modelClassName)');
58  if ($modelClassName == null)
59  {
60  $modelClassName = $moduleClassName::getPrimaryModelName();
61  }
62  $editableMetadata = $viewClassName::getMetadata();
63  $designerRulesType = $viewClassName::getDesignerRulesType();
64  $designerRulesClassName = $designerRulesType . 'DesignerRules';
65  $designerRules = new $designerRulesClassName();
66  $modelAttributesAdapter = DesignerModelToViewUtil::getModelAttributesAdapter($viewClassName, $modelClassName);
67  $derivedAttributesAdapter = new DerivedAttributesAdapter($modelClassName);
68  $attributeCollection = array_merge($modelAttributesAdapter->getAttributes(),
69  $derivedAttributesAdapter->getAttributes());
71  $attributeCollection,
72  $designerRules,
73  $editableMetadata
74  );
75  $this->layoutMetadataAdapter = new LayoutMetadataAdapter(
76  $viewClassName,
77  $moduleClassName,
78  $editableMetadata,
79  $designerRules,
80  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
81  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
82  );
83  $this->designerLayoutAttributes = $attributesLayoutAdapter->makeDesignerLayoutAttributes();
84  $this->viewClassName = $viewClassName;
85  $this->editableMetadata = $editableMetadata;
86  }
87 
88  protected function getDefaultListAttributesNamesAndLabelsFromEditableMetadata($metadata)
89  {
90  assert('isset($metadata["global"]["panels"])');
91  $attributeNames = array();
92  foreach ($metadata['global']['panels'] as $panelKey => $panel)
93  {
94  foreach ($panel['rows'] as $rowKey => $row)
95  {
96  foreach ($row['cells'] as $cellKey => $cell)
97  {
98  if (is_array($cell['elements']))
99  {
100  foreach ($cell['elements'] as $elementKey => $elementInformation)
101  {
102  //Expects listvie to always have a single cell per row
103  if (count($row['cells']) != 1)
104  {
105  throw new NotSupportedException();
106  }
107  if ($elementInformation['attributeName'] != 'null')
108  {
109  $attributeNames[] = $elementInformation['attributeName'];
110  }
111  else
112  {
113  $attributeNames[] = $elementInformation['type'];
114  }
115  }
116  }
117  }
118  }
119  }
120  return $attributeNames;
121  }
122 
127  {
128  $selectedValues = $this->getSelected();
129  $attributeNames = array();
130  foreach ($this->designerLayoutAttributes->get() as $attributeName => $data)
131  {
132  if (!in_array($attributeName, $selectedValues))
133  {
134  $attributeNames[$attributeName] = $data['attributeLabel'];
135  }
136  }
137  asort($attributeNames);
138  return $attributeNames;
139  }
140 
145  {
146  $selectedValues = $this->getSelected();
147  $attributeNames = array();
148  $allAttributes = $this->designerLayoutAttributes->get();
149  foreach ($selectedValues as $attributeName)
150  {
151  if (key_exists($attributeName, $allAttributes))
152  {
153  $attributeNames[$attributeName] = $allAttributes[$attributeName]['attributeLabel'];
154  }
155  else
156  {
157  throw new NotSupportedException();
158  }
159  }
160  return $attributeNames;
161  }
162 
166  public function getSelected()
167  {
168  if ($this->selectedValues != null)
169  {
170  return $this->selectedValues;
171  }
172  $attributeNames = $this->getDefaultListAttributesNamesAndLabelsFromEditableMetadata($this->editableMetadata);
173  return $attributeNames;
174  }
175 
180  {
181  $attributeNames = array();
182  foreach ($this->designerLayoutAttributes->get() as $attributeName => $data)
183  {
184  if (!$data['availableToSelect'])
185  {
186  $attributeNames[] = $attributeName;
187  }
188  }
189  return $attributeNames;
190  }
191 
192  public function setSelected($values)
193  {
194  $this->selectedValues = $values;
195  }
196 
201  public function getResolvedMetadata()
202  {
203  return $this->layoutMetadataAdapter->resolveMetadataFromSelectedListAttributes($this->viewClassName,
204  $this->getSelected());
205  }
206  }
207 ?>
static makeAttributesLayoutAdapter($attributeCollection, DesignerRules $designerRules, $editableMetadata)
static getModelAttributesAdapter($viewClassName, $modelClassName)
Generated on Sat Jul 4 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.