You are here

public function CampaignMonitorManager::getLists in Campaign Monitor 8.2

Gets all CM lists found under the client ID given during object creation.

The list is returned as a keyed array and cached in the cache table, so it may not always return the newest information.

The array has the format below. Be aware that the same cache is used for the getListDetails() and getCustomFields() functions. This means that the information returned by this function may contain an extended list of information if any of these functions have been called.

$list[$id] = array( 'name' => 'List name', );

Return value

array|false An array of lists available from Campaign Monitor or FALSE on failure.

3 calls to CampaignMonitorManager::getLists()
CampaignMonitorManager::getCustomFields in src/CampaignMonitorManager.php
Fetch custom fields for a given list.
CampaignMonitorManager::getExtendedList in src/CampaignMonitorManager.php
Get all information available about a given list.
CampaignMonitorManager::getListDetails in src/CampaignMonitorManager.php
Gets list details from Campaign Monitor.

File

src/CampaignMonitorManager.php, line 340

Class

CampaignMonitorManager
Manager for Campaignmonitor.

Namespace

Drupal\campaignmonitor

Code

public function getLists($list_ids = [], $reset = FALSE) {
  if (empty($this->lists)) {
    if (!$reset && ($cache = $this->cacheBackend
      ->get('campaignmonitor_lists'))) {

      // Cache information found.
      $this->lists = $cache->data;
    }
    else {

      // Create list object and get the lists, then save the lists in the
      // local cache.
      if ($obj = $this
        ->createClientObj()) {
        $result = $obj
          ->get_lists();
        if ($result
          ->was_successful()) {
          foreach ($result->response as $list) {
            $this->lists[$list->ListID] = [
              'name' => $list->Name,
            ];
          }
          $this->cacheBackend
            ->set('campaignmonitor_lists', $this->lists);
        }
        else {
          $this
            ->addError($result->response->Message, $result->http_status_code);
        }
      }
      else {
        return [];
      }
    }
  }

  // Filter by given IDs.
  if (!empty($list_ids)) {
    $filtered_lists = [];
    foreach ($list_ids as $id) {
      if (array_key_exists($id, $list_ids)) {
        $filtered_lists[$id] = $list_ids[$id];
      }
    }
    return $filtered_lists;
  }
  return $this->lists;
}