HumHub Documentation (unofficial)

NewLike extends BaseNotification
in package

Notifies a user about likes of his objects (posts, comments, tasks & co)

Tags
since
0.5

Table of Contents

Properties

$groupCount  : int
$markAsSeenOnClick  : bool
$moduleId  : mixed
$originator  : User
User which performed the activity.
$payload  : array<string|int, mixed>|null
Additional user data available for the notification
$priority  : bool
Priority flag, if set to true, this Notification type will be marked as high priority.
$record  : ActiveRecord
An SocialActivity can be represented in the database as ActiveRecord.
$record  : Notification
An SocialActivity can be represented in the database as ActiveRecord.
$recordClass  : string
$requireOriginator  : bool
$requireSource  : bool
$source  : ActiveRecord
The source instance which created this activity
$suppressSendToOriginator  : bool
$viewName  : mixed
$_category  : NotificationCategory
$_groupKey  : string

Methods

__call()  : mixed
Calls the named method which is not a class method.
__construct()  : mixed
Constructor.
__get()  : mixed
Returns the value of an object property.
__isset()  : bool
Checks if a property is set, i.e. defined and not null.
__serialize()  : array<string|int, mixed>
Serializes the $source and $originator fields.
__set()  : mixed
Sets value of an object property.
__unserialize()  : mixed
Unserializes the given string, calls the init() function and sets the $source and $originator fields (and $record indirectyl).
__unset()  : mixed
Sets an object property to null.
about()  : $this
Builder function for the source.
asArray()  : mixed
Returns an array representation of this notification.
beforeMailSend()  : bool
This method is invoked right before a mail will be send for this notificatoin
canGetProperty()  : bool
Returns a value indicating whether a property can be read.
canSetProperty()  : bool
Returns a value indicating whether a property can be set.
category()  : NotificationCategory
Returns a new NotificationCategory instance.
className()  : string
Returns the fully qualified name of this class.
delete()  : mixed
Deletes this notification
from()  : SocialActivity
Builder function for the originator.
getAsHtml()  : mixed
Use html() instead
getAsText()  : mixed
Use text() instead
getCategory()  : NotificationCategory
Returns the notification category instance. If no category class is set (default) the default notification settings can't be overwritten.
getContent()  : Content
Returns the related content instance in case the source is of type ContentOwner.
getContentContainer()  : ContentContainerActiveRecord
Determines if the activity source is related to an ContentContainer.
getContentInfo()  : string|null
Build info text about a content
getContentName()  : string|null
Returns the content name of $content or if not $content is provided of the notification source.
getContentPlainTextInfo()  : string|null
Builds plain text info text about a given content
getContentPlainTextPreview()  : string|null
Returns a short preview text of the content in plain text. The max length can be defined by setting $maxLength (60 by default).
getContentPreview()  : string|null
Returns a short preview text of the content. The max length can be defined by setting $maxLength (60 by default).
getGroupKey()  : string
Returns a key for grouping notifications.
getGroupLastUsers()  : array<string|int, User>
Returns the last users of a grouped notification
getGroupUserDisplayNames()  : string
Returns the combined display names of a grouped notification.
getLikedRecord()  : ActiveRecord
The liked record
getMailSubject()  : string
Returns a non html encoded mail subject which will be used in the notification e-mail
getSpace()  : Space
getSpaceId()  : int
getUrl()  : string
Url of the origin of this notification If source is a Content / ContentAddon / ContentContainer this will automatically generated.
getViewName()  : string
getViewParams()  : mixed
Returns an array of view parameter, required for rendering.
hasContent()  : bool
Determines if this activity is related to a content. This is the case if the activitiy source is of type ContentOwner.
hasMethod()  : bool
Returns a value indicating whether a method is defined.
hasProperty()  : bool
Returns a value indicating whether a property is defined.
html()  : string
Should be overwritten by subclasses for a html representation of the notification.
init()  : mixed
Initializes the object.
instance()  : static
Static initializer should be prefered over new initialization, since it makes use of Yii::createObject dependency injection/configuration.
isBlockedForUser()  : bool
Checks if the source is blocked for the receiver $user.
isBlockedFromUser()  : bool
Checks if the originator blocked the given $user in order to avoid receive any notifications from the $user.
isOriginator()  : bool
Checks if the given $user is the originator of this notification.
isValid()  : bool
Checks if notification is still valid before sending
json()  : string
markAsSeen()  : mixed
Marks notification as seen
payload()  : $this
Set additional data
render()  : string
Renders the Notificaiton for the given notification target.
saveRecord()  : bool
Creates the Notification instance of the current BaseNotification type for the given $user.
send()  : mixed
Sends this notification to all notification targets of the given User.
sendBulk()  : mixed
Sends this notification to a set of users.
text()  : string
validate()  : bool
Validates the existence of required attributes
isSpaceContent()  : bool
Check if the source is a Content from a Space

Properties

$markAsSeenOnClick

public bool $markAsSeenOnClick = true

automatically mark notification as seen after click on it

$moduleId

public mixed $moduleId = 'like'
Tags
inheritdoc

$payload

Additional user data available for the notification

public array<string|int, mixed>|null $payload = null
Tags
since
1.11

$priority

Priority flag, if set to true, this Notification type will be marked as high priority.

public bool $priority = false

This can be used by a given BaseTarget while handling a Notification.

A MobileTargetProvider for example could use this flag for Android devices to wake up the device out of doze mode.

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

Tags
since
1.2.3

$record

An SocialActivity can be represented in the database as ActiveRecord.

public ActiveRecord $record

By defining the $recordClass an ActiveRecord will be created automatically within the init function.

The related record for this activitiy

$record

An SocialActivity can be represented in the database as ActiveRecord.

public Notification $record

The related record for this activitiy

$recordClass

public string $recordClass = \humhub\modules\notification\models\Notification::class

Record class used for instantiation.

Tags
inheritdoc

$requireOriginator

public bool $requireOriginator = true

ensure originator existence

Tags
since
1.3

$requireSource

public bool $requireSource = true

ensure source existence

Tags
since
1.3

$viewName

public mixed $viewName = 'newLike'
Tags
inheritdoc

Methods

__call()

Calls the named method which is not a class method.

public __call(string $name, array<string|int, mixed> $params) : mixed

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

Parameters
$name : string

the method name

$params : array<string|int, mixed>

method parameters

Tags
throws
UnknownMethodException

when calling unknown method

Return values
mixed

the method return value

__construct()

Constructor.

public __construct([array<string|int, mixed> $config = [] ]) : mixed

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call [[init()]].

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
Parameters
$config : array<string|int, mixed> = []

name-value pairs that will be used to initialize the object properties

__get()

Returns the value of an object property.

public __get(string $name) : mixed

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;.

Parameters
$name : string

the property name

Tags
throws
UnknownPropertyException

if the property is not defined

throws
InvalidCallException

if the property is write-only

see
__set()
Return values
mixed

the property value

__isset()

Checks if a property is set, i.e. defined and not null.

public __isset(string $name) : bool

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($object->property).

Note that if the property is not defined, false will be returned.

Parameters
$name : string

the property name or the event name

Tags
see
https://www.php.net/manual/en/function.isset.php
Return values
bool

whether the named property is set (not null).

__set()

Sets value of an object property.

public __set(string $name, mixed $value) : mixed

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;.

Parameters
$name : string

the property name or the event name

$value : mixed

the property value

Tags
throws
UnknownPropertyException

if the property is not defined

throws
InvalidCallException

if the property is read-only

see
__get()

__unserialize()

Unserializes the given string, calls the init() function and sets the $source and $originator fields (and $record indirectyl).

public __unserialize(mixed $unserializedArr) : mixed
Parameters
$unserializedArr : mixed
Tags
link
http://php.net/manual/en/function.unserialize.php
see
ActiveRecord::unserialize()

for the serialization of your $source

__unset()

Sets an object property to null.

public __unset(string $name) : mixed

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property).

Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.

Parameters
$name : string

the property name

Tags
throws
InvalidCallException

if the property is read only.

see
https://www.php.net/manual/en/function.unset.php

about()

Builder function for the source.

public about(mixed $source) : $this
Parameters
$source : mixed
Tags
inheritdoc
Return values
$this

asArray()

Returns an array representation of this notification.

public asArray(User $user) : mixed
Parameters
$user : User
Tags
inheritdoc

canGetProperty()

Returns a value indicating whether a property can be read.

public canGetProperty(string $name[, bool $checkVars = true ]) : bool

A property is readable if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

Tags
see
canSetProperty()
Return values
bool

whether the property can be read

canSetProperty()

Returns a value indicating whether a property can be set.

public canSetProperty(string $name[, bool $checkVars = true ]) : bool

A property is writable if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

Tags
see
canGetProperty()
Return values
bool

whether the property can be written

className()

Returns the fully qualified name of this class.

public static className() : string
Tags
deprecated

since 2.0.14. On PHP >=5.5, use ::class instead.

Return values
string

the fully qualified name of this class.

getAsHtml()

Use html() instead

public getAsHtml() : mixed
Tags
deprecated

since version 1.2

getAsText()

Use text() instead

public getAsText() : mixed
Tags
deprecated

since version 1.2

getCategory()

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

public getCategory() : NotificationCategory

The category instance is cached, once created.

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

Return values
NotificationCategory

getContent()

Returns the related content instance in case the source is of type ContentOwner.

public getContent() : Content
Return values
Content

Content ActiveRecord or null if not related to a ContentOwner source

getContentInfo()

Build info text about a content

public getContentInfo([Content $content = null ][, mixed $withContentName = true ]) : string|null

This is a combination of the type of the content with a short preview of it.

If no $content is provided the contentInfo of $source is returned.

Parameters
$content : Content = null
$withContentName : mixed = true
Tags
throws
Exception
Return values
string|null

getContentName()

Returns the content name of $content or if not $content is provided of the notification source.

public getContentName([ContentOwner $content = null ]) : string|null
Parameters
$content : ContentOwner = null
Return values
string|null

getContentPlainTextInfo()

Builds plain text info text about a given content

public getContentPlainTextInfo([Content $content = null ][, mixed $withContentName = true ]) : string|null

This is a combination of the type of the content with a short preview of it.

Note: This should only be used for mail subjects and other plain text

If no $content is provided the contentInfo of $source is returned.

Parameters
$content : Content = null
$withContentName : mixed = true
Tags
throws
Exception
since
1.4
Return values
string|null

getContentPlainTextPreview()

Returns a short preview text of the content in plain text. The max length can be defined by setting $maxLength (60 by default).

public getContentPlainTextPreview([ContentOwner $content = null ][, int $maxLength = 60 ]) : string|null

If no $content is provided the contentPreview of $source is returned.

Note: This should only be used for mail subjects and other plain text

Parameters
$content : ContentOwner = null
$maxLength : int = 60
Tags
throws
Exception
since
1.4
Return values
string|null

getContentPreview()

Returns a short preview text of the content. The max length can be defined by setting $maxLength (60 by default).

public getContentPreview([ContentOwner $content = null ][, int $maxLength = 60 ]) : string|null

If no $content is provided the contentPreview of $source is returned.

Parameters
$content : ContentOwner = null
$maxLength : int = 60
Tags
throws
Exception
Return values
string|null

getGroupKey()

Returns a key for grouping notifications.

public getGroupKey() : string
Tags
inheritdoc
Return values
string

the group key

getGroupLastUsers()

Returns the last users of a grouped notification

public getGroupLastUsers([int $limit = 2 ]) : array<string|int, User>
Parameters
$limit : int = 2

users to return

Return values
array<string|int, User>

the number of user

getGroupUserDisplayNames()

Returns the combined display names of a grouped notification.

public getGroupUserDisplayNames([bool $html = true ]) : string

Examples: User A and User B User A and 5 others

Parameters
$html : bool = true

if true the result will be encoded and may contain html

Return values
string

the display names

getMailSubject()

Returns a non html encoded mail subject which will be used in the notification e-mail

public getMailSubject() : string
Tags
inheritdoc
Return values
string

the subject

getSpace()

public getSpace() : Space
Tags
throws
Exception
Return values
Space

related space instance in case the activity source is an related contentcontainer of type space, otherwise null

getSpaceId()

public getSpaceId() : int
Tags
throws
Exception
Return values
int

related space id in case the activity source is an related contentcontainer of type space, otherwise null

getUrl()

Url of the origin of this notification If source is a Content / ContentAddon / ContentContainer this will automatically generated.

public getUrl() : string

NOTE: Returned URL must be absolute with scheme

Return values
string

getViewName()

public getViewName() : string
Tags
inheritdoc
Return values
string

viewname of this viewable

getViewParams()

Returns an array of view parameter, required for rendering.

public getViewParams([mixed $params = [] ]) : mixed
Parameters
$params : mixed = []
Tags
inheritdoc

hasContent()

Determines if this activity is related to a content. This is the case if the activitiy source is of type ContentOwner.

public hasContent() : bool
Return values
bool

true if this activity is related to a ContentOwner else false

hasMethod()

Returns a value indicating whether a method is defined.

public hasMethod(string $name) : bool

The default implementation is a call to php function method_exists(). You may override this method when you implemented the php magic method __call().

Parameters
$name : string

the method name

Return values
bool

whether the method is defined

hasProperty()

Returns a value indicating whether a property is defined.

public hasProperty(string $name[, bool $checkVars = true ]) : bool

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

Tags
see
canGetProperty()
see
canSetProperty()
Return values
bool

whether the property is defined

html()

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

public html() : string
Tags
inheritdoc
Return values
string

init()

Initializes the object.

public init() : mixed
Tags
inheritdoc

instance()

Static initializer should be prefered over new initialization, since it makes use of Yii::createObject dependency injection/configuration.

public static instance([array<string|int, mixed> $options = [] ]) : static
Parameters
$options : array<string|int, mixed> = []
Tags
throws
InvalidConfigException
Return values
static

isBlockedForUser()

Checks if the source is blocked for the receiver $user.

public isBlockedForUser(User $user) : bool

For example, if the $user is not a member of a private Space

Parameters
$user : User
Tags
since
1.11.2
Return values
bool

isBlockedFromUser()

Checks if the originator blocked the given $user in order to avoid receive any notifications from the $user.

public isBlockedFromUser(User $user) : bool
Parameters
$user : User
Tags
since
1.10
Return values
bool

isOriginator()

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

public isOriginator(User $user) : bool
Parameters
$user : User
Return values
bool

isValid()

Checks if notification is still valid before sending

public isValid() : bool
Tags
since
1.15
Return values
bool

json()

public json() : string
Tags
inheritdoc
Return values
string

json content representation of this viewable.

payload()

Set additional data

public payload(mixed $payload) : $this
Parameters
$payload : mixed
Tags
since
1.11
Return values
$this

render()

Renders the Notificaiton for the given notification target.

public render([BaseTarget $target = null ]) : string

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

Parameters
$target : BaseTarget = null
Return values
string

render result

saveRecord()

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

public saveRecord(User $user) : bool
Parameters
$user : User
Return values
bool

send()

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

public send(User $user) : mixed

This function will not send notifications to the originator itself.

Parameters
$user : User
Tags
throws
InvalidConfigException

sendBulk()

Sends this notification to a set of users.

public sendBulk(ActiveQueryUser|array<string|int, mixed>|array<string|int, User$query) : mixed

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

Parameters
$query : ActiveQueryUser|array<string|int, mixed>|array<string|int, User>

the user query

Tags
throws
InvalidConfigException

text()

public text() : string
Tags
inheritdoc
Return values
string

text content representation of this viewable.

validate()

Validates the existence of required attributes

public validate() : bool
Return values
bool

isSpaceContent()

Check if the source is a Content from a Space

private isSpaceContent() : bool
Tags
since
1.11.2
Return values
bool

        
On this page

Search results