Overview

Namespaces

  • Ctct
    • Auth
    • Components
      • Account
      • Activities
      • Contacts
      • EmailMarketing
      • Tracking
    • Exceptions
    • Services
  • PHP

Classes

  • Campaign
  • ClickThroughDetails
  • MessageFooter
  • Schedule
  • TestSend
  • Overview
  • Namespace
  • Class
  • Tree
  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:  * Represents a single Campaign in Constant Contact
 14:  *
 15:  * @package        Components
 16:  * @subpackage     EmailMarketing
 17:  * @author         Constant Contact
 18:  */
 19: class Campaign extends Component
 20: {
 21:     /**
 22:      * Unique identifier for the email campaign
 23:      * @var string
 24:      */
 25:     public $id;
 26: 
 27:     /**
 28:      * Name of the email campaign; each email campaign name must be unique within a user's account
 29:      * @var string
 30:      */
 31:     public $name;
 32: 
 33:     /**
 34:      * The Subject Line for the email campaign
 35:      * @var string
 36:      */
 37:     public $subject;
 38: 
 39:     /**
 40:      * Current status of the email campaign
 41:      * @var string
 42:      */
 43:     public $status;
 44: 
 45:     /**
 46:      * Name displayed in the From field to indicate whom the email is from
 47:      * @var string
 48:      */
 49:     public $from_name;
 50: 
 51:     /**
 52:      * The email address the email campaign originated from, this must be a verified email address for the account owner
 53:      * @var string
 54:      */
 55:     public $from_email;
 56: 
 57:     /**
 58:      * The reply-to email address for the email campaign, this must be a verified email address for the account owner
 59:      * @var string
 60:      */
 61:     public $reply_to_email;
 62:     
 63:     /**
 64:      * The template used to create the email campaign
 65:      * @var string
 66:      */
 67:     public $template_type;
 68: 
 69:     /**
 70:      * Date the email campaign was last sent to contacts, in ISO-8601 format
 71:      * @var string
 72:      */
 73:     public $created_date;
 74: 
 75:     /**
 76:      * Date the email campaign was last modified, in ISO-8601 format
 77:      * @var string
 78:      */
 79:     public $modified_date;
 80: 
 81:     /**
 82:      * Date the email campaign was last run, in ISO-8601 format
 83:      * @var string
 84:      */
 85:     public $last_run_date;
 86: 
 87:     /**
 88:      * Date the email campaign is next scheduled to run and be sent to contacts, in ISO-8601 format
 89:      * @var string
 90:      */
 91:     public $next_run_date;
 92: 
 93:     /**
 94:      * If true, displays permission_reminder_text at top of email message
 95:      * @var boolean
 96:      */
 97:     public $is_permission_reminder_enabled;
 98: 
 99:     /**
100:      * Text to be displayed at the top of the email if is_permission_reminder_enabled is true
101:      * @var string
102:      */
103:     public $permission_reminder_text;
104: 
105:     /**
106:      * If true, displays the text and link specified in permission_reminder_text to view web page 
107:      * version of email message
108:      * @var string
109:      */
110:     public $is_view_as_webpage_enabled;
111: 
112:     /**
113:      * Text to be displayed if is_view_as_webpage_enabled is true
114:      * @var string
115:      */
116:     public $view_as_web_page_text;
117: 
118:     /**
119:      * Text that will be dispalyed as the link if is_view_as_webpage_enabled is true
120:      * @var string
121:      */
122:     public $view_as_web_page_link_text;
123: 
124:     /**
125:      * The salutation used in the email message (e.g. Dear)
126:      * @var string
127:      */
128:     public $greeting_salutations;
129: 
130:     /**
131:      * This is the personalized content for each contact that will be used in the greeting
132:      * @var string
133:      */
134:     public $greeting_name;
135: 
136:     /**
137:      * Specifies the greeting text used if not using greeting_name and greeting_salutations
138:      * @var string
139:      */
140:     public $greeting_string;
141: 
142:     /**
143:      * Defines the content of the email campaign message footer
144:      * @var MessageFooter
145:      */
146:     public $message_footer;
147: 
148:     /**
149:      * Campaign Tracking summary data for this campaign
150:      * @var TrackingSummary
151:      */
152:     public $tracking_summary;
153: 
154:     /**
155:      * The full HTML or XHTML content of the email campaign
156:      * @var string
157:      */
158:     public $email_content;
159: 
160:     /**
161:      * Specifies the email campaign message format, valid values: HTML, XHTML
162:      * @var string
163:      */
164:     public $email_content_format;
165: 
166:     /**
167:      * Style sheet used in the email
168:      * @var string
169:      */
170:     public $style_sheet;
171: 
172:     /**
173:      * The content for the text-only version of the email campaign which is viewed by recipients 
174:      * whose email client does not accept HTML email
175:      * @var string
176:      */
177:     public $text_content;
178: 
179:     /**
180:      * Unique IDs of the contact lists the email campaign message is sent to
181:      * @var array
182:      */
183:     public $sent_to_contact_lists = array();
184: 
185:     /**
186:      * Tracking summary data for this email campaign
187:      * @var array
188:      */
189:     public $click_through_details = array();
190: 
191:     /**
192:      * URL of the permalink for this email campaign if it exists
193:      * @var string
194:      */
195:     public $permalink_url;
196: 
197:     /**
198:      * Factory method to create a Campaign object from an array
199:      * @param array $props - associative array of initial properties to set
200:      * @return Campaign
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:      * Factory method to create a Campaign object from an array
257:      * @param array $props - associative array of initial properties to set
258:      * @return Campaign
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:         // remove unused fields
269:         foreach ($campaign as $key => $value) {
270:             if ($value == null) {
271:                 unset($campaign->$key);
272:             }
273:         }
274: 
275:         return $campaign;
276:     }
277: 
278:     /**
279:      * Add a contact list to set of lists associated with this email
280:      * @param mixed $contact_list - Contact list id, or ContactList object
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:      * Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent 
297:      * @return string 
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:             // remove sent_to_contact_lists fields that cause errors
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: 
Appconnect PHP SDK API documentation generated by ApiGen 2.8.0