abstract.inc in Message Notify 7.2
File
plugins/notifier/abstract.inc
View source
<?php
interface MessageNotifierInterface {
public function __construct($plugin, Message $message);
public function send();
public function deliver(array $output = array());
public function postSend($result, array $output = array());
public function access();
}
abstract class MessageNotifierBase implements MessageNotifierInterface {
protected $plugin;
protected $message;
public function __construct($plugin, Message $message) {
$this->plugin = $plugin;
$this->message = $message;
}
public function send() {
$message = $this->message;
$output = array();
foreach ($this->plugin['view_modes'] as $view_mode => $value) {
$content = $message
->buildContent($view_mode);
$output[$view_mode] = render($content);
}
$result = $this
->deliver($output);
$this
->postSend($result, $output);
return $result;
}
public function deliver(array $output = array()) {
}
public function postSend($result, array $output = array()) {
$plugin = $this->plugin;
$message = $this->message;
$options = $plugin['options'];
$save = FALSE;
if (!$result) {
watchdog('message_notify', t('Could not send message using @title to user ID @uid.'), array(
'@title' => $plugin['title'],
'@uid' => $message->uid,
), WATCHDOG_ERROR);
if ($options['save on fail']) {
$save = TRUE;
}
}
elseif ($result && $options['save on success']) {
$save = TRUE;
}
if ($options['rendered fields']) {
$wrapper = entity_metadata_wrapper('message', $message);
foreach ($this->plugin['view_modes'] as $view_mode => $mode) {
if (empty($options['rendered fields'][$view_mode])) {
throw new MessageNotifyException(format_string('The rendered view mode @mode cannot be saved to field, as there is not a matching one.', array(
'@mode' => $mode['label'],
)));
}
$field_name = $options['rendered fields'][$view_mode];
if (!($field = field_info_field($field_name))) {
throw new MessageNotifyException(format_string('Field @field does not exist.', array(
'@field' => $field_name,
)));
}
if (empty($wrapper->{$field_name}->format)) {
$wrapper->{$field_name}
->set($output[$view_mode]);
}
else {
$format = $wrapper->type->{MESSAGE_FIELD_MESSAGE_TEXT}
->get(0)->format
->value();
$wrapper->{$field_name}
->set(array(
'value' => $output[$view_mode],
'format' => $format,
));
}
}
}
if ($save) {
$message
->save();
}
}
public function access() {
return TRUE;
}
}