You are here

function _mailchimp_get_available_lists in Mailchimp 7

Same name and namespace in other branches
  1. 5.2 mailchimp.module \_mailchimp_get_available_lists()
  2. 5 mailchimp.module \_mailchimp_get_available_lists()
  3. 6.2 mailchimp.module \_mailchimp_get_available_lists()
  4. 6 mailchimp.module \_mailchimp_get_available_lists()

Get all of the lists that the given user can subscribe to.

Parameters

object $user :

bool $exclude_required :

Return value

Array of available lists

6 calls to _mailchimp_get_available_lists()
mailchimp_block_view in ./mailchimp.module
Implements hook_block_view(). Provides a block for each available list for a given user
mailchimp_form_user_register_form_alter in ./mailchimp.module
Implements hook_form_FORM_ID_alter(). Add newsletter fields to registration form.
mailchimp_subscribe_anon_form_all in ./mailchimp.module
Return a form for all available MC lists
mailchimp_subscribe_auth_form in ./mailchimp.module
Add mailchimp form fields to account and registration forms
mailchimp_subscribe_auth_form_submit in ./mailchimp.module
Submit handler to add users to lists when editing/creating a user

... See full list

File

./mailchimp.module, line 872
Mailchimp module.

Code

function _mailchimp_get_available_lists($user, $exclude_required = FALSE) {
  $all_lists = variable_get('mailchimp_lists', NULL);
  $available_lists = array();
  if (is_array($all_lists)) {
    foreach ($all_lists as $key => $list) {

      // Continue if we only want non-required lists
      if ($exclude_required && $list->listtype === MAILCHIMP_LISTTYPE_REQUIRED) {
        continue;
      }
      foreach ($user->roles as $rid => $info) {
        if (!empty($list->roles[$rid])) {
          $available_lists[$list->id] = $list;
          break;
        }
      }
    }
  }
  return $available_lists;
}