public function CampaignMonitor::getSubscriber in Campaign Monitor 8
Get values entered by the subscriber, when she/he subscribed to a given list.
Parameters
string $listId: The unique Campaign Monitor list ID.
string $email: The e-mail address that identifies the subscriber.
Return value
mixed array | FALSE An array containing subscriber information or FALSE on failure.
1 call to CampaignMonitor::getSubscriber()
- CampaignMonitor::isSubscribed in src/
CampaignMonitor.php - Check if a given user, identified by e-mail address, is subscribed to a given list.
File
- src/
CampaignMonitor.php, line 717 - 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 getSubscriber($listId, $email) {
$fetch = FALSE;
if (!isset($this->subscribers[$listId . $email])) {
// Not found inside object, try the cache.
if (($cache = \Drupal::cache()
->get('campaignmonitor_subscribers')) && !empty($cache->data)) {
// Cache information found.
$this->subscribers = $cache->data;
if (!isset($this->subscribers[$listId . $email])) {
// Not found inside cache either.
$fetch = TRUE;
}
}
else {
// No cache found or expired.
$fetch = TRUE;
}
}
if ($fetch) {
if ($obj = $this
->createSubscriberObj($listId)) {
$this->subscribers[$listId . $email] = [];
$result = $obj
->get($email);
if ($result
->was_successful()) {
foreach ($result->response as $key => $value) {
if ($key == 'CustomFields') {
// Convert the custom fields object into a keyed array.
$this->subscribers[$listId . $email][$key] = [];
foreach ($value as $field) {
// Check if the field has been set. If not, set the value.
if (!isset($this->subscribers[$listId . $email][$key][$field->Key])) {
$this->subscribers[$listId . $email][$key][$field->Key] = $field->Value;
}
elseif (!is_array($this->subscribers[$listId . $email][$key][$field->Key])) {
// If the field is not an array, assign an array to the field, containing the previous value of the field and this new value.
$this->subscribers[$listId . $email][$key][$field->Key] = [
$this->subscribers[$listId . $email][$key][$field->Key],
$field->Value,
];
}
else {
$this->subscribers[$listId . $email][$key][$field->Key][] = $field->Value;
}
}
}
else {
$this->subscribers[$listId . $email][$key] = $value;
}
}
// Save the subscriber information in the cache.
\Drupal::cache()
->set('campaignmonitor_subscribers', $this->subscribers, $this
->getCacheTimeout());
}
else {
$this
->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
return [];
}
}
else {
return FALSE;
}
}
return $this->subscribers[$listId . $email];
}