function node_registration_send_broadcast in Node registration 7
Send an email to all registrations for a given node.
5 calls to node_registration_send_broadcast()
- node_registration_cancel_action in includes/
node_registration.actions.inc - Action handler: cancel registration.
- node_registration_cron in ./
node_registration.module - Implements hook_cron().
- node_registration_form_submit in includes/
node_registration.forms.inc - Submit handler for node_registration_form().
- node_registration_node_registration_update in ./
node_registration.module - Implements hook_node_registration_update().
- node_registration_registrations_broadcast_form_submit in includes/
node_registration.forms.inc - Submit handler for registration_registrations_broadcast_form.
File
- includes/
node_registration.api.inc, line 190 - Registration API functions.
Code
function node_registration_send_broadcast($node, $subject, $message, $registrations = array(), $options = array()) {
// Registrations.
$registrations or $registrations = node_registration_load_multiple(FALSE, array(
'nid' => $node->nid,
'cancelled' => 0,
));
// Options.
$notify = isset($options['notify']) ? $options['notify'] : FALSE;
if ($registrations) {
// Send e-mails.
$sent_to = 0;
foreach ($registrations as $registration) {
$registration->node = $node;
$token_data = array(
'node' => $node,
'node-registration' => $registration,
);
if (isset($options['alter'])) {
$context = array(
'node' => $node,
'registration' => $registration,
);
$type = array(
'node_registration_email',
'node_registration_email_' . $options['alter'],
);
drupal_alter($type, $options, $context);
}
$result = _node_registration_send_email($registration->email, $subject, $message, $token_data, $options);
if ($result) {
$sent_to++;
}
else {
// Log failure.
watchdog('node_registration', 'Failed to send registration broadcast e-mail to %email.', array(
'%email' => $registration->email,
), WATCHDOG_ERROR);
}
}
if ($sent_to) {
$params = array(
'@total' => count($registrations),
'@sent_to' => $sent_to,
);
if ($notify) {
// Notify user of success.
drupal_set_message(t('The message has been sent to @sent_to / @total registrees.', $params));
}
// Log success.
watchdog('node_registration', 'Registration e-mail sent to @sent_to / @total registrants.', $params);
}
else {
if ($notify) {
// Notify user of failure.
drupal_set_message(t('There was an error sending the message.'), 'error');
}
}
}
else {
if ($notify) {
drupal_set_message(t('There are no participants registered for this %type.', array(
'%type' => $node->type,
)), 'warning');
}
}
}