You are here

function mailchimp_get_campaign_data in Mailchimp 7.3

Same name and namespace in other branches
  1. 8 mailchimp.module \mailchimp_get_campaign_data()
  2. 7.5 mailchimp.module \mailchimp_get_campaign_data()
  3. 7.2 mailchimp.module \mailchimp_get_campaign_data()
  4. 7.4 mailchimp.module \mailchimp_get_campaign_data()
  5. 2.x mailchimp.module \mailchimp_get_campaign_data()

Wrapper around MCAPI->campaigns->getList to return data for a given campaign.

Data is stored in the MailChimp cache.

Parameters

string $campaign_id: The ID of the campaign to get data for.

bool $reset: Set to TRUE if campaign data should not be loaded from cache.

Return value

mixed Array of campaign data or FALSE if not found.

2 calls to mailchimp_get_campaign_data()
MailchimpCampaignsTestCase::testGetCampaign in modules/mailchimp_campaign/tests/mailchimp_campaigns.test
Tests retrieval of a specific campaign.
mailchimp_activity_page in modules/mailchimp_activity/mailchimp_activity.module
Content for the mailchimp log tab on entity instance pages.

File

./mailchimp.module, line 908
Mailchimp module.

Code

function mailchimp_get_campaign_data($campaign_id, $reset = FALSE) {
  $cache = $reset ? NULL : cache_get('campaign_' . $campaign_id, 'cache_mailchimp');
  $campaign_data = FALSE;

  // Return cached lists:
  if ($cache) {
    return $campaign_data = $cache->data;
  }
  try {
    $mcapi = mailchimp_get_api_object();
    if (!$mcapi) {
      throw new MailchimpException('Cannot get list without MailChimp API. Check API key has been entered.');
    }
    $filters = array(
      'campaign_id' => $campaign_id,
    );
    $results = $mcapi->campaigns
      ->getList($filters, 0, 1);
    if (isset($results['total']) && $results['total']) {
      $campaign_data = $results['data'][0];
      cache_set('campaign_' . $campaign_id, $campaign_data, 'cache_mailchimp', CACHE_TEMPORARY);
    }
    else {
      $campaign_data = FALSE;
    }
  } catch (Exception $e) {
    watchdog('mailchimp', 'An error occurred retrieving campaign data for @campaign. "%message"', array(
      '@campaign' => $campaign_id,
      '%message' => $e
        ->getMessage(),
    ), WATCHDOG_ERROR);
  }
  return $campaign_data;
}