public function CampaignMonitor::getListStats in Campaign Monitor 8
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.
Parameters
string $listId: The Campaign Monitor list ID.
Return value
mixed array | FALSE An array containing the stats or FALSE on failure.
File
- src/
CampaignMonitor.php, line 492 - 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 getListStats($listId) {
$fetch = FALSE;
if (!isset($this->listStats[$listId])) {
// Not found inside object, try the cache.
if (($cache = \Drupal::cache()
->get('campaignmonitor_list_stats')) && !empty($cache->data)) {
// Cache information found.
$this->listStats = $cache->data;
if (!isset($this->listStats[$listId])) {
// Not found inside cache either.
$fetch = TRUE;
}
}
else {
// No cache found or expired.
$fetch = TRUE;
}
}
if ($fetch) {
if ($obj = $this
->createListObj($listId)) {
// Get stats from Campaign Monitor.
$result = $obj
->get_stats();
if ($result
->was_successful()) {
$this->listStats[$listId] = (array) $result->response;
// Update the cache.
\Drupal::cache()
->set('campaignmonitor_list_stats', $this->listStats, $this
->getCacheTimeout());
}
else {
$this
->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
return FALSE;
}
}
else {
return FALSE;
}
}
return $this->listStats[$listId];
}