Overview

Namespaces

  • Ctct
    • Auth
    • Components
      • Account
      • Activities
      • Contacts
      • EmailMarketing
      • Library
      • Tracking
    • Exceptions
    • Services
    • Util
    • WebHooks

Classes

  • Ctct\Auth\CtctOAuth2
  • Ctct\Auth\SessionDataStore
  • Ctct\Components\Account\AccountInfo
  • Ctct\Components\Account\VerifiedEmailAddress
  • Ctct\Components\Activities\Activity
  • Ctct\Components\Activities\ActivityError
  • Ctct\Components\Activities\AddContacts
  • Ctct\Components\Activities\AddContactsImportData
  • Ctct\Components\Activities\ExportContacts
  • Ctct\Components\Component
  • Ctct\Components\Contacts\Address
  • Ctct\Components\Contacts\Contact
  • Ctct\Components\Contacts\ContactList
  • Ctct\Components\Contacts\CustomField
  • Ctct\Components\Contacts\EmailAddress
  • Ctct\Components\Contacts\Note
  • Ctct\Components\EmailMarketing\Campaign
  • Ctct\Components\EmailMarketing\ClickThroughDetails
  • Ctct\Components\EmailMarketing\MessageFooter
  • Ctct\Components\EmailMarketing\Schedule
  • Ctct\Components\EmailMarketing\TestSend
  • Ctct\Components\Library\File
  • Ctct\Components\Library\FileUploadStatus
  • Ctct\Components\Library\Folder
  • Ctct\Components\Library\Thumbnail
  • Ctct\Components\ResultSet
  • Ctct\Components\Tracking\BounceActivity
  • Ctct\Components\Tracking\ClickActivity
  • Ctct\Components\Tracking\ForwardActivity
  • Ctct\Components\Tracking\OpenActivity
  • Ctct\Components\Tracking\SendActivity
  • Ctct\Components\Tracking\TrackingActivity
  • Ctct\Components\Tracking\TrackingSummary
  • Ctct\Components\Tracking\UnsubscribeActivity
  • Ctct\ConstantContact
  • Ctct\Services\AccountService
  • Ctct\Services\ActivityService
  • Ctct\Services\BaseService
  • Ctct\Services\CampaignScheduleService
  • Ctct\Services\CampaignTrackingService
  • Ctct\Services\ContactService
  • Ctct\Services\ContactTrackingService
  • Ctct\Services\EmailMarketingService
  • Ctct\Services\LibraryService
  • Ctct\Services\ListService
  • Ctct\SplClassLoader
  • Ctct\Util\Config
  • Ctct\WebHooks\CTCTWebhookUtil

Interfaces

  • Ctct\Auth\CtctDataStore

Exceptions

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