Class humhub\modules\content\components\ContentActiveRecord
Inheritance | humhub\modules\content\components\ContentActiveRecord » humhub\components\ActiveRecord » yii\db\ActiveRecord |
---|---|
Implements | Serializable, humhub\modules\content\interfaces\ContentOwner, humhub\modules\content\models\Movable |
Subclasses | humhub\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.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$autoFollow | boolean | Should the originator automatically follows this content when saved. | humhub\modules\content\components\ContentActiveRecord |
$silentContentCreation | boolean | humhub\modules\content\components\ContentActiveRecord | |
$wallEntryClass | string | The WallEntry widget class | humhub\modules\content\components\ContentActiveRecord |
Protected Properties
Property | Type | Description | Defined 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
Property Details
Should the originator automatically follows this content when saved.
Defines if the Movable behaviour of this ContentContainerActiveRecord type is active.
Used to cache the content relation in order to avoid the relation to be overwritten in the insert process
Permission instance
Related moduleId
The stream channel
The WallEntry widget class
See also humhub\modules\content\widgets\WallEntry.
Method Details
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 |
---|
public void __get ( $name ) | ||
$name |
public void afterDelete ( ) |
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 |
public void afterSave ( $insert, $changedAttributes ) | ||
$insert | ||
$changedAttributes |
public void beforeSave ( $insert ) | ||
$insert |
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 |
Returns an ActiveQueryContent to find content.
{@inheritdoc}
public static humhub\modules\content\components\ActiveQueryContent find ( ) |
Related Content model
public \yii\db\ActiveQuery|humhub\modules\content\components\ActiveQueryContent getContent ( ) |
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 |
---|
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 |
---|
Can be used to define an icon for this content type e.g.: 'fa-calendar'.
public string getIcon ( ) |
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 |
---|
Returns the $managePermission settings interpretable by an PermissionManager instance.
See also humhub\modules\content\components\ContentActiveRecord::$managePermission.
public null|object|string getManagePermission ( ) |
Returns the id of the module related to this content type Note: This may not be implemented by some legacy modules
public void getModuleId ( ) |
public static void getObjectModel ( ) |
public humhub\modules\user\models\User getOwner ( ) | ||
return | humhub\modules\user\models\User | The owner of this content record |
---|
Returns an instance of the assigned wall entry widget instance. This can be used to check matadata fields of the related widget.
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 |
---|
Returns the wall output widget of this content.
public string getWallOut ( $params = [] ) | ||
$params | array | Optional parameters for WallEntryWidget |
throws | Exception |
---|
Determines weather or not this records has an additional managePermission set.
public boolean hasManagePermission ( ) |
public void init ( ) |
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 |
---|
{@inheritdoc}
public void move ( humhub\modules\content\components\ContentContainerActiveRecord $container = null, $force = false ) | ||
$container | ||
$force |