You are here

public function CampaignMonitorUserManager::getUserSubscriptions in Campaign Monitor 8.2

Helper function to get a user's subscriptions.

Parameters

string $email: The user mail id.

string $format: Return value depends on format requested.

Return value

array list names.

File

modules/campaignmonitor_user/src/CampaignMonitorUserManager.php, line 105

Class

CampaignMonitorUserManager
Manager for Campaignmonitor subscriptions.

Namespace

Drupal\campaignmonitor_user

Code

public function getUserSubscriptions($email, $format = 'checkboxes') {
  $lists = $this->campaignMonitorManager
    ->getLists();

  // Build options for the form selector.
  $options = [];
  $default = [];
  foreach ($lists as $list_id => $list) {

    // Check if the list is selected to be shown.
    // $list_options = $this->campaignMonitorManager
    // ->getListSettings($list_id);.
    if ($this->campaignMonitorManager
      ->isListEnabled($list_id)) {

      // Check if the user is subscribed to the current list.
      $default[$list_id] = 0;
      if ($this->campaignMonitorManager
        ->isSubscribed($list_id, $email)) {
        $default[$list_id] = $list_id;
        $options[$list_id] = $list['name'];
      }
    }
  }
  switch ($format) {
    case 'checkboxes':
      return $default;
    default:
      return $options;
  }
}