Esempio n. 1
0
 /**
  * Create a site notification
  *
  * @param ElggUser   $recipient Recipient of the notification
  * @param string     $message   Notification message
  * @param ElggUser   $actor     User who caused the notification event
  * @param ElggData   $object    Optional object involved in the notification event
  * @return SiteNotification|null
  */
 public static function create($recipient, $message, $actor, $object = null)
 {
     $note = new SiteNotification();
     $note->owner_guid = $recipient->guid;
     $note->container_guid = $recipient->guid;
     $note->access_id = ACCESS_PRIVATE;
     $note->description = $message;
     if ($object) {
         // TODO Add support for setting an URL for a notification about a new relationship
         switch ($object->getType()) {
             case 'annotation':
                 // Annotations do not have an URL so we use the entity URL
                 $note->setURL($object->getEntity()->getURL());
                 break;
             default:
                 $note->setURL($object->getURL());
         }
     }
     $note->setRead(false);
     if ($note->save()) {
         $note->setActor($actor);
         return $note;
     } else {
         return null;
     }
 }
Esempio n. 2
0
 /**
  * Add a notification event to the queue
  * 
  * @param string   $action Action name
  * @param string   $type   Type of the object of the action
  * @param \ElggData $object The object of the action 
  * @return void
  * @access private
  */
 public function enqueueEvent($action, $type, $object)
 {
     if ($object instanceof \ElggData) {
         $object_type = $object->getType();
         $object_subtype = $object->getSubtype();
         $registered = false;
         if (isset($this->events[$object_type]) && isset($this->events[$object_type][$object_subtype]) && in_array($action, $this->events[$object_type][$object_subtype])) {
             $registered = true;
         }
         if ($registered) {
             $params = array('action' => $action, 'object' => $object);
             $registered = $this->hooks->trigger('enqueue', 'notification', $params, $registered);
         }
         if ($registered) {
             $this->queue->enqueue(new \Elgg\Notifications\Event($object, $action));
         }
     }
 }