public function CampaignMonitorManager::getCampaigns in Campaign Monitor 8.2
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:.
$campaigns[$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 campaigns or FALSE on failure.
File
- src/
CampaignMonitorManager.php, line 766
Class
- CampaignMonitorManager
- Manager for Campaignmonitor.
Namespace
Drupal\campaignmonitorCode
public function getCampaigns() {
if (empty($this->campaigns)) {
if (($cache = $this->cacheBackend
->get('campaignmonitor_campaigns')) && !empty($cache->data)) {
// Cache information found.
$this->campaigns = $cache->data;
}
else {
if ($obj = $this
->createClientObj()) {
$result = $obj
->get_campaigns();
if ($result
->was_successful()) {
// Build an array for each campaign returned.
foreach ($result->response as $campaign) {
$this->campaigns[$campaign->CampaignID] = [
'Name' => $campaign->Name,
'Subject' => $campaign->Subject,
'Sent' => strtotime($campaign->SentDate),
'Recipients' => $campaign->TotalRecipients,
'Link' => $campaign->WebVersionURL,
];
}
// Save campaigns in the cache.
$this->cacheBackend
->set('campaignmonitor_campaigns', $this->campaigns, $this
->getCacheTimeout());
}
else {
$this
->addError($result->response->Message, $result->http_status_code);
return FALSE;
}
}
else {
return FALSE;
}
}
}
return $this->campaigns;
}