public function CampaignMonitor::getDrafts in Campaign Monitor 8
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:.
$drafts[$id] => array( 'Name' => 'Campaign Name', 'Subject' => 'Campaign subject line', 'Sent' => 'Unix timestamp', 'Recipients' => 'The number of recipients', 'Link' => 'Online URL to the campaign', );
Return value
mixed array | FALSE An array with the drafts or FALSE on failure.
File
- src/
CampaignMonitor.php, line 667 - Implementation of the CampaignMonitor class, which is a wrapper class for Campaign Monitor v3 API. It's implemented as a Singleton class and instances are created using the account variables and the static function getConnector(). An example:.
Class
Namespace
Drupal\campaignmonitorCode
public function getDrafts() {
if (empty($this->drafts)) {
if (($cache = \Drupal::cache()
->get('campaignmonitor_drafts')) && !empty($cache->data)) {
// Cache information found.
$this->drafts = $cache->data;
}
else {
if ($obj = $this
->createClientObj()) {
$result = $obj
->get_drafts();
if ($result
->was_successful()) {
// Build an array for each campaign returned.
foreach ($result->response as $draft) {
$this->drafts[$draft->CampaignID] = [
'Name' => $draft->Name,
'Subject' => $draft->Subject,
'Created' => strtotime($draft->DateCreated),
'From' => $draft->FromName,
'Link' => $draft->PreviewURL,
];
}
// Save drafts in the cache.
\Drupal::cache()
->set('campaignmonitor_drafts', $this->drafts, $this
->getCacheTimeout());
}
else {
$this
->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
return FALSE;
}
}
else {
return FALSE;
}
}
}
return $this->drafts;
}