You are here

function mailchimp_update_local_cached_groupings in Mailchimp 7.3

Updates the locally cached interest group data.

@array $args The args that would be sent if this was a MailChimp API call. @array &$cache The current cache information for the user.

1 call to mailchimp_update_local_cached_groupings()
mailchimp_update_local_cache in ./mailchimp.module
Updates the local cache for a user as though a queued request had been processed.

File

./mailchimp.module, line 511
Mailchimp module.

Code

function mailchimp_update_local_cached_groupings($args, &$cache) {
  $lists = cache_get('lists', 'cache_mailchimp');
  if (!$lists) {
    $list_data = mailchimp_get_list($args['list_id']);
  }
  else {
    $list_data = $lists->data[$args['list_id']];
  }
  if (!empty($list_data['intgroups'])) {
    foreach ($list_data['intgroups'] as $idx => $group_settings) {
      $interests = array();
      foreach ($group_settings['groups'] as $group) {
        if (!empty($args['merge_vars']['GROUPINGS'][$idx]['groups'][$group['name']])) {
          $interested = TRUE;
        }
        else {
          $interested = FALSE;
        }
        $interests[] = array(
          'name' => $group['name'],
          'interested' => $interested,
        );
      }
      if (empty($cache['merges']['GROUPINGS'][$idx])) {
        $cache['merges']['GROUPINGS'][$idx] = $group_settings;
      }
      $cache['merges']['GROUPINGS'][$idx]['groups'] = $interests;
    }
  }
}