1: <?php
2: namespace Ctct\Components\EmailMarketing;
3:
4: use Ctct\Components\Component;
5: use Ctct\Util\Config;
6: use Ctct\Components\EmailMarketing\MessageFooter;
7: use Ctct\Components\Tracking\TrackingSummary;
8: use Ctct\Components\EmailMarketing\ClickThroughDetails;
9: use Ctct\Components\Contacts\ContactList;
10: use Ctct\Exceptions\IllegalArgumentException;
11:
12: 13: 14: 15: 16: 17: 18:
19: class Campaign extends Component
20: {
21: 22: 23: 24:
25: public $id;
26:
27: 28: 29: 30:
31: public $name;
32:
33: 34: 35: 36:
37: public $subject;
38:
39: 40: 41: 42:
43: public $status;
44:
45: 46: 47: 48:
49: public $from_name;
50:
51: 52: 53: 54:
55: public $from_email;
56:
57: 58: 59: 60:
61: public $reply_to_email;
62:
63: 64: 65: 66:
67: public $template_type;
68:
69: 70: 71: 72:
73: public $created_date;
74:
75: 76: 77: 78:
79: public $modified_date;
80:
81: 82: 83: 84:
85: public $last_run_date;
86:
87: 88: 89: 90:
91: public $next_run_date;
92:
93: 94: 95: 96:
97: public $is_permission_reminder_enabled;
98:
99: 100: 101: 102:
103: public $permission_reminder_text;
104:
105: 106: 107: 108: 109:
110: public $is_view_as_webpage_enabled;
111:
112: 113: 114: 115:
116: public $view_as_web_page_text;
117:
118: 119: 120: 121:
122: public $view_as_web_page_link_text;
123:
124: 125: 126: 127:
128: public $greeting_salutations;
129:
130: 131: 132: 133:
134: public $greeting_name;
135:
136: 137: 138: 139:
140: public $greeting_string;
141:
142: 143: 144: 145:
146: public ;
147:
148: 149: 150: 151:
152: public $tracking_summary;
153:
154: 155: 156: 157:
158: public $email_content;
159:
160: 161: 162: 163:
164: public $email_content_format;
165:
166: 167: 168: 169:
170: public $style_sheet;
171:
172: 173: 174: 175: 176:
177: public $text_content;
178:
179: 180: 181: 182:
183: public $sent_to_contact_lists = array();
184:
185: 186: 187: 188:
189: public $click_through_details = array();
190:
191: 192: 193: 194:
195: public $permalink_url;
196:
197: 198: 199: 200: 201:
202: public static function create(array $props)
203: {
204: $campaign = new Campaign();
205: $campaign->id = parent::getValue($props, "id");
206: $campaign->name = parent::getValue($props, "name");
207: $campaign->subject = parent::getValue($props, "subject");
208: $campaign->from_name = parent::getValue($props, "from_name");
209: $campaign->from_email = parent::getValue($props, "from_email");
210: $campaign->reply_to_email = parent::getValue($props, "reply_to_email");
211: $campaign->template_type = parent::getValue($props, "template_type");
212: $campaign->created_date = parent::getValue($props, "created_date");
213: $campaign->modified_date = parent::getValue($props, "modified_date");
214: $campaign->last_run_date = parent::getValue($props, "last_run_date");
215: $campaign->next_run_date = parent::getValue($props, "next_run_date");
216: $campaign->status = parent::getValue($props, "status");
217: $campaign->is_permission_reminder_enabled = parent::getValue($props, "is_permission_reminder_enabled");
218: $campaign->permission_reminder_text = parent::getValue($props, "permission_reminder_text");
219: $campaign->is_view_as_webpage_enabled = parent::getValue($props, "is_view_as_webpage_enabled");
220: $campaign->view_as_web_page_text = parent::getValue($props, "view_as_web_page_text");
221: $campaign->view_as_web_page_link_text = parent::getValue($props, "view_as_web_page_link_text");
222: $campaign->greeting_salutations = parent::getValue($props, "greeting_salutations");
223: $campaign->greeting_name = parent::getValue($props, "greeting_name");
224: $campaign->greeting_string = parent::getValue($props, "greeting_string");
225:
226: if (array_key_exists("message_footer", $props)) {
227: $campaign->message_footer = MessageFooter::create($props['message_footer']);
228: }
229:
230: if (array_key_exists("tracking_summary", $props)) {
231: $campaign->tracking_summary = TrackingSummary::create($props['tracking_summary']);
232: }
233:
234: $campaign->email_content = parent::getValue($props, "email_content");
235: $campaign->email_content_format = parent::getValue($props, "email_content_format");
236: $campaign->style_sheet = parent::getValue($props, "style_sheet");
237: $campaign->text_content = parent::getValue($props, "text_content");
238: $campaign->permalink_url = parent::getValue($props, "permalink_url");
239:
240: if (array_key_exists('sent_to_contact_lists', $props)) {
241: foreach ($props['sent_to_contact_lists'] as $sent_to_contact_list) {
242: $campaign->sent_to_contact_lists[] = ContactList::create($sent_to_contact_list);
243: }
244: }
245:
246: if (array_key_exists('click_through_details', $props)) {
247: foreach ($props['click_through_details'] as $click_through_details) {
248: $campaign->click_through_details[] = ClickThroughDetails::create($click_through_details);
249: }
250: }
251:
252: return $campaign;
253: }
254:
255: 256: 257: 258: 259:
260: public static function createSummary(array $props)
261: {
262: $campaign = new Campaign();
263: $campaign->id = parent::getValue($props, "id");
264: $campaign->name = parent::getValue($props, "name");
265: $campaign->status = parent::getValue($props, "status");
266: $campaign->modified_date = parent::getValue($props, "modified_date");
267:
268:
269: foreach ($campaign as $key => $value) {
270: if ($value == null) {
271: unset($campaign->$key);
272: }
273: }
274:
275: return $campaign;
276: }
277:
278: 279: 280: 281:
282: public function addList($contact_list)
283: {
284: if ($contact_list instanceof ContactList) {
285: $list = $contact_list;
286: } elseif (is_numeric($contact_list)) {
287: $list = new ContactList($contact_list);
288: } else {
289: throw new IllegalArgumentException(sprintf(Config::get('errors.id_or_object'), 'ContactList'));
290: }
291:
292: $this->sent_to_contact_lists[] = $list;
293: }
294:
295: 296: 297: 298:
299: public function toJson()
300: {
301: $campaign = clone $this;
302: unset($campaign->id);
303: unset($campaign->created_date);
304: unset($campaign->last_run_date);
305: unset($campaign->next_run_date);
306: unset($campaign->tracking_summary);
307: unset($campaign->click_through_details);
308:
309: if (is_null($campaign->message_footer)) {
310: unset($campaign->message_footer);
311: }
312:
313: if (empty($campaign->sent_to_contact_lists)) {
314: unset($campaign->sent_to_contact_lists);
315: } else {
316:
317:
318: foreach ($campaign->sent_to_contact_lists as $list) {
319: unset($list->name);
320: unset($list->contact_count);
321: unset($list->status);
322: }
323: }
324:
325: return json_encode($campaign);
326: }
327: }
328: