Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
WorkflowActionAttributeForm.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 
41  {
42  const TYPE_STATIC = 'Static';
43 
44  const TYPE_STATIC_NULL = 'StaticNull';
45 
46  abstract public function getValueElementType();
47 
48  abstract protected function makeTypeValuesAndLabels($isCreatingNewModel, $isRequired);
49 
53  public $type;
54 
58  public $value;
59 
65  protected $stringifiedModelForValue;
66 
71  public $shouldSetValue;
72 
79  protected $modelClassName;
80 
86  protected $modelAttributeName;
87 
92  protected $displayLabel;
93 
99  protected $shouldResolveValueForMergeTags = false;
100 
105  public static function getFormType()
106  {
107  $type = get_called_class();
108  $type = substr($type, 0, strlen($type) - strlen('WorkflowActionAttributeForm'));
109  return $type;
110  }
111 
116  public static function resolveValueBeforeSave()
117  {
118  return true;
119  }
120 
125  public function __construct($modelClassName, $modelAttributeName)
126  {
127  assert('is_string($modelClassName)');
128  assert('is_string($modelAttributeName)');
129  $this->modelClassName = $modelClassName;
130  $this->modelAttributeName = $modelAttributeName;
131  }
132 
138  public function getAlternateValue()
139  {
140  return $this->value;
141  }
142 
146  public function getDisplayLabel()
147  {
148  return $this->displayLabel;
149  }
150 
154  public function getStringifiedModelForValue()
155  {
156  return $this->stringifiedModelForValue;
157  }
158 
162  public function setDisplayLabel($displayLabel)
163  {
164  assert('is_string($displayLabel)');
165  $this->displayLabel = $displayLabel;
166  }
167 
171  public function getModelClassName()
172  {
173  return $this->modelClassName;
174  }
175 
179  public function getModelAttributeName()
180  {
181  return $this->modelAttributeName;
182  }
183 
187  public function rules()
188  {
189  $rules = array_merge(parent::rules(), array(
190  array('type', 'type', 'type' => 'string'),
191  array('type', 'required'),
192  array('value', 'safe'),
193  array('value', 'validateValue'),
194  array('shouldSetValue', 'boolean'),
195  ));
198  $this->modelClassName,
199  $this->modelAttributeName,
200  'value');
201  return array_merge($rules, $applicableRules);
202  }
203 
207  public function attributeLabels()
208  {
209  return array('alternateValue' => Zurmo::t('Core', 'Value'));
210  }
211 
216  public function validateValue()
217  {
218  if ($this->type == self::TYPE_STATIC && empty($this->value) && $this->shouldSetValue)
219  {
220  $this->addError('value', Zurmo::t('Core', 'Value cannot be blank.'));
221  return false;
222  }
223  return true;
224  }
225 
232  public function getTypeValuesAndLabels($isCreatingNewModel, $isRequired)
233  {
234  assert('is_bool($isCreatingNewModel)');
235  assert('is_bool($isRequired)');
236  return $this->makeTypeValuesAndLabels($isCreatingNewModel, $isRequired);
237  }
238 
246  {
247  assert('is_string($attribute)');
248  if ($this->type == WorkflowActionAttributeForm::TYPE_STATIC)
249  {
250  $value = $this->value;
251  if ($this->shouldResolveValueForMergeTags)
252  {
253  $value = $this->resolveValueForMergeTags($value, $adapter);
254  }
255  $adapter->getModel()->{$attribute} = $value;
256  }
257  elseif ($this->type == WorkflowActionAttributeForm::TYPE_STATIC_NULL)
258  {
259  $adapter->getModel()->{$attribute} = null;
260  }
261  else
262  {
263  throw new NotSupportedException();
264  }
265  }
266 
267  public function shouldSetNullAlternativeValue()
268  {
269  return false;
270  }
271 
281  {
282  assert('is_string($attribute)');
283  if ($this->shouldSetValue || !$this->shouldSetNullAlternativeValue())
284  {
285  throw new NotSupportedException();
286  }
287  }
288 
289  protected function resolveValueForMergeTags($value, WorkflowActionProcessingModelAdapter $adapter)
290  {
291  $mergeTagsUtil = MergeTagsUtilFactory::make(EmailTemplate::TYPE_WORKFLOW,
292  Yii::app()->languageHelper->getByUser($adapter->getTriggeredByUser()),
293  $value);
294  if (false === $resolvedValue = $mergeTagsUtil->resolveMergeTags($adapter->getTriggeredModel()))
295  {
296  return $value;
297  }
298  return $resolvedValue;
299  }
300  }
301 ?>
resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
resolveNullAlternativeValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
static make($emailTemplateType, $language, $content)
__construct($modelClassName, $modelAttributeName)
static getApplicableRulesByModelClassNameAndAttributeName($modelClassName, $attributeName, $ruleAttributeName)
getTypeValuesAndLabels($isCreatingNewModel, $isRequired)
Generated on Tue Jul 7 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.