getObject() public method

Get the object of the event
public getObject ( ) : ElggDat\ElggData | false | null
return ElggDat\ElggData | false | null
 /**
  * Get the subscriptions for this notification event
  *
  * The return array is of the form:
  *
  * array(
  *     <user guid> => array('email', 'sms', 'ajax'),
  * );
  *
  * @param \Elgg\Notifications\Event $event Notification event
  * @return array
  */
 public function getSubscriptions(\Elgg\Notifications\Event $event)
 {
     $subscriptions = array();
     if (!$this->methods) {
         return $subscriptions;
     }
     $object = $event->getObject();
     if (!$object) {
         return $subscriptions;
     }
     $prefixLength = strlen(self::RELATIONSHIP_PREFIX);
     $records = $this->getSubscriptionRecords($object->getContainerGUID());
     foreach ($records as $record) {
         $deliveryMethods = explode(',', $record->methods);
         $subscriptions[$record->guid] = substr_replace($deliveryMethods, '', 0, $prefixLength);
     }
     $params = array('event' => $event);
     return _elgg_services()->hooks->trigger('get', 'subscriptions', $params, $subscriptions);
 }
Example #2
0
 /**
  * Is someone using the deprecated override
  * 
  * @param \Elgg\Notifications\Event $event Event
  * @return boolean
  */
 protected function existsDeprecatedNotificationOverride(\Elgg\Notifications\Event $event)
 {
     $entity = $event->getObject();
     if (!elgg_instanceof($entity)) {
         return false;
     }
     $params = array('event' => $event->getAction(), 'object_type' => $entity->getType(), 'object' => $entity);
     $hookresult = $this->hooks->trigger('object:notifications', $entity->getType(), $params, false);
     if ($hookresult === true) {
         elgg_deprecated_notice("Using the plugin hook 'object:notifications' has been deprecated by the hook 'send:before', 'notifications'", 1.9);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Get body for the notification
  *
  * Plugin can define a subtype specific body simply by providing a
  * translation for the string "notification:body:<action>:<type>:<subtype".
  *
  * For example in mod/blog/languages/en.php:
  *
  *    'notification:body:publish:object:blog' => '
  *         Hi %s!
  *
  *         %s has created a new post called "%s" in the group %s.
  *
  *         It says:
  *
  *         "%s"
  *
  *         You can comment the post here:
  *         %s
  *     ',
  *
  * The arguments passed into the translation are:
  *     1. Recipient's name
  *     2. Name of the user who triggered the notification
  *     3. Title of the content
  *     4. Name of the content's container
  *     5. The actual content (entity's 'description' field)
  *     6. URL to the content
  *
  * Argument swapping can be used to change the order of the parameters.
  * See http://php.net/manual/en/function.sprintf.php#example-5427
  *
  * @param Event     $event     Notification event
  * @param \ElggUser $recipient Notification recipient
  * @return string Notification body in the recipient's language
  */
 private function getNotificationBody(Event $event, \ElggUser $recipient)
 {
     $actor = $event->getActor();
     $object = $event->getObject();
     /* @var \ElggObject $object */
     $language = $recipient->language;
     // Check custom notification body for the action/type/subtype combination
     $body_key = "notification:{$event->getDescription()}:body";
     if ($this->translator->languageKeyExists($body_key, $language)) {
         $container = $object->getContainerEntity();
         return $this->translator->translate($body_key, array($recipient->name, $actor->name, $object->getDisplayName(), $container->getDisplayName(), $object->description, $object->getURL()), $language);
     }
     // Fall back to default body
     return $this->translator->translate('notification:body', array($object->getURL()), $language);
 }