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