function newsletter_load_custom_newsletters in Newsletter 7
Load draft newsletters as object containing all needed information.
Parameters
$sent: Whether to load the sent custom Newlsetters.
Return value
an array with newsletter draft objects with the following properties: id: the draft key in the drupal variable system. title: the newsletter title. template_title: the template title this draft uses. subscribers: the array with subscriber objects that this newsletter will be sent to draft: boolean TRUE.
1 call to newsletter_load_custom_newsletters()
- newsletter_draft_manual_list in includes/
newsletter.admin.inc - Menu callback; List manual lists and newsletter drafts.
File
- includes/
newsletter.admin.inc, line 1607 - Admin page callbacks for the newsletter module.
Code
function newsletter_load_custom_newsletters($sent = TRUE) {
$draft_newsletters = variable_get('newsletter_custom_drafts', array());
$custom_newsletters = array();
foreach ($draft_newsletters as $nnid => $newsletter) {
$draft = new stdClass();
$draft->id = $nnid;
$draft->title = newsletter_newsletter_load($nnid)->title;
$draft->template_title = newsletter_template_load($newsletter['ntid'])->subject;
$draft->custom = TRUE;
$custom_newsletters[] = $draft;
}
if ($sent) {
$query = db_select('newsletter_newsletter', 'newsletters');
$query
->join('newsletter_template', 'templates', 'newsletters.ntid = templates.ntid');
$query
->addField('templates', 'subject', 'template_title');
$query
->addField('newsletters', 'nnid', 'id');
$query
->fields('newsletters', array(
'title',
));
$query
->condition('custom', 1);
$manual_lists = $query
->execute()
->fetchAll();
foreach ($manual_lists as $manual) {
$manual->custom = TRUE;
if (array_search($manual, $custom_newsletters) === FALSE) {
$manual->sent = TRUE;
$custom_newsletters[] = $manual;
}
}
}
return $custom_newsletters;
}