All Data Structures Functions Variables Pages
DemoController.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 
37  Yii::import('application.modules.campaigns.controllers.DefaultController', true);
39  {
44  {
45  if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel))
46  {
47  throw new NotSupportedException();
48  }
49  $emailBox = EmailBoxUtil::getDefaultEmailBoxByUser(Yii::app()->user->userModel);
50 
51  $marketingList = new MarketingList();
52  $marketingList->name = 'Demo Marketing List';
53  $marketingList->save();
54  $campaign = new Campaign();
55  $campaign->marketingList = $marketingList;
56  $campaign->name = 'Campaign with all campaignItemActivity';
57  $campaign->subject = 'Demo for all types of campaignItemActivities';
58  $campaign->status = Campaign::STATUS_COMPLETED;
59  $campaign->sendOnDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
60  $campaign->supportsRichText = true;
61  $campaign->htmlContent = 'Demo content';
62  $campaign->fromName = 'Zurmo';
63  $campaign->fromAddress = 'zurmo@zurmo.org';
64  $campaign->enableTracking = true;
65  $saved = $campaign->save();
66  if (!$saved)
67  {
68  throw new FailedToSaveModelException();
69  }
70 
71  $contacts = Contact::getAll();
72 
73  //Awaiting queue
74  $contact = $contacts[0];
75  $campaignItem = new CampaignItem();
76  $campaignItem->processed = true;
77  $campaignItem->campaign = $campaign;
78  $campaignItem->contact = $contact;
79  $campaignItem->unrestrictedSave();
80 
81  //Contact is not subscribed
82  $contact = $contacts[1];
83  $marketingList->addNewMember($contact->id, true);
84  $campaignItem = new CampaignItem();
85  $campaignItem->processed = true;
86  $campaignItem->campaign = $campaign;
87  $campaignItem->contact = $contact;
88  $activity = new CampaignItemActivity();
89  $activity->person = $contact;
90  $activity->campaignItem = $campaignItem;
91  $activity->quantity = 1;
92  $activity->type = CampaignItemActivity::TYPE_SKIP;
93  $activity->save();
94  $campaignItem->unrestrictedSave();
95 
96  //Skipped, both primary and secondary are opted out
97  $contact = $contacts[2];
98  $contact->primaryEmail->emailAddress = $contact->firstName . '1@zurmo.org';
99  $contact->primaryEmail->optOut = true;
100  $contact->secondaryEmail->emailAddress = $contact->firstName . '2@zurmo.org';
101  $contact->secondaryEmail->optOut = true;
102  $contact->save();
103  $marketingList->addNewMember($contact->id);
104  $campaignItem = new CampaignItem();
105  $campaignItem->processed = true;
106  $campaignItem->campaign = $campaign;
107  $campaignItem->contact = $contact;
108  $activity = new CampaignItemActivity();
109  $activity->person = $contact;
110  $activity->campaignItem = $campaignItem;
111  $activity->quantity = 1;
112  $activity->type = CampaignItemActivity::TYPE_SKIP;
113  $activity->save();
114  $campaignItem->unrestrictedSave();
115 
116  //Skipped, primary is opted out but secondary is not
117  $contact = $contacts[3];
118  $contact->primaryEmail->emailAddress = $contact->firstName . '1@zurmo.org';
119  $contact->primaryEmail->optOut = true;
120  $contact->secondaryEmail->emailAddress = $contact->firstName . '2@zurmo.org';
121  $contact->secondaryEmail->optOut = false;
122  $contact->save();
123  $marketingList->addNewMember($contact->id);
124  $campaignItem = new CampaignItem();
125  $campaignItem->processed = true;
126  $campaignItem->campaign = $campaign;
127  $campaignItem->contact = $contact;
128  $activity = new CampaignItemActivity();
129  $activity->person = $contact;
130  $activity->campaignItem = $campaignItem;
131  $activity->quantity = 1;
132  $activity->type = CampaignItemActivity::TYPE_SKIP;
133  $activity->save();
134  $campaignItem->unrestrictedSave();
135 
136  //Skipped, primary and secondary not set
137  $contact = $contacts[4];
138  $contact->primaryEmail = null;
139  $contact->secondaryEmail = null;
140  $contact->save();
141  $marketingList->addNewMember($contact->id);
142  $campaignItem = new CampaignItem();
143  $campaignItem->processed = true;
144  $campaignItem->campaign = $campaign;
145  $campaignItem->contact = $contact;
146  $activity = new CampaignItemActivity();
147  $activity->person = $contact;
148  $activity->campaignItem = $campaignItem;
149  $activity->quantity = 1;
150  $activity->type = CampaignItemActivity::TYPE_SKIP;
151  $activity->save();
152  $campaignItem->unrestrictedSave();
153 
154  //Skipped, primary not set but secondary is set
155  $contact = $contacts[5];
156  $contact->primaryEmail = null;
157  $contact->secondaryEmail->emailAddress = $contact->firstName . '@zurmo.org';
158  $contact->secondaryEmail->optOut = false;
159  $contact->save();
160  $marketingList->addNewMember($contact->id);
161  $campaignItem = new CampaignItem();
162  $campaignItem->processed = true;
163  $campaignItem->campaign = $campaign;
164  $campaignItem->contact = $contact;
165  $activity = new CampaignItemActivity();
166  $activity->person = $contact;
167  $activity->campaignItem = $campaignItem;
168  $activity->quantity = 1;
169  $activity->type = CampaignItemActivity::TYPE_SKIP;
170  $activity->save();
171  $campaignItem->unrestrictedSave();
172 
173  //Queued
174  $contact = $contacts[6];
175  $campaignItem = new CampaignItem();
176  $campaignItem->processed = true;
177  $campaignItem->campaign = $campaign;
178  $campaignItem->contact = $contact;
179  $activity = new CampaignItemActivity();
180  $activity->person = $contact;
181  $activity->campaignItem = $campaignItem;
182  $activity->quantity = 1;
183  $activity->save();
184 
185  $emailMessage = new EmailMessage();
186  $emailMessage->setScenario('importModel');
187  $emailMessage->owner = $contact->owner;
188  $emailMessage->subject = 'Subject';
189  $emailContent = new EmailMessageContent();
190  $emailContent->textContent = 'My First Message';
191  $emailContent->htmlContent = 'Some fake HTML content';
192  $emailMessage->content = $emailContent;
193  //Sending is current user (super)
194  $sender = new EmailMessageSender();
195  $sender->fromAddress = 'zurmo@zurmo.org';
196  $sender->fromName = 'Zurmo';
197  $sender->personsOrAccounts->add(Yii::app()->user->userModel);
198  $emailMessage->sender = $sender;
199  //Recipient is BobMessage
200  $recipient = new EmailMessageRecipient();
201  $recipient->toAddress = 'bob.message@zurmotest.com';
202  $recipient->toName = strval($contact);
203  $recipient->personsOrAccounts->add($contact);
204  $recipient->type = EmailMessageRecipient::TYPE_TO;
205  $emailMessage->recipients->add($recipient);
206  $emailMessage->folder = EmailFolder::getByBoxAndType($emailBox, EmailFolder::TYPE_OUTBOX);
207  $emailMessage->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
208  $emailMessage->save();
209  if (!$saved)
210  {
211  throw new FailedToSaveModelException();
212  }
213  $campaignItem->emailMessage = $emailMessage;
214  $campaignItem->unrestrictedSave();
215 
216  //Queued with error
217  $contact = $contacts[7];
218  $campaignItem = new CampaignItem();
219  $campaignItem->processed = true;
220  $campaignItem->campaign = $campaign;
221  $campaignItem->contact = $contact;
222  $activity = new CampaignItemActivity();
223  $activity->person = $contact;
224  $activity->campaignItem = $campaignItem;
225  $activity->quantity = 1;
226  $activity->save();
227 
228  $emailMessage = new EmailMessage();
229  $emailMessage->setScenario('importModel');
230  $emailMessage->owner = $contact->owner;
231  $emailMessage->subject = 'Subject';
232  $emailContent = new EmailMessageContent();
233  $emailContent->textContent = 'My First Message';
234  $emailContent->htmlContent = 'Some fake HTML content';
235  $emailMessage->content = $emailContent;
236  //Sending is current user (super)
237  $sender = new EmailMessageSender();
238  $sender->fromAddress = 'zurmo@zurmo.org';
239  $sender->fromName = 'Zurmo';
240  $sender->personsOrAccounts->add(Yii::app()->user->userModel);
241  $emailMessage->sender = $sender;
242  //Recipient is BobMessage
243  $recipient = new EmailMessageRecipient();
244  $recipient->toAddress = 'bob.message@zurmotest.com';
245  $recipient->toName = strval($contact);
246  $recipient->personsOrAccounts->add($contact);
247  $recipient->type = EmailMessageRecipient::TYPE_TO;
248  $emailMessage->recipients->add($recipient);
249  $emailMessage->folder = EmailFolder::getByBoxAndType($emailBox, EmailFolder::TYPE_OUTBOX_ERROR);
250  $emailMessage->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
251  $emailMessage->sendAttempts = 2;
252  $emailMessageError = new EmailMessageSendError();
253  $emailMessageError->serializedData = serialize(array('code' => '0001', 'message' => 'Error Message'));
254  $emailMessage->error = $emailMessageError;
255  $emailMessage->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
256  $emailMessage->save();
257  if (!$saved)
258  {
259  throw new FailedToSaveModelException();
260  }
261  $campaignItem->emailMessage = $emailMessage;
262  $campaignItem->unrestrictedSave();
263 
264  //Failure
265  $contact = $contacts[8];
266  $campaignItem = new CampaignItem();
267  $campaignItem->processed = true;
268  $campaignItem->campaign = $campaign;
269  $campaignItem->contact = $contact;
270  $activity = new CampaignItemActivity();
271  $activity->person = $contact;
272  $activity->campaignItem = $campaignItem;
273  $activity->quantity = 1;
274  $activity->save();
275 
276  $emailMessage = new EmailMessage();
277  $emailMessage->setScenario('importModel');
278  $emailMessage->owner = $contact->owner;
279  $emailMessage->subject = 'Subject';
280  $emailContent = new EmailMessageContent();
281  $emailContent->textContent = 'My First Message';
282  $emailContent->htmlContent = 'Some fake HTML content';
283  $emailMessage->content = $emailContent;
284  //Sending is current user (super)
285  $sender = new EmailMessageSender();
286  $sender->fromAddress = 'zurmo@zurmo.org';
287  $sender->fromName = 'Zurmo';
288  $sender->personsOrAccounts->add(Yii::app()->user->userModel);
289  $emailMessage->sender = $sender;
290  //Recipient is BobMessage
291  $recipient = new EmailMessageRecipient();
292  $recipient->toAddress = 'bob.message@zurmotest.com';
293  $recipient->toName = strval($contact);
294  $recipient->personsOrAccounts->add($contact);
295  $recipient->type = EmailMessageRecipient::TYPE_TO;
296  $emailMessage->recipients->add($recipient);
297  $emailMessage->folder = EmailFolder::getByBoxAndType($emailBox, EmailFolder::TYPE_OUTBOX_FAILURE);
298  $emailMessage->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
299  $emailMessage->sendAttempts = 3;
300  $emailMessageError = new EmailMessageSendError();
301  $emailMessageError->serializedData = serialize(array('code' => '0001', 'message' => 'Error Message'));
302  $emailMessage->error = $emailMessageError;
303  $emailMessage->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
304  $emailMessage->save();
305  if (!$saved)
306  {
307  throw new FailedToSaveModelException();
308  }
309  $campaignItem->emailMessage = $emailMessage;
310  $campaignItem->unrestrictedSave();
311 
312  //Sent, open, click, bounce
313  $contact = $contacts[9];
314  $campaignItem = new CampaignItem();
315  $campaignItem->processed = true;
316  $campaignItem->campaign = $campaign;
317  $campaignItem->contact = $contact;
318  $activity = new CampaignItemActivity();
319  $activity->person = $contact;
320  $activity->campaignItem = $campaignItem;
321  $activity->type = CampaignItemActivity::TYPE_CLICK;
322  $activity->quantity = rand(1, 50);
323  $activity->latestDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + rand(100, 1000));
324  $activity->latestSourceIP = '10.11.12.13';
325  $activity->save();
326  $activity = new CampaignItemActivity();
327  $activity->person = $contact;
328  $activity->campaignItem = $campaignItem;
329  $activity->type = CampaignItemActivity::TYPE_OPEN;
330  $activity->quantity = rand(1, 50);
331  $activity->latestDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + rand(100, 1000));
332  $activity->latestSourceIP = '10.11.12.13';
333  $activity->save();
334  $activity = new CampaignItemActivity();
335  $activity->person = $contact;
336  $activity->campaignItem = $campaignItem;
337  $activity->type = CampaignItemActivity::TYPE_BOUNCE;
338  $activity->quantity = rand(1, 50);
339  $activity->latestDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + rand(100, 1000));
340  $activity->latestSourceIP = '10.11.12.13';
341  $activity->save();
342 
343  $emailMessage = new EmailMessage();
344  $emailMessage->setScenario('importModel');
345  $emailMessage->owner = $contact->owner;
346  $emailMessage->subject = 'Subject';
347  $emailContent = new EmailMessageContent();
348  $emailContent->textContent = 'My First Message';
349  $emailContent->htmlContent = 'Some fake HTML content';
350  $emailMessage->content = $emailContent;
351  //Sending is current user (super)
352  $sender = new EmailMessageSender();
353  $sender->fromAddress = 'zurmo@zurmo.org';
354  $sender->fromName = 'Zurmo';
355  $sender->personsOrAccounts->add(Yii::app()->user->userModel);
356  $emailMessage->sender = $sender;
357  //Recipient is BobMessage
358  $recipient = new EmailMessageRecipient();
359  $recipient->toAddress = 'bob.message@zurmotest.com';
360  $recipient->toName = strval($contact);
361  $recipient->personsOrAccounts->add($contact);
362  $recipient->type = EmailMessageRecipient::TYPE_TO;
363  $emailMessage->recipients->add($recipient);
364  $emailMessage->folder = EmailFolder::getByBoxAndType($emailBox, EmailFolder::TYPE_SENT);
365  $emailMessage->sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
366  $emailMessage->save();
367  if (!$saved)
368  {
369  throw new FailedToSaveModelException();
370  }
371 
372  $emailMessage->save();
373  $campaignItem->emailMessage = $emailMessage;
374  $campaignItem->unrestrictedSave();
375  }
376  }
377 ?>
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static getDefaultEmailBoxByUser(User $user, $refreshUserModel=true)
Generated on Fri May 29 2020 07:10:29