You are here

public function CampaignMonitor::getListDetails in Campaign Monitor 7

Gets list details from Campaign Monitor.

This information is retrieved from the local cache and may be outdated. It fetches the unsubscribe link, confirmation success page and confirmed opt-in options.

Parameters

string $list_id: The Campaign Monitor list ID.

Return value

array|bool An array with the information or FALSE on failure.

2 calls to CampaignMonitor::getListDetails()
CampaignMonitor::getExtendedList in lib/campaignmonitor.class.inc
Get all information available about a given list.
CampaignMonitor::updateList in lib/campaignmonitor.class.inc
Update remote list information.

File

lib/campaignmonitor.class.inc, line 427
Implementation of the CampaignMonitor class.

Class

CampaignMonitor
Implementation of the CampaignMonitor class.

Code

public function getListDetails($list_id) {

  // If lists have not been loaded yet, get them as they build the basic
  // cache.
  if (empty($this->lists)) {
    $this
      ->getLists();
  }

  // Test that the listId is valid.
  if (!isset($this->lists[$list_id])) {
    $this
      ->addError(WATCHDOG_ERROR, t('Unknown list id @listID.', [
      '@listID' => $list_id,
    ]));
    return FALSE;
  }

  // If list details are not set, create list object and fetch the information
  // from the Campaign Monitor servers.
  if (!isset($this->lists[$list_id]['details'])) {
    if ($obj = $this
      ->createListObj($list_id)) {
      $result = $obj
        ->get();
      if ($result
        ->was_successful()) {

        // Convert the return object into a keyed array.
        $this->lists[$list_id]['details'] = [];
        foreach ($result->response as $key => $value) {
          if (!in_array($key, [
            'ListID',
            'Title',
          ])) {
            $this->lists[$list_id]['details'][$key] = $value;
          }
        }

        // Update the cache with list details.
        cache_set('campaignmonitor_lists', $this->lists, 'cache');
      }
      else {
        $this
          ->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
        return FALSE;
      }
    }
    else {
      return FALSE;
    }
  }
  return $this->lists[$list_id]['details'];
}