Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SavedWorkflowToWorkflowAdapter.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  public static function makeWorkflowBySavedWorkflow(SavedWorkflow $savedWorkflow)
47  {
48  $workflow = new Workflow();
49  if ($savedWorkflow->id > 0)
50  {
51  $workflow->setId((int)$savedWorkflow->id);
52  }
53  $workflow->setDescription ($savedWorkflow->description);
54  $workflow->setIsActive ((bool)$savedWorkflow->isActive);
55  $workflow->setModuleClassName ($savedWorkflow->moduleClassName);
56  $workflow->setName ($savedWorkflow->name);
57  $workflow->setOrder ((int)$savedWorkflow->order);
58  $workflow->setType ($savedWorkflow->type);
59  $workflow->setTriggerOn ($savedWorkflow->triggerOn);
60  if ($savedWorkflow->serializedData != null)
61  {
62  $unserializedData = unserialize($savedWorkflow->serializedData);
63  if (isset($unserializedData['triggersStructure']))
64  {
65  $workflow->setTriggersStructure($unserializedData['triggersStructure']);
66  }
67  self::makeComponentFormAndPopulateWorkflowFromData(
68  $unserializedData[ComponentForWorkflowForm::TYPE_TRIGGERS], $workflow, 'Trigger');
69  self::makeActionForWorkflowFormAndPopulateWorkflowFromData(
70  $unserializedData[ComponentForWorkflowForm::TYPE_ACTIONS], $workflow);
71  self::makeEmailMessageForWorkflowFormAndPopulateWorkflowFromData(
72  $unserializedData[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES], $workflow);
73  if (isset($unserializedData[ComponentForWorkflowForm::TYPE_TIME_TRIGGER]))
74  {
75  $moduleClassName = $workflow->getModuleClassName();
76  $timeTrigger = new TimeTriggerForWorkflowForm($moduleClassName,
77  $moduleClassName::getPrimaryModelName(),
78  $workflow->getType());
79  $timeTrigger->setAttributes($unserializedData[ComponentForWorkflowForm::TYPE_TIME_TRIGGER]);
80  $workflow->setTimeTrigger($timeTrigger);
81  $workflow->setTimeTriggerAttribute($timeTrigger->getAttributeIndexOrDerivedType());
82  }
83  }
84  return $workflow;
85  }
86 
91  public static function resolveWorkflowToSavedWorkflow(Workflow $workflow, SavedWorkflow $savedWorkflow)
92  {
93  $savedWorkflow->description = $workflow->getDescription();
94  $savedWorkflow->isActive = $workflow->getIsActive();
95  $savedWorkflow->moduleClassName = $workflow->getModuleClassName();
96  $savedWorkflow->name = $workflow->getName();
97  $savedWorkflow->order = $workflow->getOrder();
98  $savedWorkflow->triggerOn = $workflow->getTriggerOn();
99  $savedWorkflow->type = $workflow->getType();
100  $data = array();
101  $data['triggersStructure'] = $workflow->getTriggersStructure();
103  self::makeArrayFromComponentFormsAttributesData($workflow->getTriggers());
105  self::makeArrayFromActionForWorkflowFormAttributesData($workflow->getActions());
107  self::makeArrayFromEmailMessageForWorkflowFormAttributesData($workflow->getEmailMessages());
108  if ($workflow->getTimeTrigger() != null)
109  {
110  $data[ComponentForWorkflowForm::TYPE_TIME_TRIGGER] = self::makeArrayFromTimeTriggerForWorkflowFormAttributesData(
111  $workflow->getTimeTrigger());
112  }
113  $savedWorkflow->serializedData = serialize($data);
114  }
115 
120  public static function makeArrayFromEmailMessageForWorkflowFormAttributesData(Array $componentFormsData)
121  {
122  $data = array();
123  foreach ($componentFormsData as $key => $emailMessageForWorkflowForm)
124  {
125  foreach ($emailMessageForWorkflowForm->getAttributes() as $attribute => $value)
126  {
127  $data[$key][$attribute] = $value;
128  }
129  foreach ($emailMessageForWorkflowForm->getEmailMessageRecipients() as
130  $emailMessageRecipientKey => $workflowEmailMessageRecipientForm)
131  {
132  foreach ($workflowEmailMessageRecipientForm->getAttributes() as $attribute => $value)
133  {
135  [$emailMessageRecipientKey][$attribute] = $value;
136  }
137  }
138  }
139  return $data;
140  }
141 
147  TimeTriggerForWorkflowForm $timeTriggerForWorkflowForm)
148  {
149  $data = array();
150  foreach ($timeTriggerForWorkflowForm->getAttributes() as $attribute => $value)
151  {
152  if ($attribute != 'stringifiedModelForValue')
153  {
154  $data[$attribute] = $value;
155  }
156  }
157  return $data;
158  }
159 
164  protected static function makeArrayFromComponentFormsAttributesData(Array $componentFormsData)
165  {
166  $data = array();
167  foreach ($componentFormsData as $key => $componentForm)
168  {
169  foreach ($componentForm->getAttributes() as $attribute => $value)
170  {
171  $data[$key][$attribute] = $value;
172  }
173  }
174  return $data;
175  }
176 
181  protected static function makeArrayFromActionForWorkflowFormAttributesData(Array $componentFormsData)
182  {
183  $data = array();
184  foreach ($componentFormsData as $key => $actionForWorkflowForm)
185  {
186  foreach ($actionForWorkflowForm->getAttributes() as $attribute => $value)
187  {
188  $data[$key][$attribute] = $value;
189  }
190  foreach ($actionForWorkflowForm->getActionAttributes() as $actionAttribute => $workflowActionAttributeForm)
191  {
192  foreach ($workflowActionAttributeForm->getAttributes() as $attribute => $value)
193  {
194  $data[$key][ActionForWorkflowForm::ACTION_ATTRIBUTES][$actionAttribute][$attribute] = $value;
195  }
196  }
197  }
198  return $data;
199  }
200 
206  protected static function makeComponentFormAndPopulateWorkflowFromData($componentFormsData, Workflow $workflow,
207  $componentPrefix)
208  {
209  assert('is_array($componentFormsData)');
210  assert('is_string($componentPrefix) || $componentPrefix == null');
211  $moduleClassName = $workflow->getModuleClassName();
212  $addMethodName = 'add' . $componentPrefix;
213  $componentClassName = $componentPrefix . 'ForWorkflowForm';
214  $rowKey = 0;
215  foreach ($componentFormsData as $componentFormData)
216  {
217  $component = new $componentClassName($moduleClassName,
218  $moduleClassName::getPrimaryModelName(),
219  $workflow->getType(), $rowKey);
220  $component->setAttributes($componentFormData);
221  $workflow->{$addMethodName}($component);
222  $rowKey++;
223  }
224  }
225 
230  protected static function makeActionForWorkflowFormAndPopulateWorkflowFromData($componentFormsData,
231  Workflow $workflow)
232  {
233  assert('is_array($componentFormsData)');
234  $moduleClassName = $workflow->getModuleClassName();
235  $rowKey = 0;
236  foreach ($componentFormsData as $componentFormData)
237  {
238  $component = new ActionForWorkflowForm($moduleClassName::getPrimaryModelName(),
239  $workflow->getType(), $rowKey);
240  $component->setAttributes($componentFormData);
241  $workflow->addAction($component);
242  $rowKey++;
243  }
244  }
245 
250  protected static function makeEmailMessageForWorkflowFormAndPopulateWorkflowFromData($componentFormsData,
251  Workflow $workflow)
252  {
253  assert('is_array($componentFormsData)');
254  $moduleClassName = $workflow->getModuleClassName();
255  $rowKey = 0;
256  foreach ($componentFormsData as $componentFormData)
257  {
258  $component = new EmailMessageForWorkflowForm($moduleClassName::getPrimaryModelName(),
259  $workflow->getType(), $rowKey);
260  $component->setAttributes($componentFormData);
261  $workflow->addEmailMessage($component);
262  $rowKey++;
263  }
264  }
265  }
266 ?>
static makeArrayFromTimeTriggerForWorkflowFormAttributesData(TimeTriggerForWorkflowForm $timeTriggerForWorkflowForm)
static makeArrayFromActionForWorkflowFormAttributesData(Array $componentFormsData)
getTriggersStructure()
Definition: Workflow.php:301
addEmailMessage(EmailMessageForWorkflowForm $emailMessage)
Definition: Workflow.php:469
static makeWorkflowBySavedWorkflow(SavedWorkflow $savedWorkflow)
static makeEmailMessageForWorkflowFormAndPopulateWorkflowFromData($componentFormsData, Workflow $workflow)
getIsActive()
Definition: Workflow.php:223
static makeArrayFromEmailMessageForWorkflowFormAttributesData(Array $componentFormsData)
getTimeTrigger()
Definition: Workflow.php:389
addAction(ActionForWorkflowForm $action)
Definition: Workflow.php:445
getModuleClassName()
Definition: Workflow.php:240
setAttributes($values, $safeOnly=true)
static makeActionForWorkflowFormAndPopulateWorkflowFromData($componentFormsData, Workflow $workflow)
static makeComponentFormAndPopulateWorkflowFromData($componentFormsData, Workflow $workflow, $componentPrefix)
static makeArrayFromComponentFormsAttributesData(Array $componentFormsData)
static resolveWorkflowToSavedWorkflow(Workflow $workflow, SavedWorkflow $savedWorkflow)
getTriggers()
Definition: Workflow.php:413
getEmailMessages()
Definition: Workflow.php:461
getTriggerOn()
Definition: Workflow.php:274
getOrder()
Definition: Workflow.php:257
getActions()
Definition: Workflow.php:437
getDescription()
Definition: Workflow.php:206
Generated on Wed Sep 30 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.