Abstract Class humhub\components\SocialActivity

Inheritancehumhub\components\SocialActivity » yii\base\BaseObject
ImplementsSerializable, humhub\components\rendering\Viewable
Subclasseshumhub\modules\activity\components\BaseActivity, humhub\modules\admin\notifications\ExcludeGroupNotification, humhub\modules\admin\notifications\IncludeGroupNotification, humhub\modules\admin\notifications\NewVersionAvailable, humhub\modules\comment\activities\NewComment, humhub\modules\comment\notifications\NewComment, humhub\modules\content\activities\ContentCreated, humhub\modules\content\notifications\ContentCreated, humhub\modules\friendship\notifications\Request, humhub\modules\friendship\notifications\RequestApproved, humhub\modules\friendship\notifications\RequestDeclined, humhub\modules\like\activities\Liked, humhub\modules\like\notifications\NewLike, humhub\modules\notification\components\BaseNotification, humhub\modules\space\activities\Created, humhub\modules\space\activities\MemberAdded, humhub\modules\space\activities\MemberRemoved, humhub\modules\space\activities\SpaceArchived, humhub\modules\space\activities\SpaceUnArchived, 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\activities\UserFollow, humhub\modules\user\notifications\Followed, humhub\modules\user\notifications\Mentioned
Available since version1.1

This class represents a social Activity triggered within the network.

A SocialActivity can be assigned with an originator User, which triggered the activity and a source ActiveRecord. The source is used to connect the SocialActivity to a related Content, ContentContainerActiveRecord or any other ActiveRecord.

Since SocialActivities need to be rendered in most cases it implements the humhub\components\rendering\Viewable interface and provides a default implementation of the getViewParams function.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$moduleId string The module id which this activity belongs to (required) humhub\components\SocialActivity
$originator humhub\modules\user\models\User humhub\components\SocialActivity
$record \yii\db\ActiveRecord The related record for this activitiy humhub\components\SocialActivity
$recordClass string Record class used for instantiation. humhub\components\SocialActivity
$requireOriginator boolean Ensure originator existence humhub\components\SocialActivity
$requireSource boolean Ensure source existence humhub\components\SocialActivity
$source \yii\db\ActiveRecord humhub\components\SocialActivity
$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\components\SocialActivity
asArray() Returns an array representation of this notification. humhub\components\SocialActivity
from() Builder function for the originator. humhub\components\SocialActivity
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
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\SocialActivity
getViewParams() Returns an array of view parameter, required for rendering. humhub\components\SocialActivity
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() humhub\components\SocialActivity
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
json() humhub\components\SocialActivity
serialize() Serializes the $source and $originator fields. humhub\components\SocialActivity
text() humhub\components\SocialActivity
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

Property Details

$moduleId public property

The module id which this activity belongs to (required)

public string $moduleId null
$originator public property
$record public property

The related record for this activitiy

public \yii\db\ActiveRecord $record null
$recordClass public property

Record class used for instantiation.

public string $recordClass null
$requireOriginator public property (available since version 1.3)

Ensure originator existence

$requireSource public property (available since version 1.3)

Ensure source existence

public boolean $requireSource true
$source public property
public \yii\db\ActiveRecord $source null
$viewName public property

View name used for rendering the activity

public string $viewName 'default.php'

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
from() public method

Builder function for the originator.

public humhub\components\SocialActivity from ( $originator )
$originator humhub\modules\user\models\User
getContent() public method

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

public humhub\modules\content\models\Content getContent ( )
return humhub\modules\content\models\Content

Content ActiveRecord or null if not related to a ContentOwner source

getContentContainer() public method

Determines if the activity source is related to an ContentContainer.

This is the case if the source is either a ContentContainerActiveRecord itself or a ContentOwner.

public humhub\modules\content\components\ContentContainerActiveRecord getContentContainer ( )
getContentInfo() public method

Build info text about a content

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

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

public string|null getContentInfo ( humhub\modules\content\interfaces\ContentOwner $content null, $withContentName true )
$content humhub\modules\content\models\Content
$withContentName
getContentName() public method

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

public string|null getContentName ( humhub\modules\content\interfaces\ContentOwner $content null )
$content humhub\modules\content\interfaces\ContentOwner
getContentPreview() public method

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

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

public string|null getContentPreview ( humhub\modules\content\interfaces\ContentOwner $content null, $maxLength 25 )
$content humhub\modules\content\interfaces\ContentOwner
$maxLength integer
throws Exception
getSpace() public method

public humhub\modules\space\models\Space getSpace ( )
return humhub\modules\space\models\Space

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

getSpaceId() public method

public integer getSpaceId ( )
return integer

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

getUrl() public method

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

public string getUrl ( )
getViewName() public method

public string getViewName ( )
return string

Viewname of this viewable

getViewParams() public method

Returns an array of view parameter, required for rendering.

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

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

public boolean hasContent ( )
return boolean

True if this activity is related to a ContentOwner else false

html() public method

public string html ( )
return string

Html content representation of this viewable.

init() public method

public void init ( )
instance() public static method

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

public static static instance ( $options = [] )
$options array
throws \yii\base\InvalidConfigException
json() public method

public string json ( )
return string

Json content representation of this viewable.

serialize() public method (available since version 1.2)

Serializes the $source and $originator fields.

See also humhub\components\ActiveRecord::serialize() for the serialization of your $source.

public string serialize ( )
text() public method

public string text ( )
return string

Text content representation of this viewable.

unserialize() public method

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

See also humhub\components\ActiveRecord::unserialize() for the serialization of your $source.

public void unserialize ( $serialized )
$serialized string
validate() public method

Validates the existence of required attributes

public boolean validate ( )