/** * Sends this notification to a User * * @param User $user */ public function send(User $user) { if ($this->moduleId == "") { throw new \yii\base\InvalidConfigException("No moduleId given!"); } // Skip - do not set notification to the originator if ($this->originator !== null && $user->id == $this->originator->id) { return; } $notification = new Notification(); $notification->user_id = $user->id; $notification->class = $this->className(); $notification->module = $this->moduleId; $notification->seen = 0; // Load group key if ($this->_groupKey === null) { $this->_groupKey = $this->getGroupKey(); } if ($this->_groupKey !== '') { $notification->group_key = $this->getGroupKey(); } if ($this->source !== null) { $notification->source_pk = $this->source->getPrimaryKey(); $notification->source_class = $this->source->className(); // Automatically set spaceId if source is Content/Addon/Container if ($this->source instanceof ContentActiveRecord || $this->source instanceof ContentAddonActiveRecord) { if ($this->source->content->container instanceof \humhub\modules\space\models\Space) { $notification->space_id = $this->source->content->container->id; } } elseif ($this->source instanceof \humhub\modules\space\models\Space) { $notification->space_id = $this->source->id; } } if ($this->originator !== null) { $notification->originator_user_id = $this->originator->id; } $notification->save(); }
/** * Marks notification as seen */ public function markAsSeen() { $this->record->seen = 1; $this->record->save(); }