Class humhub\modules\content\models\ContentTag

Inheritancehumhub\modules\content\models\ContentTag » humhub\components\ActiveRecord » yii\db\ActiveRecord
ImplementsSerializable
Subclasseshumhub\modules\topic\models\Topic
Available since version1.2.2

ContentTags are a concept to categorize content on module and ContentContainer level.

By means of ContentTags a module is able to create own category concepts as for example event types (calendar) or task related tags, in which the module itself is responsible for managing and the usage of it's tags.

Module implementing own an own category concept should extend the ContentTag class as follows:

class MyModuleCategory extends ContentTag
{
  public $moduleId = 'myModule';

  public static getLabel()
 {
    return 'MyCategory'
 }

All MyModuleCategory will be assigned with the given $moduleId as $module_id and the class name as $type. Calls to MyModuleCategory::find() will always include $module_id filters, the same goes for other query methods as findByCotnainer etc.

If a subclass sets $includeTypeQuery to true queries will also include a $type filter. This is required if a module provides more than one tag type.

If you require to select untyped tags use ContentTag::find() instead.

If the contentcontainer_id of a given ContentTag is null, the ContentTag is meant to be module global and therefore not bound to a ContentContainer instance.

In some cases a ContentTag has to be related with some further settigns, this can be achieved by extending the ContentTagAddition class and setting the ContentTags $additioNClass.

An instance of this class will automatically be created by calling $tag->addition

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$additionClass string Class of ContentTagAddition (optional), if set a call to $tag->addition will create an empty addition instance, the addition will also be validated and saved in the tag save process. humhub\modules\content\models\ContentTag
$includeTypeQuery boolean If set to true the default search queries will include a type condition beside the module condition, this is only required if one module provides multiple content tag concepts. humhub\modules\content\models\ContentTag
$moduleId string Id of the module related to this content tag concept humhub\modules\content\models\ContentTag

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() ContentTag constructor. humhub\modules\content\models\ContentTag
__get() humhub\modules\content\models\ContentTag
addQueryCondition() Adds content tag related fitler conditions to a given query. humhub\modules\content\models\ContentTag
afterSave() humhub\modules\content\models\ContentTag
beforeSave() humhub\components\ActiveRecord
deleteAll() In case this function is not called on the base ContentTag function, it will ensure to that at least either a 'module_id' or 'type' condition is given to prevent deleting all content tags. humhub\modules\content\models\ContentTag
deleteByModule() Deletes all tags by module id humhub\modules\content\models\ContentTag
deleteByType() Deletes all tags by type humhub\modules\content\models\ContentTag
deleteContentRelations() Deletes all tag relations of the given type for the given $content. humhub\modules\content\models\ContentTag
find() Finds instances and filters by module_id if a static module_id is given. humhub\modules\content\models\ContentTag
findAll() Searches for all content tags of this type. humhub\modules\content\models\ContentTag
findByContainer() Finds instances by ContentContainerActiveRecord and optional type. humhub\modules\content\models\ContentTag
findByContent() Returns Content related tags. humhub\modules\content\models\ContentTag
findByModule() Finds ContentTag for the given $moduleId humhub\modules\content\models\ContentTag
findByName() Finds instances by given name and optionally by contentContainer. humhub\modules\content\models\ContentTag
findByType() Finds instances by given $type. humhub\modules\content\models\ContentTag
findGlobal() Finds all global content tags of this type. humhub\modules\content\models\ContentTag
findOne() Find a single instances either by providing an id or other condition. humhub\modules\content\models\ContentTag
getAddition() humhub\modules\content\models\ContentTag
getContainer() Returns the actual Container (Space/User) related to this tag or null if this is a global tag. humhub\modules\content\models\ContentTag
getContentContainer() Returns the ContentContainer relation as ActiveQuery to this tag or null if this is a global tag. humhub\modules\content\models\ContentTag
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
getLabel() humhub\modules\content\models\ContentTag
getParent() Returns the parent tag relation. humhub\modules\content\models\ContentTag
getTagContentRelations() Returns all tag relations of the given type for the given $content. humhub\modules\content\models\ContentTag
getUniqueId() Returns a unique id for this record/model humhub\components\ActiveRecord
getUpdatedBy() Relation to User defined in updated_by attribute humhub\components\ActiveRecord
getUrl() humhub\modules\content\models\ContentTag
hasAddition() humhub\modules\content\models\ContentTag
init() Sets the module_id as and type. humhub\modules\content\models\ContentTag
is() Checks if this content tag is of the given $type. humhub\modules\content\models\ContentTag
load() humhub\modules\content\models\ContentTag
moduleQuery() Adds an module id filter query to the given $query instance in case a subclass has set the $moduleId. humhub\modules\content\models\ContentTag
rules() humhub\modules\content\models\ContentTag
serialize() Serializes attributes and oldAttributes of this record. humhub\components\ActiveRecord
setAddition() Sets a ContentTagAddition for this instance, note you'll have to call $tag->save() manually humhub\modules\content\models\ContentTag
tableName() humhub\modules\content\models\ContentTag
typeQuery() Adds an type filter query to the given $query instance in case $includeTypeQuery of the subclass is set to true and the calling class is not ContentTag class itself. humhub\modules\content\models\ContentTag
unserialize() Unserializes the given string, calls the init() function and sets the attributes and oldAttributes. humhub\components\ActiveRecord
validate() humhub\modules\content\models\ContentTag
validateUnique() Validates humhub\modules\content\models\ContentTag

Property Details

$additionClass public property

Class of ContentTagAddition (optional), if set a call to $tag->addition will create an empty addition instance, the addition will also be validated and saved in the tag save process.

public string $additionClass null
$includeTypeQuery public property

If set to true the default search queries will include a type condition beside the module condition, this is only required if one module provides multiple content tag concepts.

public boolean $includeTypeQuery false
$moduleId public property

Id of the module related to this content tag concept

public string $moduleId null

Method Details

__construct() public method

ContentTag constructor.

Can be called either with a yii contfig array or with contentcontainer and name.

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

public void __get ( $name )
$name
addQueryCondition() public static method (available since version 1.3)

Adds content tag related fitler conditions to a given query.

public static \yii\db\ActiveQuery addQueryCondition ( \yii\db\ActiveQuery $query )
$query \yii\db\ActiveQuery
afterSave() public method

public void afterSave ( $insert, $changedAttributes )
$insert
$changedAttributes
deleteAll() public static method (available since version 1.3.2)

In case this function is not called on the base ContentTag function, it will ensure to that at least either a 'module_id' or 'type' condition is given to prevent deleting all content tags.

If no 'module_id' or 'type' condition is given this function will automatically add a 'type' condition.

public static void deleteAll ( $condition null, $params = [] )
$condition
$params
deleteByModule() public static method

Deletes all tags by module id

public static integer deleteByModule ( $contentContainer null )
$contentContainer humhub\modules\content\components\ContentContainerActiveRecord|integer
return integer

The number of rows deleted

deleteByType() public static method

Deletes all tags by type

public static integer deleteByType ( $contentContainer null )
$contentContainer humhub\modules\content\components\ContentContainerActiveRecord|integer
return integer

The number of rows deleted

deleteContentRelations() public static method

Deletes all tag relations of the given type for the given $content.

public static void deleteContentRelations ( humhub\modules\content\models\Content $content, $includeGlobal true )
$content humhub\modules\content\models\Content
$includeGlobal
find() public static method

Finds instances and filters by module_id if a static module_id is given.

public static \yii\db\ActiveQuery find ( )
findAll() public static method (available since version 1.3.2)

Searches for all content tags of this type.

public static humhub\components\ActiveRecord[] findAll ( $condition )
$condition
findByContainer() public static method

Finds instances by ContentContainerActiveRecord and optional type.

If $includeGlobal is set to true the query will also include global content tags of this type.

public static \yii\db\ActiveQuery findByContainer ( $container, $includeGlobal false )
$container

ContentContainerActiveRecord|int

$includeGlobal boolean

If true the query will include global tags as well @since 1.2.3

findByContent() public static method

Returns Content related tags.

public static \yii\db\ActiveQuery findByContent ( humhub\modules\content\models\Content $content )
$content humhub\modules\content\models\Content
findByModule() public static method

Finds ContentTag for the given $moduleId

public static \yii\db\ActiveQuery findByModule ( $moduleId )
$moduleId
findByName() public static method

Finds instances by given name and optionally by contentContainer.

public static \yii\db\ActiveQuery findByName ( $name, $contentContainer null )
$name
$contentContainer humhub\modules\content\components\ContentContainerActiveRecord|integer|null
findByType() public static method

Finds instances by given $type.

public static \yii\db\ActiveQuery findByType ( $type )
$type string
findGlobal() public static method

Finds all global content tags of this type.

public static \yii\db\ActiveQuery findGlobal ( )
findOne() public static method

Find a single instances either by providing an id or other condition.

public static static findOne ( $condition )
$condition
getAddition() public method

public humhub\components\ActiveRecord|\yii\db\ActiveQuery getAddition ( )
getContainer() public method

Returns the actual Container (Space/User) related to this tag or null if this is a global tag.

This function will cache the container instance once loaded.

public null|humhub\modules\content\components\ContentContainerActiveRecord getContainer ( )
throws \yii\db\IntegrityException
getContentContainer() public method

Returns the ContentContainer relation as ActiveQuery to this tag or null if this is a global tag.

Note: In order to retrieve the actual Container (Space/User) use getContainer().

public \yii\db\ActiveQuery getContentContainer ( )
getLabel() public static method

public static void getLabel ( )
getParent() public method

Returns the parent tag relation.

public \yii\db\ActiveQuery getParent ( )
getTagContentRelations() public static method

Returns all tag relations of the given type for the given $content.

public static humhub\modules\content\models\ContentTagRelation[] getTagContentRelations ( humhub\modules\content\models\Content $content, $includeGlobal true )
$content humhub\modules\content\models\Content
$includeGlobal
getUrl() public method

public string getUrl ( )
return string

Related link

hasAddition() public method

public boolean hasAddition ( )
return boolean

Check if this content tag has an related addition

init() public method

Sets the module_id as and type.

Subclasses overwriting this method have to make sure to call parent::init() at the end.

public void init ( )
is() public method

Checks if this content tag is of the given $type.

public boolean is ( $type )
$type
load() public method

public void load ( $data, $formName null )
$data
$formName
moduleQuery() public static method

Adds an module id filter query to the given $query instance in case a subclass has set the $moduleId.

public static mixed moduleQuery ( $query )
$query

ActiveQuery

rules() public method

public void rules ( )
setAddition() public method

Sets a ContentTagAddition for this instance, note you'll have to call $tag->save() manually

public void setAddition ( humhub\modules\content\models\ContentTagAddition $addition )
$addition humhub\modules\content\models\ContentTagAddition
tableName() public static method

public static void tableName ( )
typeQuery() public static method

Adds an type filter query to the given $query instance in case $includeTypeQuery of the subclass is set to true and the calling class is not ContentTag class itself.

public static mixed typeQuery ( $query )
$query

ActiveQuery

validate() public method

public void validate ( $attributeNames null, $clearErrors true )
$attributeNames
$clearErrors
validateUnique() public method

Validates

public void validateUnique ( $attribute, $params, $validator )
$attribute
$params
$validator