Class humhub\modules\content\models\ContentTag
Inheritance | humhub\modules\content\models\ContentTag » humhub\components\ActiveRecord » yii\db\ActiveRecord |
---|---|
Implements | Serializable |
Subclasses | humhub\modules\topic\models\Topic |
Available since version | 1.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
Property | Type | Description | Defined 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
Property Details
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.
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.
Id of the module related to this content tag concept
Method Details
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 |
public void __get ( $name ) | ||
$name |
Adds content tag related fitler conditions to a given query.
public static \yii\db\ActiveQuery addQueryCondition ( \yii\db\ActiveQuery $query ) | ||
$query | \yii\db\ActiveQuery |
public void afterSave ( $insert, $changedAttributes ) | ||
$insert | ||
$changedAttributes |
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 |
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 |
---|
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 |
---|
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 |
Finds instances and filters by module_id if a static module_id is given.
public static \yii\db\ActiveQuery find ( ) |
Searches for all content tags of this type.
public static humhub\components\ActiveRecord[] findAll ( $condition ) | ||
$condition |
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 |
Returns Content related tags.
public static \yii\db\ActiveQuery findByContent ( humhub\modules\content\models\Content $content ) | ||
$content | humhub\modules\content\models\Content |
Finds ContentTag for the given $moduleId
public static \yii\db\ActiveQuery findByModule ( $moduleId ) | ||
$moduleId |
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 |
Finds instances by given $type.
public static \yii\db\ActiveQuery findByType ( $type ) | ||
$type | string |
Finds all global content tags of this type.
public static \yii\db\ActiveQuery findGlobal ( ) |
Find a single instances either by providing an id or other condition.
public static static findOne ( $condition ) | ||
$condition |
public humhub\components\ActiveRecord|\yii\db\ActiveQuery getAddition ( ) |
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 |
---|
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 ( ) |
public static void getLabel ( ) |
Returns the parent tag relation.
public \yii\db\ActiveQuery getParent ( ) |
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 |
public string getUrl ( ) | ||
return | string | Related link |
---|
public boolean hasAddition ( ) | ||
return | boolean | Check if this content tag has an related addition |
---|
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 ( ) |
Checks if this content tag is of the given $type.
public boolean is ( $type ) | ||
$type |
public void load ( $data, $formName = null ) | ||
$data | ||
$formName |
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 |
public void rules ( ) |
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 |
public static void tableName ( ) |
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 |
public void validate ( $attributeNames = null, $clearErrors = true ) | ||
$attributeNames | ||
$clearErrors |
Validates
public void validateUnique ( $attribute, $params, $validator ) | ||
$attribute | ||
$params | ||
$validator |