function mailchimp_activity_get_member_activity in Mailchimp 7.4
Same name and namespace in other branches
- 7.5 modules/mailchimp_activity/mailchimp_activity.module \mailchimp_activity_get_member_activity()
- 7.2 modules/mailchimp_activity/mailchimp_activity.module \mailchimp_activity_get_member_activity()
- 7.3 modules/mailchimp_activity/mailchimp_activity.module \mailchimp_activity_get_member_activity()
Get the Mailchimp member activity for a given email address and list.
Results are cached in the cache_mailchimp_user bin which is cleared by the Mailchimp web hooks system when needed.
Parameters
string $list_id: The Mailchimp list to get activity for.
string $email: The Mailchimp user email address to get activity for.
bool $reset: Set to TRUE if member activity should not be loaded from cache.
Return value
array Associative array of Mailchimp member activity.
1 call to mailchimp_activity_get_member_activity()
- mailchimp_activity_get_all_activity in modules/
mailchimp_activity/ mailchimp_activity.module - Return all activity on all lists for a given email address.
File
- modules/
mailchimp_activity/ mailchimp_activity.module, line 118 - Module file for mailchimp_activity.
Code
function mailchimp_activity_get_member_activity($list_id, $email, $reset = FALSE) {
$cache = $reset ? NULL : cache_get("activity_{$list_id}_{$email}", 'cache_mailchimp');
$memberactivity = array();
// Return cached lists:
if ($cache && isset($cache->data)) {
$memberactivity = $cache->data;
}
else {
/* @var \Mailchimp\MailchimpLists $mc_lists */
$mc_lists = mailchimp_get_api_object('MailchimpLists');
try {
if (!$mc_lists) {
throw new MailchimpException('Cannot get member activity without Mailchimp API. Check API key has been entered.');
}
$result = $mc_lists
->getMemberActivity($list_id, $email);
if ($result->total_items > 0) {
$memberactivity = $result->activity;
cache_set('activity_' . $list_id . '_' . $email, $memberactivity, 'cache_mailchimp', CACHE_TEMPORARY);
}
} catch (Exception $e) {
drupal_set_message($e
->getMessage(), 'error');
watchdog('mailchimp_activity', 'An error occurred while getting activity for email "%email": %message', array(
'%email' => $email,
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
return NULL;
}
}
return $memberactivity;
}