class Notifications_Message in Notifications 7
Same name and namespace in other branches
- 6.4 includes/notifications_message.class.inc \Notifications_Message
- 6.3 classes/notifications_message.class.inc \Notifications_Message
Wrapper for Notifications messages
Store some more temporary properties on the message that will be dropped if the message is stored
Hierarchy
- class \Messaging_Message
- class \Notifications_Message
Expanded class hierarchy of Notifications_Message
File
- ./
notifications.message.inc, line 12 - Drupal Notifications Framework - Default class file
View source
class Notifications_Message extends Messaging_Message {
// Message type, set property
public $type = 'notifications';
// Send interval used for grouping
public $send_interval = 0;
// Notifications events
public $events = array();
// Map events to subscriptions
public $events_subscriptions = array();
// Subscriptions that triggered this message, indexed by sid
public $subscriptions = array();
// Text parts used to build this, will be useful for debugging
public $text_parts = array();
// Digest flag, will be true if this is a digest of multiple events
public $digest = FALSE;
// Build method used for this
public $build_method;
/**
* Check parameters and go for alter hook
*/
protected function do_build() {
parent::do_build();
drupal_alter('notifications_message', $this);
// Clean up Notifications objects so we don't move too much data around (Sometimes the full object gets serialized)
unset($this->events);
unset($this->events_subscriptions);
unset($this->subscriptions);
unset($this->text_parts);
// The message must be built, without errors and not for discarding
return $this
->check_status();
}
/**
* Add event to the message. One message can be produced by one or more events.
*/
public function add_event($event, $subscriptions = array()) {
$this->events[$event->eid] = $event;
$this->events_subscriptions[$event->eid] = $subscriptions;
$this
->add_subscriptions($subscriptions);
}
/**
* Add subscriptions
*/
public function add_subscriptions($subscriptions) {
foreach ($subscriptions as $sid) {
if (!isset($this->subscriptions[$sid])) {
$this->subscriptions[$sid] = $sid;
}
}
}
/**
* Set message sender. Depending on options this will set sender account too.
*
* Optional sender, if chosen will be the user account who produced the event
* It will be up to the sending method modules what to do with this information.
*/
public function set_sender($account) {
$sender_option = variable_get('notifications_sender', 0);
if ($sender_option) {
$sender = is_numeric($account) ? notifications_load_user($account) : $account;
if ($sender_option == 2) {
parent::set_sender($sender);
}
else {
$this->sender = 0;
$this->sender_name = $sender->name;
}
}
}
/**
* Digest multiple events in a single message, short format.
*
* Was: notifications_process_build_simple()
*
* @return array with messages ready to be sent
*/
public static function build_simple($template, $events, $subscriptions, $module = 'notifications') {
$messages = array();
$sender_option = variable_get('notifications_sender', 0);
foreach ($events as $event) {
$event_subscriptions = isset($subscriptions[$event->eid]) ? array_filter($subscriptions[$event->eid]) : NULL;
$message = self::build_simple_message($template, $event, $event_subscriptions, $module);
$message
->set_sender($event->uid);
$messages[] = $message;
}
return $messages;
}
/**
* Creates a single message for a single event
*
* @param $account
* Destination user account
* @param $event
* Event object which caused this notification
* @param $subscriptions
* Array of subscription ids
* @param $debug
* Return template parts information with the message
*
* @return
* Message object
*/
public static function build_simple_message($template, $event, $subscriptions, $module = 'notifications') {
$send_method = $template->method;
$destination = $template
->get_destination();
$account = $template
->get_user();
$language = $template
->get_language();
// Start the message by cloning the template
$message = clone $template;
$message
->add_event($event, $subscriptions);
// Create message. Do all this in one replacemente
$parts = array(
'subject' => $event
->message_part('subject', $send_method, $language, $module),
'header' => $event
->message_part('header', $send_method, $language, $module),
'event' => $event
->message_part('main', $send_method, $language, $module),
'footer' => $event
->message_part('footer', $send_method, $language, $module),
);
// We pass only the first subscription, which is at least something
// @ TODO Handle nicely the case where there are more than one subscription
$subscription = $subscriptions ? notifications_subscription_load(current($subscriptions)) : NULL;
$objects = array(
'destination' => $destination,
'user' => $account,
'event' => $event,
'subscription' => $subscription,
);
$objects = array_merge($objects, $event
->get_objects());
$text = messaging_template_text_replace($parts, $objects, $language);
// Get subject out of text and build the message array
$message->subject = $text['subject'];
unset($text['subject']);
$message->body = $text;
$message->text_parts = $parts;
return $message;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
protected | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
protected | property | ||
Messaging_Message:: |
protected | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
public | property | ||
Messaging_Message:: |
function | Add address or array of addresses as destination | ||
Messaging_Message:: |
function | Add list of addresses as destinations | ||
Messaging_Message:: |
function | Add destination object | ||
Messaging_Message:: |
function | Add destination list, taking care of duplicated destinations | ||
Messaging_Message:: |
function | Add user as a destination | ||
Messaging_Message:: |
function | Add list of users as destinations | ||
Messaging_Message:: |
public static | function | Build from db object | |
Messaging_Message:: |
public static | function | Build from template object | |
Messaging_Message:: |
function | Get a list of destinations for current method | ||
Messaging_Message:: |
function | Check message status, will return FALSE if we should stop processing | ||
Messaging_Message:: |
protected | function | Get default message template | |
Messaging_Message:: |
public | function | Delete message from logs and store | |
Messaging_Message:: |
function | Get list of destinations of this type | ||
Messaging_Message:: |
function | Discard message | ||
Messaging_Message:: |
function | After the message has been processed with errors | ||
Messaging_Message:: |
function | After the message has been processed successfully | ||
Messaging_Message:: |
protected | function | Check whether the message is to be sent / queued | |
Messaging_Message:: |
protected | function | Prepare for sending through given method | |
Messaging_Message:: |
protected | function | Queue message using sending method | |
Messaging_Message:: |
protected | function | Render through sending method | |
Messaging_Message:: |
protected | function | Send message through sending method | |
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
function | Get rendered body | ||
Messaging_Message:: |
function | Get message content rendered | ||
Messaging_Message:: |
function | Get destinations for sending with current method | ||
Messaging_Message:: |
function | Get message files | ||
Messaging_Message:: |
function | Get language object | ||
Messaging_Message:: |
function | Get generic parameters | ||
Messaging_Message:: |
function | Get sending results | ||
Messaging_Message:: |
function | Get sender parameters or single property | ||
Messaging_Message:: |
function | Get sender account if uid present | ||
Messaging_Message:: |
function | Get sender name | ||
Messaging_Message:: |
function | Get rendered subject | ||
Messaging_Message:: |
function | Get message template for current method | ||
Messaging_Message:: |
function | Get template text, prepared for this method | ||
Messaging_Message:: |
function | Get user, if the message is intended for a single user | ||
Messaging_Message:: |
protected | function | Invoke hook_messaging_message() on all modules | |
Messaging_Message:: |
public static | function | Load message by id | |
Messaging_Message:: |
public static | function | Load multiple events | |
Messaging_Message:: |
public | function | Log message | |
Messaging_Message:: |
protected | function | Debug facility | |
Messaging_Message:: |
protected | function | Log facility | |
Messaging_Message:: |
protected static | function | Build text parts for drupal_render() | |
Messaging_Message:: |
protected | function | Run operations on message for current method if not done before | |
Messaging_Message:: |
protected | function | Mark operation as done for the current method | |
Messaging_Message:: |
protected | function | Return process result for method and operation | |
Messaging_Message:: |
protected | function | Run operations on message for current method if not done before | |
Messaging_Message:: |
protected | function | Check whether an operation is still to do for the current method | |
Messaging_Message:: |
public | function | Queue message using the messaging store. | |
Messaging_Message:: |
public | function | Create or update message record | |
Messaging_Message:: |
public | function | Render for current method | |
Messaging_Message:: |
public | function | Save message to store $name | |
Messaging_Message:: |
public | function | Send message through sending method. | |
Messaging_Message:: |
public | function | Send message through all sending methods | |
Messaging_Message:: |
public | function | Get send method object | |
Messaging_Message:: |
function | Set error condition and stop processing | ||
Messaging_Message:: |
function | Set send method | ||
Messaging_Message:: |
function | Mark as sent for this destination key or for all | ||
Messaging_Message:: |
function | Set success status and return status check | ||
Messaging_Message:: |
function | Set message template | ||
Messaging_Message:: |
function | Set user, if the message is intended for a single user try to find suitable method | ||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
constant | |||
Messaging_Message:: |
function | Constructor, with predefined array of data | ||
Messaging_Message:: |
public | function | Magic method, properly set some variables | |
Messaging_Message:: |
public | function | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | property | ||
Notifications_Message:: |
public | function | Add event to the message. One message can be produced by one or more events. | |
Notifications_Message:: |
public | function | Add subscriptions | |
Notifications_Message:: |
public static | function | Digest multiple events in a single message, short format. | |
Notifications_Message:: |
public static | function | Creates a single message for a single event | |
Notifications_Message:: |
protected | function |
Check parameters and go for alter hook Overrides Messaging_Message:: |
|
Notifications_Message:: |
public | function | Set message sender. Depending on options this will set sender account too. |