Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DynamicTriggeredModelRelationWorkflowEmailMessageRecipientForm.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  {
46  const RELATION_FILTER_ALL = 'RelationFilterAll';
47 
51  public $relation;
52 
59  public $relationFilter = self::RELATION_FILTER_ALL;
60 
64  public static function getTypeLabel()
65  {
67  return Zurmo::t('WorkflowsModule', 'Related ContactsModulePluralLowerCaseLabel or LeadsModulePluralLowerCaseLabel', $params);
68  }
69 
77  public static function resolveRecipientsAsUniquePeople($existingRecipients, $newRecipients)
78  {
79  $existingItemIds = array();
80  $resolvedRecipients = array();
81  foreach ($existingRecipients as $recipient)
82  {
83  foreach ($recipient->personsOrAccounts as $personOrAccount)
84  {
85  if ($personOrAccount->id > 0)
86  {
87  if (!in_array($personOrAccount->getClassId('Item'), $existingItemIds))
88  {
89  $existingItemIds[] = $personOrAccount->getClassId('Item');
90  $resolvedRecipients[] = $recipient;
91  }
92  else
93  {
94  throw new NotSupportedException();
95  }
96  }
97  }
98  }
99  foreach ($newRecipients as $recipient)
100  {
101  foreach ($recipient->personsOrAccounts as $personOrAccount)
102  {
103  if (!in_array($personOrAccount->getClassId('Item'), $existingItemIds))
104  {
105  $existingItemIds[] = $personOrAccount->getClassId('Item');
106  $resolvedRecipients[] = $recipient;
107  }
108  }
109  }
110  return $resolvedRecipients;
111  }
112 
116  public function rules()
117  {
118  return array_merge(parent::rules(), array(
119  array('relation', 'type', 'type' => 'string'),
120  array('relation', 'required'),
121  array('relationFilter', 'type', 'type' => 'string'),
122  array('relationFilter', 'validateRelationFilter')));
123  }
124 
128  public function validateRelationFilter()
129  {
130  if ($this->relationFilter == self::RELATION_FILTER_ALL)
131  {
132  return true;
133  }
134  $this->addError('relationFilter', Zurmo::t('WorkflowsModule', 'Invalid Relation Filter'));
135  return false;
136  }
137 
141  public function getRelationValuesAndLabels()
142  {
143  $modelClassName = $this->modelClassName;
144  $adapter = ModelRelationsAndAttributesToWorkflowAdapter::make($modelClassName::getModuleClassName(),
145  $modelClassName, $this->workflowType);
146  $valueAndLabels = array();
147  foreach ($adapter->getSelectableContactRelationsDataForEmailMessageRecipientModelRelation() as $relation => $data)
148  {
149  $valueAndLabels[$relation] = $data['label'];
150  }
151  return $valueAndLabels;
152  }
153 
160  public function makeRecipients(RedBeanModel $model, User $triggeredByUser)
161  {
162  $modelClassName = $this->modelClassName;
163  $recipients = array();
164  if ($model->isADerivedRelationViaCastedUpModel($this->relation) &&
165  $model->getDerivedRelationType($this->relation) == RedBeanModel::MANY_MANY)
166  {
167  foreach (WorkflowUtil::resolveDerivedModels($model, $this->relation) as $resolvedModel)
168  {
169  $recipients = self::resolveRecipientsAsUniquePeople($recipients, $this->resolveRecipients($resolvedModel));
170  }
171  }
172  elseif ($modelClassName::getInferredRelationModelClassNamesForRelation(
174  {
175  foreach (WorkflowUtil::
176  getInferredModelsByAtrributeAndModel($this->relation, $model) as $resolvedModel)
177  {
178  $recipients = self::resolveRecipientsAsUniquePeople($recipients, $this->resolveRecipients($resolvedModel));
179  }
180  }
181  elseif ($model->{$this->relation} instanceof RedBeanMutableRelatedModels)
182  {
183  if (!$this->relationFilter == self::RELATION_FILTER_ALL)
184  {
185  throw new NotSupportedException();
186  }
187  foreach ($model->{$this->relation} as $resolvedModel)
188  {
189  $recipients = self::resolveRecipientsAsUniquePeople($recipients, $this->resolveRecipients($resolvedModel));
190  }
191  }
192  elseif ($modelClassName::isRelationTypeAHasOneVariant($this->relation))
193  {
194  if ($model->{$this->relation}->id > 0)
195  {
196  $recipients = $this->resolveRecipients($model->{$this->relation});
197  }
198  }
199  else
200  {
201  throw new NotSupportedException();
202  }
203  return $recipients;
204  }
205 
210  public function resolveRecipients(RedBeanModel $model)
211  {
212  $recipients = array();
213  if ($model instanceof Contact && $model->primaryEmail->emailAddress != null)
214  {
215  $recipient = new EmailMessageRecipient();
216  $recipient->toAddress = $model->primaryEmail->emailAddress;
217  $recipient->toName = strval($model);
218  $recipient->type = $this->audienceType;
219  $recipient->personsOrAccounts->add($model);
220  $recipients[] = $recipient;
221  }
222  return $recipients;
223  }
224  }
225 ?>
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
Definition: User.php:37
static resolveDerivedModels(RedBeanModel $model, $relation)
static make($moduleClassName, $modelClassName, $workflowType)
static getDerivedRelationType($relationName)
Definition: BeanModel.php:335
const MANY_MANY
Definition: BeanModel.php:78
static isADerivedRelationViaCastedUpModel($relationName)
Definition: BeanModel.php:320
Generated on Thu Aug 6 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.