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