Class humhub\modules\content\components\ContentActiveRecord

Inheritancehumhub\modules\content\components\ContentActiveRecord » humhub\components\ActiveRecord » yii\db\ActiveRecord
ImplementsSerializable, humhub\modules\content\interfaces\ContentOwner, humhub\modules\content\models\Movable
Subclasseshumhub\modules\activity\models\Activity, humhub\modules\post\models\Post

ContentActiveRecord is the base ActiveRecord \yii\db\ActiveRecord for Content.

Each instance automatically belongs to a humhub\modules\content\models\Content record which is accessible via the content attribute. This relations will be automatically added/updated and is also available before this record is inserted.

The Content record/model holds all neccessary informations/methods like:

  • Related ContentContainer (must be set before save!)
  • Visibility
  • Meta information (created_at, created_by, ...)
  • Wall handling, archiving, pinning, ...

Before adding a new ContentActiveRecord instance, you need at least assign an ContentContainer.

Example:

$post = new Post();
$post->content->container = $space;
$post->content->visibility = Content::VISIBILITY_PRIVATE; // optional
$post->message = "Hello world!";
$post->save();

Note: If the underlying Content record cannot be saved or validated an Exception will thrown.

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$canMove boolean Defines if the Movable behaviour of this ContentContainerActiveRecord type is active. humhub\modules\content\components\ContentActiveRecord
$initContent humhub\modules\content\models\Content Used to cache the content relation in order to avoid the relation to be overwritten in the insert process humhub\modules\content\components\ContentActiveRecord
$managePermission string Permission instance humhub\modules\content\components\ContentActiveRecord
$moduleId string Related moduleId humhub\modules\content\components\ContentActiveRecord
$streamChannel string|null The stream channel humhub\modules\content\components\ContentActiveRecord

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() ContentActiveRecord constructor accepts either an configuration array as first argument or an ContentContainerActiveRecord and visibility settings. humhub\modules\content\components\ContentActiveRecord
__get() humhub\modules\content\components\ContentActiveRecord
afterDelete() humhub\modules\content\components\ContentActiveRecord
afterMove() This function can be overwritten in order to define model specific logic as moving sub-content or other related humhub\modules\content\components\ContentActiveRecord
afterSave() humhub\modules\content\components\ContentActiveRecord
beforeSave() humhub\modules\content\components\ContentActiveRecord
canMove() Can be overwritten to define additional model specific checks. humhub\modules\content\components\ContentActiveRecord
find() Returns an ActiveQueryContent to find content. humhub\modules\content\components\ContentActiveRecord
getContent() Related Content model humhub\modules\content\components\ContentActiveRecord
getContentDescription() Returns a description of this particular content. humhub\modules\content\components\ContentActiveRecord
getContentName() Returns the name of this type of content. humhub\modules\content\components\ContentActiveRecord
getCreatedBy() Relation to User defined in created_by attribute humhub\components\ActiveRecord
getErrorMessage() Returns the errors as string for all attribute or a single attribute. humhub\components\ActiveRecord
getFileManager() Returns the file manager for this record humhub\components\ActiveRecord
getIcon() Can be used to define an icon for this content type e.g.: 'fa-calendar'. humhub\modules\content\components\ContentActiveRecord
getLabels() Returns either Label widget instances or strings. humhub\modules\content\components\ContentActiveRecord
getManagePermission() Returns the $managePermission settings interpretable by an PermissionManager instance. humhub\modules\content\components\ContentActiveRecord
getModuleId() Returns the id of the module related to this content type Note: This may not be implemented by some legacy modules humhub\modules\content\components\ContentActiveRecord
getObjectModel() humhub\modules\content\components\ContentActiveRecord
getOwner() humhub\modules\content\components\ContentActiveRecord
getUniqueId() Returns a unique id for this record/model humhub\components\ActiveRecord
getUpdatedBy() Relation to User defined in updated_by attribute humhub\components\ActiveRecord
getWallEntryWidget() Returns the assigned wall entry widget instance humhub\modules\content\components\ContentActiveRecord
getWallOut() Returns the wall output widget of this content. humhub\modules\content\components\ContentActiveRecord
hasManagePermission() Determines weather or not this records has an additional managePermission set. humhub\modules\content\components\ContentActiveRecord
init() humhub\modules\content\components\ContentActiveRecord
isOwner() Checks if the given user or the current logged in user if no user was given, is the owner of this content humhub\modules\content\components\ContentActiveRecord
move() {@inheritdoc} humhub\modules\content\components\ContentActiveRecord
serialize() Serializes attributes and oldAttributes of this record. humhub\components\ActiveRecord
unserialize() Unserializes the given string, calls the init() function and sets the attributes and oldAttributes. humhub\components\ActiveRecord

Property Details

$autoFollow public property

Should the originator automatically follows this content when saved.

public boolean $autoFollow true
$canMove protected property (available since version 1.3)

Defines if the Movable behaviour of this ContentContainerActiveRecord type is active.

See also humhub\modules\content\models\Content::move().

protected boolean $canMove false
$initContent protected property (available since version 1.3)

Used to cache the content relation in order to avoid the relation to be overwritten in the insert process

See also https://github.com/humhub/humhub/issues/3110.

$managePermission protected property (available since version 1.2.1)

Permission instance

protected string $managePermission = \humhub\modules\content\permissions\ManageContent::class
$moduleId protected property (available since version 1.3)

Related moduleId

protected string $moduleId null
$silentContentCreation public property (available since version 1.2.3)
$streamChannel protected property (available since version 1.2)

The stream channel

protected string|null $streamChannel 'default'
$wallEntryClass public property

The WallEntry widget class

See also humhub\modules\content\widgets\WallEntry.

public string $wallEntryClass ""

Method Details

__construct() public method

ContentActiveRecord constructor accepts either an configuration array as first argument or an ContentContainerActiveRecord and visibility settings.

Use as follows:

$model = new MyContent(['myField' => 'value']);

or

$model = new MyContent($space1, Content::VISIBILITY_PUBLIC, ['myField' => 'value']);

or

$model = new MyContent($space1, ['myField' => 'value']);

public void __construct ( $contentContainer = [], $visibility null, $config = [] )
$contentContainer array|humhub\modules\content\components\ContentContainerActiveRecord

Either the configuration or contentcontainer

$visibility integer|array
$config array
throws \yii\base\Exception
__get() public method

public void __get ( $name )
$name
afterDelete() public method

public void afterDelete ( )
afterMove() public method

This function can be overwritten in order to define model specific logic as moving sub-content or other related

public void afterMove ( humhub\modules\content\components\ContentContainerActiveRecord $container null )
$container humhub\modules\content\components\ContentContainerActiveRecord|null
afterSave() public method

public void afterSave ( $insert, $changedAttributes )
$insert
$changedAttributes
beforeSave() public method

public void beforeSave ( $insert )
$insert
canMove() public method

Can be overwritten to define additional model specific checks.

This function should also validate all existing sub-content entries to prevent data inconsistency.

Note: Default checks for the underlying content are automatically handled within the humhub\modules\content\models\Content::canMove()

public boolean|string canMove ( humhub\modules\content\components\ContentContainerActiveRecord $container null )
$container humhub\modules\content\components\ContentContainerActiveRecord|null
find() public static method

Returns an ActiveQueryContent to find content.

{@inheritdoc}

public static humhub\modules\content\components\ActiveQueryContent find ( )
getContent() public method

Related Content model

public \yii\db\ActiveQuery|humhub\modules\content\components\ActiveQueryContent getContent ( )
getContentDescription() public method

Returns a description of this particular content.

This will be used to create a text preview of the content record. (e.g. in Activities or Notifications) You need to override this method in your content implementation.

public string getContentDescription ( )
return string

Description of this content

getContentName() public method

Returns the name of this type of content.

You need to override this method in your content implementation.

public string getContentName ( )
return string

The name of the content

getIcon() public method

Can be used to define an icon for this content type e.g.: 'fa-calendar'.

public string getIcon ( )
getLabels() public method

Returns either Label widget instances or strings.

Subclasses should call paren::getLabels() as follows:

public function getLabels($labels = [], $includeContentName = true)
{
   return parent::getLabels([Label::info('someText')->sortOrder(5)]);
}
public humhub\widgets\Label[]|\string[] getLabels ( $labels = [], $includeContentName true )
$labels array
$includeContentName boolean
return humhub\widgets\Label[]|\string[]

Content labels used for example in wallentrywidget

getManagePermission() public method (available since version 1.2.1)

Returns the $managePermission settings interpretable by an PermissionManager instance.

See also humhub\modules\content\components\ContentActiveRecord::$managePermission.

public null|object|string getManagePermission ( )
getModuleId() public method (available since version 1.3)

Returns the id of the module related to this content type Note: This may not be implemented by some legacy modules

public void getModuleId ( )
getObjectModel() public static method

public static void getObjectModel ( )
getOwner() public method

public humhub\modules\user\models\User getOwner ( )
return humhub\modules\user\models\User

The owner of this content record

getWallEntryWidget() public method

Returns the assigned wall entry widget instance

public null|humhub\modules\content\widgets\WallEntry getWallEntryWidget ( )
return null|humhub\modules\content\widgets\WallEntry

For this class by wallEntryClass property , null will be returned if this wallEntryClass is empty

getWallOut() public method

Returns the wall output widget of this content.

public string getWallOut ( $params = [] )
$params array

Optional parameters for WallEntryWidget

throws Exception
hasManagePermission() public method (available since version 1.2.1)

Determines weather or not this records has an additional managePermission set.

public boolean hasManagePermission ( )
init() public method

public void init ( )
isOwner() public method (available since version 1.3)

Checks if the given user or the current logged in user if no user was given, is the owner of this content

public boolean isOwner ( $user null )
$user null
throws Throwable
move() public method

{@inheritdoc}

public void move ( humhub\modules\content\components\ContentContainerActiveRecord $container null, $force false )
$container
$force