/** * Factory method to create a Campaign object from an array * @param array $props - associative array of initial properties to set * @return Campaign */ public static function create(array $props) { $campaign = new Campaign(); $campaign->id = parent::getValue($props, "id"); $campaign->name = parent::getValue($props, "name"); $campaign->subject = parent::getValue($props, "subject"); $campaign->from_name = parent::getValue($props, "from_name"); $campaign->from_email = parent::getValue($props, "from_email"); $campaign->reply_to_email = parent::getValue($props, "reply_to_email"); $campaign->template_type = parent::getValue($props, "template_type"); $campaign->created_date = parent::getValue($props, "created_date"); $campaign->modified_date = parent::getValue($props, "modified_date"); $campaign->last_run_date = parent::getValue($props, "last_run_date"); $campaign->next_run_date = parent::getValue($props, "next_run_date"); $campaign->status = parent::getValue($props, "status"); $campaign->is_permission_reminder_enabled = parent::getValue($props, "is_permission_reminder_enabled"); $campaign->permission_reminder_text = parent::getValue($props, "permission_reminder_text"); $campaign->is_view_as_webpage_enabled = parent::getValue($props, "is_view_as_webpage_enabled"); $campaign->view_as_web_page_text = parent::getValue($props, "view_as_web_page_text"); $campaign->view_as_web_page_link_text = parent::getValue($props, "view_as_web_page_link_text"); $campaign->greeting_salutations = parent::getValue($props, "greeting_salutations"); $campaign->greeting_name = parent::getValue($props, "greeting_name"); $campaign->greeting_string = parent::getValue($props, "greeting_string"); if (array_key_exists("message_footer", $props)) { $campaign->message_footer = MessageFooter::create($props['message_footer']); } if (array_key_exists("tracking_summary", $props)) { $campaign->tracking_summary = TrackingSummary::create($props['tracking_summary']); } $campaign->email_content = parent::getValue($props, "email_content"); $campaign->email_content_format = parent::getValue($props, "email_content_format"); $campaign->style_sheet = parent::getValue($props, "style_sheet"); $campaign->text_content = parent::getValue($props, "text_content"); $campaign->permalink_url = parent::getValue($props, "permalink_url"); if (array_key_exists('sent_to_contact_lists', $props)) { foreach ($props['sent_to_contact_lists'] as $sent_to_contact_list) { $campaign->sent_to_contact_lists[] = ContactList::create($sent_to_contact_list); } } if (array_key_exists('click_through_details', $props)) { foreach ($props['click_through_details'] as $click_through_details) { $campaign->click_through_details[] = ClickThroughDetails::create($click_through_details); } } return $campaign; }
/** * Get a summary of reporting data for a given contact * @param string $accessToken - Constant Contact OAuth2 access token * @param int $contact_id - Contact id * @return TrackingSummary */ public function getSummary($accessToken, $contact_id) { $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact_tracking_summary'), $contact_id); $url = $this->buildUrl($baseUrl); $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken)); return TrackingSummary::create(json_decode($response->body, true)); }