You are here

public function CampaignMonitor::getLists in Campaign Monitor 7

Gets all lists from Campaign Monitor.

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 CampaignMonitor::getLists()
CampaignMonitor::getCustomFields in lib/campaignmonitor.class.inc
Gets custom fields.
CampaignMonitor::getExtendedList in lib/campaignmonitor.class.inc
Get all information available about a given list.
CampaignMonitor::getListDetails in lib/campaignmonitor.class.inc
Gets list details from Campaign Monitor.

File

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

Class

CampaignMonitor
Implementation of the CampaignMonitor class.

Code

public function getLists() {
  if (empty($this->lists)) {
    if (($cache = cache_get('campaignmonitor_lists')) && !empty($cache->data)) {

      // 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,
            ];
          }
          cache_set('campaignmonitor_lists', $this->lists, 'cache');
        }
        else {
          $this
            ->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
        }
      }
      else {
        return FALSE;
      }
    }
  }
  return $this->lists;
}