function notifications_digest_build_short in Notifications 6.3
Same name and namespace in other branches
- 6.4 notifications_digest/notifications_digest.module \notifications_digest_build_short()
Digest multiple events in a single message, short format.
Return value
array with messages ready to be sent
1 call to notifications_digest_build_short()
- NotificationsTemplatesTests::testNotificationsTemplates in tests/
notifications_templates.test - Play with creating, retrieving, deleting a pair subscriptions
1 string reference to 'notifications_digest_build_short'
- notifications_digest_notifications in notifications_digest/
notifications_digest.module - Implementation of hook_notifications()
File
- notifications_digest/
notifications_digest.module, line 176 - Notifications message digest
Code
function notifications_digest_build_short($params) {
notifications_log('Digesting short format', array(
'params' => $params,
));
// Build the base template with full parameters
$template = Notifications_Template::create_template('digest', NULL, $params->send_method, $params->language, $params->module);
// $template = notifications_digest_template(NULL, $params->module, $params->send_method, $params->language);
$template->subscriptions = $params->subscriptions;
$template->events = $params->events;
$template
->set_params($params);
$template
->add_part('subject');
$template
->add_part('header');
// Add shared objects, will be inherited by child templates
$template
->set_object('user', $params->account);
// Compile list of events for each object and build child templates
$list = array();
foreach ($params->events as $event) {
// Pass only the first subscription for this event
$subscriptions = !empty($params->subscriptions[$event->eid]) ? $params->subscriptions[$event->eid] : array();
$event_subscription = ($sid = current($subscriptions)) ? notifications_load_subscription($sid) : NULL;
// How each event is digested will depend on the event
$digest = nofitications_digest_event_info($event);
$digest_type = $digest['type'];
$digest_value = $digest['value'];
$digest_field = $digest['field'];
// Build digest line for the event, then add to the group. Method, language will be from parent
if ($event_template = $template
->get_event_template($event)) {
$event_template
->set_object('subscription', $event_subscription);
$event_template
->add_part('digest');
// We may have the template for this group already created
if (isset($list[$digest_type][$digest_value])) {
$list[$digest_type][$digest_value]
->add_child($event_template, 'events');
}
else {
// Template name will look like 'notifications-digest-node-nid'
$group_template = $template
->get_digest_template('digest', $digest_type . '-' . $digest_field);
$template
->add_child($group_template, 'main');
$group_template
->set_object($digest_type, $digest['object']);
// Just the first event's subscription will be beter than nothing
$group_template
->set_object('subscription', $event_subscription);
$group_template
->add_part('title');
$group_template
->add_child($event_template, 'events');
$group_template
->add_part('closing');
$list[$digest_type][$digest_value] = $group_template;
}
}
}
// Close the main template and render
$template
->add_part('footer');
// We dont pass a subscription object here, won't be too much use anyway
$template
->set_object('subscription', NULL);
notifications_log('Built short digest template', array(
'template' => $template,
));
// Build message from template and parameters
$message = $template
->build();
// Return array of messages instead of message;
return array(
$message,
);
}