/**
* Send a notification to a subscriber
*
* @param \Elgg\Notifications\Event $event The notification event
* @param int $guid The guid of the subscriber
* @param string $method The notification method
* @return bool
* @access private
*/
protected function sendNotification(\Elgg\Notifications\Event $event, $guid, $method)
{
$recipient = get_user($guid);
if (!$recipient || $recipient->isBanned()) {
return false;
}
// don't notify the creator of the content
if ($recipient->getGUID() == $event->getActorGUID()) {
return false;
}
$actor = $event->getActor();
$object = $event->getObject();
if (!$actor || !$object) {
return false;
}
if ($object instanceof ElggEntity && !has_access_to_entity($object, $recipient)) {
return false;
}
$language = $recipient->language;
$params = array('event' => $event, 'method' => $method, 'recipient' => $recipient, 'language' => $language, 'object' => $object);
$subject = _elgg_services()->translator->translate('notification:subject', array($actor->name), $language);
$body = _elgg_services()->translator->translate('notification:body', array($object->getURL()), $language);
$notification = new \Elgg\Notifications\Notification($event->getActor(), $recipient, $language, $subject, $body, '', $params);
$type = 'notification:' . $event->getDescription();
if ($this->hooks->hasHandler('prepare', $type)) {
$notification = $this->hooks->trigger('prepare', $type, $params, $notification);
} else {
// pre Elgg 1.9 notification message generation
$notification = $this->getDeprecatedNotificationBody($notification, $event, $method);
}
if ($this->hooks->hasHandler('send', "notification:{$method}")) {
// return true to indicate the notification has been sent
$params = array('notification' => $notification, 'event' => $event);
return $this->hooks->trigger('send', "notification:{$method}", $params, false);
} else {
// pre Elgg 1.9 notification handler
$userGuid = $notification->getRecipientGUID();
$senderGuid = $notification->getSenderGUID();
$subject = $notification->subject;
$body = $notification->body;
$params = $notification->params;
return (bool) _elgg_notify_user($userGuid, $senderGuid, $subject, $body, $params, array($method));
}
}