Abstract Class humhub\modules\notification\components\BaseNotification

Inheritancehumhub\modules\notification\components\BaseNotification » humhub\components\SocialActivity » yii\base\BaseObject
ImplementsSerializable, humhub\components\rendering\Viewable
Subclasseshumhub\modules\admin\notifications\ExcludeGroupNotification, humhub\modules\admin\notifications\IncludeGroupNotification, humhub\modules\admin\notifications\NewVersionAvailable, humhub\modules\comment\notifications\NewComment, humhub\modules\content\notifications\ContentCreated, humhub\modules\friendship\notifications\Request, humhub\modules\friendship\notifications\RequestApproved, humhub\modules\friendship\notifications\RequestDeclined, humhub\modules\like\notifications\NewLike, humhub\modules\space\notifications\ApprovalRequest, humhub\modules\space\notifications\ApprovalRequestAccepted, humhub\modules\space\notifications\ApprovalRequestDeclined, humhub\modules\space\notifications\ChangedRolesMembership, humhub\modules\space\notifications\Invite, humhub\modules\space\notifications\InviteAccepted, humhub\modules\space\notifications\InviteDeclined, humhub\modules\space\notifications\InviteRevoked, humhub\modules\space\notifications\UserAddedNotification, humhub\modules\user\notifications\Followed, humhub\modules\user\notifications\Mentioned

A BaseNotification class describes the behaviour and the type of a Notification.

A BaseNotification is created and can be sent to one or multiple users over different targets.

The BaseNotification can should be created like this:

MyNotification::instance()->from($originator)->about($source)->sendBulk($activeQueryUser);

This will send Notifications to different notification targets by using a queue.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$groupCount integer Number of combined notifications humhub\modules\notification\components\BaseNotification
$markAsSeenOnClick boolean Automatically mark notification as seen after click on it humhub\modules\notification\components\BaseNotification
$moduleId string The module id which this activity belongs to (required) humhub\components\SocialActivity
$originator humhub\modules\user\models\User humhub\components\SocialActivity
$priority boolean If set to true marks this notification type as high priority. humhub\modules\notification\components\BaseNotification
$record \yii\db\ActiveRecord The related record for this activitiy humhub\components\SocialActivity
$recordClass string Record class used for instantiation. humhub\modules\notification\components\BaseNotification
$requireOriginator boolean Ensure originator existence humhub\components\SocialActivity
$requireSource boolean Ensure source existence humhub\components\SocialActivity
$source \yii\db\ActiveRecord humhub\components\SocialActivity
$suppressSendToOriginator boolean Do not send this notification also to the originator humhub\modules\notification\components\BaseNotification
$viewName string View name used for rendering the activity humhub\components\SocialActivity

Public Methods

Hide inherited methods

MethodDescriptionDefined By
about() Builder function for the source. humhub\modules\notification\components\BaseNotification
asArray() Returns an array representation of this notification. humhub\modules\notification\components\BaseNotification
beforeMailSend() This method is invoked right before a mail will be send for this notificatoin humhub\modules\notification\components\BaseNotification
delete() Deletes this notification humhub\modules\notification\components\BaseNotification
from() Builder function for the originator. humhub\modules\notification\components\BaseNotification
getAsHtml() Use html() instead humhub\modules\notification\components\BaseNotification
getAsText() Use text() instead humhub\modules\notification\components\BaseNotification
getCategory() Returns the notification category instance. If no category class is set (default) the default notification settings can't be overwritten. humhub\modules\notification\components\BaseNotification
getContent() Returns the related content instance in case the source is of type ContentOwner. humhub\components\SocialActivity
getContentContainer() Determines if the activity source is related to an ContentContainer. humhub\components\SocialActivity
getContentInfo() Build info text about a content humhub\components\SocialActivity
getContentName() Returns the content name of $content or if not $content is provided of the notification source. humhub\components\SocialActivity
getContentPreview() Returns a short preview text of the content. The max length can be defined by setting $maxLength (25 by default). humhub\components\SocialActivity
getGroupKey() Returns a key for grouping notifications. humhub\modules\notification\components\BaseNotification
getGroupLastUsers() Returns the last users of a grouped notification humhub\modules\notification\components\BaseNotification
getGroupUserDisplayNames() Returns the combined display names of a grouped notification. humhub\modules\notification\components\BaseNotification
getMailSubject() Returns the mail subject which will be used in the notification e-mail humhub\modules\notification\components\BaseNotification
getSpace() humhub\components\SocialActivity
getSpaceId() humhub\components\SocialActivity
getUrl() Url of the origin of this notification If source is a Content / ContentAddon / ContentContainer this will automatically generated. humhub\components\SocialActivity
getViewName() humhub\components\rendering\Viewable
getViewParams() Returns an array of view parameter, required for rendering. humhub\modules\notification\components\BaseNotification
hasContent() Determines if this activity is related to a content. This is the case if the activitiy source is of type ContentOwner. humhub\components\SocialActivity
html() Should be overwritten by subclasses for a html representation of the notification. humhub\modules\notification\components\BaseNotification
init() humhub\components\SocialActivity
instance() Static initializer should be prefered over new initialization, since it makes use of Yii::createObject dependency injection/configuration. humhub\components\SocialActivity
isOriginator() Checks if the given $user is the originator of this notification. humhub\modules\notification\components\BaseNotification
json() humhub\components\rendering\Viewable
markAsSeen() Marks notification as seen humhub\modules\notification\components\BaseNotification
render() Renders the Notificaiton for the given notification target. humhub\modules\notification\components\BaseNotification
saveRecord() Creates the Notification instance of the current BaseNotification type for the given $user. humhub\modules\notification\components\BaseNotification
send() Sends this notification to all notification targets of the given User. humhub\modules\notification\components\BaseNotification
sendBulk() Sends this notification to a set of users. humhub\modules\notification\components\BaseNotification
serialize() Serializes the $source and $originator fields. humhub\components\SocialActivity
text() humhub\components\rendering\Viewable
unserialize() Unserializes the given string, calls the init() function and sets the $source and $originator fields (and $record indirectyl). humhub\components\SocialActivity
validate() Validates the existence of required attributes humhub\components\SocialActivity

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
category() Returns a new NotificationCategory instance. humhub\modules\notification\components\BaseNotification

Property Details

$_category protected property

Cached category instance

$_groupKey protected property

The group key

protected string $_groupKey null
$groupCount public property

Number of combined notifications

public integer $groupCount 0
$markAsSeenOnClick public property

Automatically mark notification as seen after click on it

$priority public property (available since version 1.2.3)

If set to true marks this notification type as high priority.

public boolean $priority false
$recordClass public property

Record class used for instantiation.

public string $recordClass = \humhub\modules\notification\models\Notification::class
$suppressSendToOriginator public property (available since version 1.2.3)

Do not send this notification also to the originator

See also humhub\modules\notification\components\NotificationManager.

Method Details

about() public method

Builder function for the source.

public $this about ( $source )
$source \yii\db\ActiveRecord
asArray() public method

Returns an array representation of this notification.

public void asArray ( humhub\modules\user\models\User $user )
$user
beforeMailSend() public method

This method is invoked right before a mail will be send for this notificatoin

See also humhub\modules\notification\targets\MailTarget.

public boolean beforeMailSend ( \yii\mail\MessageInterface $message )
$message \yii\mail\MessageInterface
return boolean

When true the mail will be send

category() protected method

Returns a new NotificationCategory instance.

This function should be overwritten by subclasses to append this BaseNotification to the returned category. If no category instance is returned, the BaseNotification behavriour (targets) will not be configurable.

protected humhub\modules\notification\components\NotificationCategory category ( )
delete() public method

Deletes this notification

public void delete ( humhub\modules\user\models\User $user null )
$user
from() public method

Builder function for the originator.

public humhub\components\SocialActivity from ( $originator )
$originator humhub\modules\user\models\User
getAsHtml() public method
Deprecated since version 1.2

Use html() instead

public void getAsHtml ( )
getAsText() public method
Deprecated since version 1.2

Use text() instead

public void getAsText ( )
getCategory() public method

Returns the notification category instance. If no category class is set (default) the default notification settings can't be overwritten.

The category instance is cached, once created.

If the Notification configuration should be configurable subclasses have to overwrite this method.

public humhub\modules\notification\components\NotificationCategory getCategory ( )
getGroupKey() public method

Returns a key for grouping notifications.

If null is returned (default) the notification grouping for this BaseNotification type disabled.

The returned key could for example be a combination of classname related content id.

public string getGroupKey ( )
return string

The group key

getGroupLastUsers() public method

Returns the last users of a grouped notification

public humhub\modules\user\models\User[] getGroupLastUsers ( $limit 2 )
$limit integer

Users to return

return humhub\modules\user\models\User[]

The number of user

getGroupUserDisplayNames() public method

Returns the combined display names of a grouped notification.

Examples:

 User A and User B
 User A and 5 others
public string getGroupUserDisplayNames ( )
return string

The display names

getMailSubject() public method

Returns the mail subject which will be used in the notification e-mail

See also humhub\modules\notification\targets\MailTarget.

public string getMailSubject ( )
return string

The subject

getViewParams() public method

Returns an array of view parameter, required for rendering.

public void getViewParams ( $params = [] )
$params array
html() public method

Should be overwritten by subclasses for a html representation of the notification.

public string html ( )
isOriginator() public method

Checks if the given $user is the originator of this notification.

public boolean isOriginator ( humhub\modules\user\models\User $user )
$user humhub\modules\user\models\User
markAsSeen() public method

Marks notification as seen

public void markAsSeen ( )
render() public method

Renders the Notificaiton for the given notification target.

Subclasses are able to use custom renderer for different targets by overwriting this function.

public string render ( humhub\modules\notification\targets\BaseTarget $target null )
$target humhub\modules\notification\targets\BaseTarget
return string

Render result

saveRecord() public method

Creates the Notification instance of the current BaseNotification type for the given $user.

public boolean saveRecord ( humhub\modules\user\models\User $user )
$user humhub\modules\user\models\User
send() public method

Sends this notification to all notification targets of the given User.

This function will not send notifications to the originator itself.

public void send ( humhub\modules\user\models\User $user )
$user humhub\modules\user\models\User
throws \yii\base\InvalidConfigException
sendBulk() public method

Sends this notification to a set of users.

Note: For compatibility reasons this method also allows to pass an array of user objects. This support will removed in future versions.

public void sendBulk ( $query )
$query humhub\modules\user\components\ActiveQueryUser|array|humhub\modules\user\models\User[]

The user query

throws \yii\base\InvalidConfigException