Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
EmailMessageForWorkflowForm.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 SEND_FROM_TYPE_DEFAULT = 'Default';
43 
44  const SEND_FROM_TYPE_CUSTOM = 'Custom';
45 
46  const SEND_FROM_TYPE_TRIGGERED_MODEL_OWNER = 'TriggeredModelOwner';
47 
51  const TYPE_EMAIL_MESSAGE_RECIPIENTS = 'EmailMessageRecipients';
52 
56  const EMAIL_MESSAGE_RECIPIENTS = 'EmailMessageRecipients';
57 
61  public $emailTemplateId;
62 
66  public $sendAfterDurationInterval;
67 
71  public $sendAfterDurationType = TimeDurationUtil::DURATION_TYPE_DAY;
72 
76  public $sendFromType;
77 
81  public $sendFromName;
82 
86  public $sendFromAddress;
87 
91  public $excludeIfTriggeredByUser = false;
92 
96  private $_workflowType;
97 
101  private $_emailMessageRecipients = array();
102 
108  private $_emailMessageRecipientsRealToTemporaryKeyData = array();
109 
113  private $_modelClassName;
114 
118  private $_rowKey;
119 
124  protected static function resolveErrorAttributePrefix($attributeName)
125  {
126  assert('is_int($attributeName)');
127  return self::EMAIL_MESSAGE_RECIPIENTS . '_' . $attributeName . '_';
128  }
129 
134  public function resolveNewTimeStampForDuration($initialTimeStamp)
135  {
136  assert('is_int($initialTimeStamp)');
137  return TimeDurationUtil::resolveNewTimeStampForDuration($initialTimeStamp, (int)$this->sendAfterDurationInterval,
138  TimeDurationUtil::DURATION_SIGN_POSITIVE, $this->sendAfterDurationType);
139  }
140 
144  public function getRowKey()
145  {
146  return $this->_rowKey;
147  }
148 
154  public function __construct($modelClassName, $workflowType, $rowKey = 0)
155  {
156  assert('is_string($modelClassName)');
157  assert('is_string($workflowType)');
158  assert('is_int($rowKey)');
159  $this->_modelClassName = $modelClassName;
160  $this->_workflowType = $workflowType;
161  $this->_rowKey = $rowKey;
162  }
163 
168  {
169  return count($this->_emailMessageRecipients);
170  }
171 
175  public function getEmailMessageRecipients()
176  {
177  return $this->_emailMessageRecipients;
178  }
179 
183  public function getWorkflowType()
184  {
185  return $this->_workflowType;
186  }
187 
191  public function getModelClassName()
192  {
193  return $this->_modelClassName;
194  }
195 
199  public function rules()
200  {
201  return array_merge(parent::rules(), array(
202  array('emailTemplateId', 'required'),
203  array('sendAfterDurationInterval', 'type', 'type' => 'integer'),
204  array('sendAfterDurationInterval', 'numerical', 'min' => 0),
205  array('sendAfterDurationInterval', 'required'),
206  array('sendAfterDurationType', 'type', 'type' => 'string'),
207  array('sendAfterDurationType', 'required'),
208  array('sendFromType', 'type', 'type' => 'string'),
209  array('sendFromType', 'validateSendFromType'),
210  array('sendFromName', 'type', 'type' => 'string'),
211  array('sendFromAddress', 'type', 'type' => 'string'),
212  array('excludeIfTriggeredByUser', 'type', 'type' => 'boolean'),
213  ));
214  }
215 
219  public function attributeLabels()
220  {
221  return array('emailTemplateId' => Zurmo::t('WorkflowsModule', 'Template'),
222  'sendAfterDurationInterval' => Zurmo::t('Core', 'Send After'),
223  'sendFromType' => Zurmo::t('WorkflowsModule', 'Send From'),
224  'sendFromName' => Zurmo::t('EmailMessagesModule', 'From Name'),
225  'sendFromAddress' => Zurmo::t('EmailMessagesModule', 'From Address'),
226  'excludeIfTriggeredByUser' => Zurmo::t('WorkflowsModule', 'Exclude user who triggered the action'),
227  );
228  }
229 
236  public function setAttributes($values, $safeOnly = true)
237  {
238  $recipients = null;
239  if (isset($values[self::EMAIL_MESSAGE_RECIPIENTS]) &&
240  is_array($values[self::EMAIL_MESSAGE_RECIPIENTS]))
241  {
242  $recipients = $values[self::EMAIL_MESSAGE_RECIPIENTS];
243  unset($values[self::EMAIL_MESSAGE_RECIPIENTS]);
244  $this->_emailMessageRecipients = array();
245  }
246  if (isset($values['excludeIfTriggeredByUser']))
247  {
248  $values['excludeIfTriggeredByUser'] = (bool)$values['excludeIfTriggeredByUser'];
249  }
250  parent::setAttributes($values, $safeOnly);
251  if ($recipients != null)
252  {
253  $count = 0;
254  foreach ($recipients as $temporaryKey => $recipientData)
255  {
256  if (!isset($recipientData['type']))
257  {
258  throw new NotSupportedException();
259  }
260  $form = WorkflowEmailMessageRecipientFormFactory::make($recipientData['type'], $this->_modelClassName,
261  $this->_workflowType);
262  $form->setAttributes($recipientData);
263  $this->_emailMessageRecipients[] = $form;
264  $this->_emailMessageRecipientsRealToTemporaryKeyData[] = $temporaryKey;
265  $count++;
266  }
267  }
268  }
269 
273  public function validateSendFromType()
274  {
275  if ($this->sendFromType == self::SEND_FROM_TYPE_CUSTOM)
276  {
277  $validated = true;
278  if ($this->sendFromName == null)
279  {
280  $this->addError('sendFromName', Zurmo::t('WorkflowsModule', 'From Name cannot be blank.'));
281  $validated = false;
282  }
283  if ($this->sendFromAddress == null)
284  {
285  $this->addError('sendFromAddress', Zurmo::t('WorkflowsModule', 'From Email Address cannot be blank.'));
286  $validated = false;
287  }
288  return $validated;
289  }
290  elseif ($this->sendFromType != self::SEND_FROM_TYPE_DEFAULT &&
291  $this->sendFromType != self::SEND_FROM_TYPE_TRIGGERED_MODEL_OWNER)
292  {
293  $this->addError('type', Zurmo::t('WorkflowsModule', 'Invalid Send From Type'));
294  }
295  return true;
296  }
297 
301  public function beforeValidate()
302  {
303  if (!$this->validateRecipients())
304  {
305  return false;
306  }
307  return parent::beforeValidate();
308  }
309 
313  public function validateRecipients()
314  {
315  $passedValidation = true;
316  if (count($this->_emailMessageRecipients) == 0)
317  {
318  $this->addError('recipientsValidation',
319  Zurmo::t('WorkflowsModule', 'At least one recipient must be added'));
320  return false;
321  }
322  foreach ($this->_emailMessageRecipients as $key => $workflowEmailMessageRecipientForm)
323  {
324  if (!$workflowEmailMessageRecipientForm->validate())
325  {
326  foreach ($workflowEmailMessageRecipientForm->getErrors() as $attribute => $errorArray)
327  {
328  assert('is_array($errorArray)');
329  $attributePrefix = static::resolveErrorAttributePrefix($this->resolveTemporaryKeyByRealKey($key));
330  $this->addError( $attributePrefix . $attribute, $errorArray[0]);
331  }
332  $passedValidation = false;
333  }
334  }
335  return $passedValidation;
336  }
337 
342  {
343  $data = array();
344  $data[self::SEND_FROM_TYPE_DEFAULT] = Zurmo::t('WorkflowsModule', 'Default System From Name/Address');
345  $data[self::SEND_FROM_TYPE_CUSTOM] = Zurmo::t('WorkflowsModule', 'Custom From Name/Address');
346  $data[self::SEND_FROM_TYPE_TRIGGERED_MODEL_OWNER] =
347  Zurmo::t('WorkflowsModule', "Triggered Record Owner's From Name/Address");
348  return $data;
349  }
350 
355  protected function resolveTemporaryKeyByRealKey($key)
356  {
357  assert(is_int($key)); // Not Coding Standard
358  return $this->_emailMessageRecipientsRealToTemporaryKeyData[$key];
359  }
360  }
361 ?>
static resolveErrorAttributePrefix($attributeName)
__construct($modelClassName, $workflowType, $rowKey=0)
static make($type, $modelClassName, $workflowType)
static resolveNewTimeStampForDuration($initialTimeStamp, $durationInterval, $durationSign, $durationType)
Generated on Thu Jul 9 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.