class CampaignMonitorCampaign in Campaign Monitor 8
Hierarchy
- class \Drupal\campaignmonitor\CampaignMonitor
- class \Drupal\campaignmonitor_campaign\CampaignMonitorCampaign
Expanded class hierarchy of CampaignMonitorCampaign
1 file declares its use of CampaignMonitorCampaign
- CampaignMonitorCampaignSendForm.php in modules/
campaignmonitor_campaign/ src/ Form/ CampaignMonitorCampaignSendForm.php
File
- modules/
campaignmonitor_campaign/ src/ CampaignMonitorCampaign.php, line 10
Namespace
Drupal\campaignmonitor_campaignView source
class CampaignMonitorCampaign extends CampaignMonitor {
/**
* Used to load the different library parts of the API.
*/
const CampaignMonitorCAMPAIGN = 'csrest_campaigns.php';
protected $campaignMonitor;
/**
*
*/
public function __construct() {
// // Get account information.
$this->campaignMonitor = CampaignMonitor::GetConnector();
}
/**
* Create API campaign object.
*
* @return mixed object CS_REST_Clients | FALSE
* The Campaign Monitor client object or FALSE on failure.
*/
protected function createCampaignObj() {
if ($this->campaignMonitor
->libraryLoad(self::CampaignMonitorCAMPAIGN)) {
// See http://drupal.stackexchange.com/questions/142247/how-to-autoload-classes-from-a-3rd-party-php-library-in-drupal-8
return new \CS_REST_Campaigns($this->campaignMonitor->client_id, $this->campaignMonitor->api_key);
}
$this->campaignMonitor
->addError(WATCHDOG_ERROR, t('Failed to locate the client library.'));
return FALSE;
}
/**
* Create a new campaign at the Campaign Monitor servers. The side-effect is that
* the local cache is cleared.
*
* @param array $data
* Has the following keys:
* 'Subject' => 'Campaign Subject',
* 'Name' => 'Campaign Name',
* 'FromName' => 'Campaign From Name',
* 'FromEmail' => 'Campaign From Email Address',
* 'ReplyTo' => 'Campaign Reply To Email Address',
* 'HtmlUrl' => 'Campaign HTML Import URL',
* # 'TextUrl' => 'Optional campaign text import URL',
* 'ListIDs' => array('First List', 'Second List'),
* 'SegmentIDs' => array('First Segment', 'Second Segment')
*
* @return bool
* TRUE on success, FALSE otherwise.
*/
public function createCampaign($data) {
if ($obj = $this
->createCampaignObj(NULL)) {
$result = $obj
->create($this->campaignMonitor->client_id, $data);
if ($result
->was_successful()) {
// Clear the cache, so the list information can be retrieved again.
$this->campaignMonitor
->clearCache();
return $result
->was_successful();
}
else {
$this->campaignMonitor
->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
drupal_set_message(t('Error message: @message', [
'@message' => $result->response->Message,
]));
return FALSE;
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected | property | Config settings. | |
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected static | property | Holds the object instance (part of the singleton pattern). | |
CampaignMonitor:: |
protected | property | These variables are used as static cache for the object. | |
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected | property | ||
CampaignMonitor:: |
protected | function | Add an error to the local stack and call watchdog, if logging is enabled. | |
CampaignMonitor:: |
constant | Used to load the different library parts of the API. | ||
CampaignMonitor:: |
constant | |||
CampaignMonitor:: |
constant | |||
CampaignMonitor:: |
public | function | Clears all the caches used by this wrapper object. | |
CampaignMonitor:: |
protected | function | Create API client object. | |
CampaignMonitor:: |
public | function | Create a new list at the Campaign Monitor servers. The side-effect is that the local cache is cleared. | |
CampaignMonitor:: |
protected | function | Create API list object. | |
CampaignMonitor:: |
protected | function | Create API subscribers object. | |
CampaignMonitor:: |
public | function | Delete a list from Campaign Monitor. This action can not be reverted. The list is also removed from the local cache. | |
CampaignMonitor:: |
protected | function | Create a UNIX timestamp based on the cache timeout set in the administration interface. | |
CampaignMonitor:: |
public | function | Get basic information about campaigns in the form of a keyed array. The information is stored locally in a temporary cache. The array is formatted like this:. | |
CampaignMonitor:: |
public static | function | Implements a singleton pattern that returns an instance of this object. The function requires Campaign Monitor account keys to create the connection. These keys can be found at the Campaign Monitor homepage and should be entered in the administration… | |
CampaignMonitor:: |
public | function | Fetch custom fields for a given list, then store this information locally in the list cache. The information is stored as a keyed array on the list array under the "CustomFields" key. | |
CampaignMonitor:: |
public | function | Get basic information about drafts in the form of a keyed array. The information is stored locally in a temporary cache. The array is formatted like this:. | |
CampaignMonitor:: |
public | function | Returns the internal error array with the format below. | |
CampaignMonitor:: |
public | function | Get all information available about a given list. This is done by calling getLists(), getListDetails() and getCustomFields(), hence building the local list cache. | |
CampaignMonitor:: |
public | function | Returns the latest error from the stack of possible errors encountered during communication with Campaign Monitor servers. | |
CampaignMonitor:: |
public | function | Gets list details from Campaign Monitor. This information is retrieved from the local cache and may be outdated. It fetches the unsubscribe link, confirmation success page and confirmed opt-in options. | |
CampaignMonitor:: |
public | function | Gets all lists from Campaign Monitor found under the client ID given during object creation. The list is returned as a keyed array and cached in the cache table, so it may not always return the newest information. | |
CampaignMonitor:: |
public | function | Fetch stats about a given list, which includes number of subscribers and unsubscribers. This information is temporarily stored in the local cache. The default timeout is 360 seconds. | |
CampaignMonitor:: |
public | function | Get values entered by the subscriber, when she/he subscribed to a given list. | |
CampaignMonitor:: |
public | function | Check if a given user, identified by e-mail address, is subscribed to a given list. | |
CampaignMonitor:: |
public | function | Remove subscribers from local cache. This forces the data to be fetched from Campaign Monitor at the next request. This function should be used in connection with updating subscriber information. | |
CampaignMonitor:: |
public | function | Resets the internal error array to an empty array. | |
CampaignMonitor:: |
public | function | Subscribe a user to a given list, with information entered. If the user is already subscribed to the list, her/his information will be updated with the new values. | |
CampaignMonitor:: |
public | function | Unsubscribe a given user, identified by e-mail address, from a given list. | |
CampaignMonitor:: |
public | function | Update remote list information. The options array should have the fields "Title", "UnsubscribePage", "ConfirmedOptIn" and "ConfirmationSuccessPage". If you do not wish to set these use an empty string. | |
CampaignMonitor:: |
public | function | Updates the subscriber e-mail address for a given list. | |
CampaignMonitorCampaign:: |
protected | property | ||
CampaignMonitorCampaign:: |
constant | Used to load the different library parts of the API. | ||
CampaignMonitorCampaign:: |
public | function | Create a new campaign at the Campaign Monitor servers. The side-effect is that the local cache is cleared. | |
CampaignMonitorCampaign:: |
protected | function | Create API campaign object. | |
CampaignMonitorCampaign:: |
public | function |
Private class constructor, which prevents creation of this class directly.
Use the static function CampaignMonitor::GetConnector(). Overrides CampaignMonitor:: |