function mailchimp_campaign_list_templates in Mailchimp 7.4
Same name and namespace in other branches
- 8 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_list_templates()
- 7.5 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_list_templates()
- 7.3 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_list_templates()
- 2.x modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_list_templates()
Return all available user templates.
Parameters
bool $reset: True if templates should not be loaded from cache.
int $offset: The number of templates to skip.
int $count: The number of templates to return.
string $type: The template type to limit results to.
int $folder_id: The template folder ID to limit results to.
Return value
mixed Array listing existing Mailchimp templates by type.
2 calls to mailchimp_campaign_list_templates()
- mailchimp_campaign_campaign_form in modules/
mailchimp_campaign/ includes/ mailchimp_campaign.admin.inc - Returns a form for creating a campaign.
- mailchimp_campaign_overview_page in modules/
mailchimp_campaign/ mailchimp_campaign.module - Page callback for showing a list of Mailchimp Campaign entities.
File
- modules/
mailchimp_campaign/ mailchimp_campaign.module, line 532 - Module file for mailchimp_campaign.
Code
function mailchimp_campaign_list_templates($reset = FALSE, $offset = 0, $count = 10, $type = NULL, $folder_id = NULL) {
$cache_key = 'templates-' . $offset . '-' . $count . '-' . $type . '-' . $folder_id;
$cache = $reset ? NULL : cache_get($cache_key, 'cache_mailchimp');
$all_templates = array();
// Return cached templates:
if ($cache) {
$all_templates = $cache->data;
}
else {
/* @var \Mailchimp\MailchimpTemplates $mc_templates */
if ($mc_templates = mailchimp_get_api_object('MailchimpTemplates')) {
$template_params = array(
'offset' => $offset,
'count' => $count,
);
if ($type != NULL) {
$template_params['type'] = $type;
}
if ($folder_id != NULL) {
$template_params['folder_id'] = $folder_id;
}
$response = $mc_templates
->getTemplates($template_params);
if ($response->total_items > 0) {
foreach ($response->templates as $template) {
$all_templates[$template->type][$template->id] = $template;
}
}
}
cache_set($cache_key, $all_templates, 'cache_mailchimp', CACHE_TEMPORARY);
}
return $all_templates;
}