Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DropDownAttributeForm.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  {
39  public $customFieldDataName;
40 
41  public $customFieldDataData;
42 
48  public $customFieldDataLabels;
49 
55 
59  protected $customFieldDataId;
60 
61  public $defaultValueOrder;
62 
70  public function __construct(RedBeanModel $model = null, $attributeName = null)
71  {
72  parent::__construct($model, $attributeName);
73  if ($model !== null)
74  {
75  $this->customFieldDataName = $model->$attributeName->data->name;
76  $this->customFieldDataId = $model->$attributeName->data->id;
77  $this->customFieldDataData = unserialize($model->$attributeName->data->serializedData);
78  if ($model->$attributeName->data->serializedLabels !== null)
79  {
80  $this->customFieldDataLabels = unserialize($model->$attributeName->data->serializedLabels);
81  }
83  $this->defaultValue, $this->customFieldDataData);
84  }
85  }
86 
91  public function getCollectionCountData()
92  {
93  if ($this->customFieldDataId > 0)
94  {
95  return GroupedAttributeCountUtil::getCountData('CustomField', 'value', 'data',
96  $this->customFieldDataId);
97  }
98  return 0;
99  }
100 
101  public function getCustomFieldDataId()
102  {
104  }
105 
106  public function rules()
107  {
108  return array_merge(parent::rules(), array(
109  array('customFieldDataData', 'safe'),
110  array('customFieldDataDataExistingValues', 'safe'),
111  array('customFieldDataData', 'required',
112  'message' => 'You must have at least one pick list item.'),
113  array('customFieldDataData', 'validateCustomFieldDataData'),
114  array('defaultValueOrder', 'safe'),
115  array('attributeName', 'length', 'min' => 1, 'max' => 64),
116  array('customFieldDataLabels', 'safe'),
117  ));
118  }
119 
120  public function attributeLabels()
121  {
122  return array_merge(parent::attributeLabels(), array(
123  'customFieldDataData' => Zurmo::t('DesignerModule', 'Pick List Values'),
124  'customFieldDataLabels' => Zurmo::t('DesignerModule', 'Pick List Value Translations'),
125  'defaultValueOrder' => Zurmo::t('ZurmoModule', 'Default Value'),
126  ));
127  }
128 
129  public static function getAttributeTypeDisplayName()
130  {
131  return Zurmo::t('DesignerModule', 'Pick List');
132  }
133 
134  public static function getAttributeTypeDisplayDescription()
135  {
136  return Zurmo::t('DesignerModule', 'A pick list with specific values to select from');
137  }
138 
139  public function getAttributeTypeName()
140  {
141  return 'DropDown';
142  }
143 
148  {
149  return 'DropDownModelAttributesAdapter';
150  }
151 
156  public function validateCustomFieldDataData($attribute, $params)
157  {
158  $data = $this->$attribute;
159  if (!empty($data) && $nonUniqueData = array_diff_key( $data , ArrayUtil::array_iunique( $data )) )
160  {
161  $nonUniqueValuesString = null;
162  foreach ($nonUniqueData as $nonUniqueValue)
163  {
164  if ($nonUniqueValuesString != null)
165  {
166  $nonUniqueValuesString .= ', ';
167  }
168  $nonUniqueValuesString .= $nonUniqueValue;
169  }
170  $this->addError('customFieldDataData',
171  Zurmo::t('DesignerModule',
172  'Each item must be uniquely named and the following are not: {values}',
173  array('{values}' => $nonUniqueValuesString)));
174  }
175  if (!empty($data))
176  {
177  foreach ($data as $value)
178  {
179  if ($value != str_replace(',', '', $value)) // Not Coding Standard
180  {
181  $this->addError('customFieldDataData', Zurmo::t('DesignerModule', 'Each value must not contain a comma.'));
182  return;
183  }
184  elseif ($value == '')
185  {
186  $this->addError('customFieldDataData', Zurmo::t('Core', 'Value cannot be blank.'));
187  return;
188  }
189  }
190  }
191  }
192 
197  public function canUpdateAttributeProperty($propertyName)
198  {
199  if ($propertyName == 'defaultValueOrder')
200  {
201  return true;
202  }
203  return $this->attributePropertyToDesignerFormAdapter->canUpdateProperty($propertyName);
204  }
205 
210  {
212  }
213 
218  {
219  parent::validateAttributeNameDoesNotExists();
220  if (CustomFieldData::getByName($this->attributeName, false)->id > 0)
221  {
222  $this->addError('attributeName', Zurmo::t('DesignerModule', 'A field with this name and data is already used in another module.'));
223  }
224  }
225  }
226 ?>
__construct(RedBeanModel $model=null, $attributeName=null)
static array_iunique($array)
Definition: ArrayUtil.php:93
canUpdateAttributeProperty($propertyName)
static getCountData($modelClassName, $attributeName, $filterByAttributeName=null, $filterByAttributeValue=null)
static getDefaultValueOrderFromDefaultValue($defaultValue, $customFieldDataData)
validateCustomFieldDataData($attribute, $params)
static getByName($name, $shouldCache=true)
static getModelPluralNameAndAttributeLabelsByName($name)
static getModelAttributeAdapterNameForSavingAttributeFormData()
Generated on Fri Sep 25 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.