Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
AttributeForm.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 $attributeName;
40  public $attributeLabels;
41  public $defaultValue = null;
42  public $isAudited = false;
43  public $isRequired = false;
44  protected $attributePropertyToDesignerFormAdapter;
45  protected $modelClassName;
46 
47  public function __construct(RedBeanModel $model = null, $attributeName = null)
48  {
49  assert('$attributeName === null || is_string($attributeName)');
50  assert('$model === null || $model->isAttribute($attributeName)');
51  if ($model !== null)
52  {
53  $this->attributeName = $attributeName;
54  $this->attributeLabels = $model->getAttributeLabelsForAllActiveLanguagesByAttributeName(
55  $attributeName);
56  $this->attributePropertyToDesignerFormAdapter = new AttributePropertyToDesignerFormAdapter();
57  $validators = $model->getValidators($attributeName);
58  foreach ($validators as $validator)
59  {
60  if ($validator instanceof CDefaultValueValidator)
61  {
62  $this->defaultValue = $validator->value;
63  }
64  elseif ($validator instanceof CRequiredValidator)
65  {
66  $this->isRequired = true;
67  $modelAttributesAdapter = new ModelAttributesAdapter($model);
68  if ($modelAttributesAdapter->isStandardAttribute($attributeName) &&
69  $modelAttributesAdapter->isStandardAttributeRequiredByDefault($attributeName))
70  {
71  $this->attributePropertyToDesignerFormAdapter->setUpdateRequiredFieldStatus(false);
72  }
73  }
74  }
75  if ($model instanceof Item && $attributeName != null)
76  {
77  $this->isAudited = $model->isAttributeAudited($attributeName);
78  }
79  }
80  }
81 
82  public function __toString()
83  {
84  $attributeLabel = ModelFormAttributeLabelsUtil::getTranslatedAttributeLabelByLabels($this->attributeLabels);
85  if ($attributeLabel == null)
86  {
87  return Zurmo::t('Core', '(Unnamed)');
88  }
89  return $attributeLabel;
90  }
91 
92  public function rules()
93  {
94  return array(
95  array('attributeName', 'required'),
96  array('attributeName', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/', // Not Coding Standard
97  'message' => Zurmo::t('Core', 'Name must not contain spaces or special characters'),
98  ),
99  array('attributeName', 'match', 'pattern' => '/^[a-z]/', // Not Coding Standard
100  'message' => Zurmo::t('Core', 'First character must be a lower case letter'),
101  ),
102  array('attributeName',
103  'length',
105  'on' => "createAttribute"),
106  array('attributeName', 'validateIsAttributeNameDatabaseReservedWord'),
107  array('attributeLabels', 'validateAttributeLabels'),
108  array('defaultValue', 'safe'),
109  array('isAudited', 'boolean'),
110  array('isRequired', 'boolean'),
111  array('attributeName',
112  'validateAttributeNameDoesNotExists',
113  'skipOnError' => true,
114  'on' => 'createAttribute',
115  ),
116  array('attributeName', 'validateAttributeDoesNotContainReservedCharacters', 'on' => 'createAttribute'),
117  );
118  }
119 
120  public function attributeLabels()
121  {
122  return array(
123  'attributeName' => Zurmo::t('DesignerModule', 'Field Name'),
124  'attributeLabels' => Zurmo::t('DesignerModule', 'Display Name'),
125  'defaultValue' => Zurmo::t('ZurmoModule', 'Default Value'),
126  'isAudited' => Zurmo::t('DesignerModule', 'Track Audit Log'),
127  'isRequired' => Zurmo::t('DesignerModule', 'Required Field'),
128  );
129  }
130 
131  public function canUpdateAttributeProperty($propertyName)
132  {
133  return $this->attributePropertyToDesignerFormAdapter->canUpdateProperty($propertyName);
134  }
135 
136  public static function getAttributeTypeDisplayName()
137  {
138  return null;
139  }
140 
141  public static function getAttributeTypeDisplayDescription()
142  {
143  return null;
144  }
145 
146  abstract public function getAttributeTypeName();
147 
159  {
160  return array();
161  }
162 
170  {
171  assert('$this->modelClassName != null');
172  $modelClassName = $this->modelClassName;
173  $model = new $modelClassName();
174  if ($model->isAttribute(ModelMetadataUtil::resolveName($this->attributeName)) ||
175  $model->isAttribute($this->attributeName) ||
176  $model->isAttributeWithLowerCaseConversion(ModelMetadataUtil::resolveName($this->attributeName)) ||
177  $model->isAttributeWithLowerCaseConversion($this->attributeName))
178  {
179  $this->addError('attributeName', Zurmo::t('DesignerModule', 'A field with this name is already used.'));
180  }
181  }
182 
187  {
188  if (in_array($this->attributeName, DatabaseCompatibilityUtil::getDatabaseReserverWords()))
189  {
190  $this->addError('attributeName', Zurmo::t('DesignerModule', '"{$attributeName}" field name is a database reserved word. Please enter a different one.',
191  array('{$attributeName}' => $this->attributeName)));
192  }
193  }
194 
199  {
200  if (!(strpos($this->attributeName, FormModelUtil::DELIMITER) === false) ||
201  !(strpos($this->attributeName, FormModelUtil::RELATION_DELIMITER) === false))
202  {
203  $this->addError('attributeName',
204  Zurmo::t('DesignerModule', '"{$attributeName}" field name contains reserved characters. Either {reserved1} or {reserved2}.',
205  array('{$attributeName}' => $this->attributeName,
206  '{reserved1}' => FormModelUtil::DELIMITER,
207  '{reserved2}' => FormModelUtil::RELATION_DELIMITER)));
208  }
209  }
210 
211  public function validateAttributeLabels($attribute, $params)
212  {
213  $data = $this->$attribute;
214  foreach (Yii::app()->languageHelper->getActiveLanguagesData() as $language => $notUsed)
215  {
216  if ( empty($data[$language]))
217  {
218  $this->addError($attribute . '[' . $language . ']', Zurmo::t('Core', 'Label must not be empty.'));
219  }
220  }
221  }
222 
223  public function setModelClassName($modelClassName)
224  {
225  $this->modelClassName = $modelClassName;
226  }
227 
228  public function getModelClassName()
229  {
230  return $this->modelClassName;
231  }
232 
240  {
241  return 'ModelAttributesAdapter';
242  }
243 
249  public function sanitizeFromPostAndSetAttributes($values)
250  {
251  assert('is_array($values)');
252  $this->setAttributes($values);
253  }
254  }
255 ?>
validateAttributeNameDoesNotExists()
sanitizeFromPostAndSetAttributes($values)
static getTranslatedAttributeLabelByLabels($attributeLabels)
const RELATION_DELIMITER
static getModelAttributeAdapterNameForSavingAttributeFormData()
validateIsAttributeNameDatabaseReservedWord()
validateAttributeDoesNotContainReservedCharacters()
Definition: Item.php:37
static resolveName($name)
getModelAttributePartialRule()
Generated on Sat Oct 24 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.