You are here

function mailchimp_lists_get_available_lists in Mailchimp 7.2

Return all available lists for a given user.

Parameters

<drupal_user> $account: Optional account to get available lists for. Otherwise returns lists available to the currently authenticated user.

<array> $conditions: List settings to filter the results by (uses logical "AND"). Options include the following (see mailchimp_lists_list_form_submit()): 'allow_anonymous' => boolean 'required' => boolean 'doublein' => boolean 'cron' => boolean 'webhooks' => boolean 'show_account_form' => boolean 'show_register_form' => boolean 'default_register_form_optin' => boolean 'include_interest_groups' => boolean 'form_label' => string 'submit_label' => string 'interest_groups_label' => string

Return value

<array> An array of appropriate mailchimp_list objects.

7 calls to mailchimp_lists_get_available_lists()
mailchimp_lists_form_user_register_form_alter in modules/mailchimp_lists/mailchimp_lists.module
Implements hook_form_FORM_ID_alter().
mailchimp_lists_freeform_subscribe_page in modules/mailchimp_lists/mailchimp_lists.module
Page callback for a freeform newsletter subscription page.
mailchimp_lists_freeform_subscribe_page_access in modules/mailchimp_lists/mailchimp_lists.module
Access callback for mailchimp_lists_freeform_subscribe_page().
mailchimp_lists_user_delete in modules/mailchimp_lists/mailchimp_lists.module
Implements hook_user_delete().
mailchimp_lists_user_subscribe_page in modules/mailchimp_lists/mailchimp_lists.module
Page callback for a user newsletter subscription page.

... See full list

File

modules/mailchimp_lists/mailchimp_lists.module, line 829
Mailchimp lists module.

Code

function mailchimp_lists_get_available_lists($account = NULL, $conditions = array()) {
  if (empty($account)) {
    global $user;
    $account = $user;
  }
  $lists = mailchimp_lists_load_multiple(array());
  $user_lists = array();
  foreach ($lists as $lid => $list) {
    foreach ($account->roles as $rid => $role) {
      if (isset($list->settings['roles'][$rid]) && $list->settings['roles'][$rid]) {
        $pass = TRUE;
        if (!empty($conditions)) {
          foreach ($conditions as $key => $condition) {
            if (!isset($list->settings[$key]) || $list->settings[$key] != $condition) {
              $pass = FALSE;
            }
          }
        }
        if ($pass) {
          $user_lists[$lid] = $list;
        }
        break;
      }
    }
  }
  return $user_lists;
}