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