Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DropDownDependencyAttributeForm.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 
43  {
44  public $id;
45 
64  public $mappingData = array();
65 
71 
72  public function __construct(RedBeanModel $model = null, $attributeName = null)
73  {
74  assert('$attributeName === null || is_string($attributeName)');
75  assert('$model === null || !$model->isAttribute($attributeName)');
76  if ($model !== null)
77  {
78  if ($attributeName != null)
79  {
81  getByNameAndModelClassName($attributeName, get_class($model));
82  $unserializedMetadata = unserialize($metadata->serializedMetadata);
83  $this->id = $metadata->id;
84  $this->attributeName = $metadata->name;
85  $this->attributeLabels = $unserializedMetadata['attributeLabels'];
86  $this->mappingData = $unserializedMetadata['mappingData'];
87  $this->modelClassName = get_class($model);
88  }
89  }
90  }
91 
92  public function rules()
93  {
94  return array_merge(parent::rules(), array(
95  array('mappingData', 'safe'),
96  array('mappingData', 'validateMappingData'),
97  ));
98  }
99 
100  public function attributeLabels()
101  {
102  return array_merge(parent::attributeLabels(), array(
103  'mappingData' => Zurmo::t('DesignerModule', 'Dependency Mapping'),
104  ));
105  }
106 
107  public static function getAttributeTypeDisplayName()
108  {
109  return Zurmo::t('DesignerModule', 'Dependent Pick Lists');
110  }
111 
112  public static function getAttributeTypeDisplayDescription()
113  {
114  return Zurmo::t('DesignerModule', 'A set of dependent pick lists');
115  }
116 
117  public function getAttributeTypeName()
118  {
119  return 'DropDownDependency';
120  }
121 
127  {
128  assert('$this->modelClassName != null');
129  parent::validateAttributeNameDoesNotExists();
130  try
131  {
133  getByNameAndModelClassName($this->attributeName, $this->modelClassName);
134  $this->addError('attributeName', Zurmo::t('DesignerModule', 'A field with this name is already used.'));
135  }
136  catch (NotFoundException $e)
137  {
138  }
139  }
140 
151  public function validateMappingData($attribute, $params)
152  {
153  assert('$this->modelClassName != null');
154  assert('$attribute == "mappingData"');
155  $mappingData = $this->$attribute;
156  $selectedAttributeNames = 0;
157  foreach ($mappingData as $data)
158  {
159  if (isset($data['attributeName']) && $data['attributeName'] != null)
160  {
161  $selectedAttributeNames++;
162  }
163  }
164  if (count($mappingData) < 2 || $selectedAttributeNames < 2)
165  {
166  $this->addError('mappingData', Zurmo::t('DesignerModule', 'You must select at least 2 pick-lists.'));
167  }
168  if (count($mappingData) > 4 || $selectedAttributeNames > 4)
169  {
170  $this->addError('mappingData', Zurmo::t('DesignerModule', 'You can only have at most 4 pick-lists selected.'));
171  }
172  foreach ($mappingData as $position => $attributeNameAndData)
173  {
174  assert('isset($attributeNameAndData["attributeName"])');
175  if ($position > 0 && $attributeNameAndData['attributeName'] != null)
176  {
177  if (!isset($attributeNameAndData['valuesToParentValues']) ||
178  self::getValuesToParentValuesMappedCount($attributeNameAndData['valuesToParentValues']) == 0)
179  {
180  $this->addError('mappingData', Zurmo::t('DesignerModule', 'At least one pick-list value must be mapped for each used level.'));
181  }
182  else
183  {
184  $customFieldData = CustomFieldDataModelUtil::
185  getDataByModelClassNameAndAttributeName($this->modelClassName,
186  $attributeNameAndData['attributeName']);
187  $dataValues = unserialize($customFieldData->serializedData);
188  $parentPosition = $position - 1;
189  $parentAttributeName = $mappingData[$parentPosition]['attributeName'];
190  $parentCustomFieldData = CustomFieldDataModelUtil::
191  getDataByModelClassNameAndAttributeName($this->modelClassName,
192  $parentAttributeName);
193  $parentDataValues = unserialize($parentCustomFieldData->serializedData);
194 
195  foreach ($attributeNameAndData['valuesToParentValues'] as $customFieldDataValue => $parentCustomFieldDataValue)
196  {
197  if ($parentCustomFieldDataValue != null &&
198  !in_array($parentCustomFieldDataValue, $parentDataValues))
199  {
200  $this->addError('mappingData',
201  Zurmo::t('DesignerModule',
202  'Each pick-list value must map correctly to a parent pick-list value. ' .
203  'This value does map correctly: {value} - {parentValue}',
204  array('{value}' => $customFieldDataValue,
205  '{parentValue}' => $parentCustomFieldDataValue)));
206  }
207  }
208  }
209  }
210  }
211  }
212 
217  {
218  return 'DropDownDependencyModelDerivedAttributesAdapter';
219  }
220 
225  public function sanitizeFromPostAndSetAttributes($values)
226  {
227  assert('is_array($values)');
228  if (isset($values['mappingData']))
229  {
230  foreach ($values['mappingData'] as $position => $data)
231  {
232  if ($data['attributeName'] == null && isset($data['valuesToParentValues']))
233  {
234  unset($values['mappingData'][$position]['valuesToParentValues']);
235  }
236  }
237  }
238  parent::sanitizeFromPostAndSetAttributes($values);
239  }
240 
247  public function getValuesToParentValuesMappedCount($valuesToParentValues)
248  {
249  assert('is_array($valuesToParentValues)');
250  $count = 0;
251  foreach ($valuesToParentValues as $value => $parentValue)
252  {
253  if ($parentValue != null)
254  {
255  $count++;
256  }
257  }
258  return $count;
259  }
260 
261  public function canUpdateAttributeProperty($propertyName)
262  {
263  if ($propertyName == 'attributeName' && $this->id != null)
264  {
265  return false;
266  }
267  return true;
268  }
269  }
270 ?>
static getDataByModelClassNameAndAttributeName($modelClassName, $attributeName)
static getByNameAndModelClassName($name, $modelClassName)
Generated on Wed Sep 30 2020 07:10:32
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.