TagAssociationInterface
in
Interface for managing tag associations with entities.
Implementations handle specific entity types:
- Words (word_tag_map table)
- Texts (text_tag_map table)
- Archived texts (archived_text_tag_map table)
Tags
Table of Contents
Methods
- addTag() : bool
- Add a tag to an item.
- addTagToItems() : int
- Add a tag to multiple items.
- cleanupOrphanedLinks() : int
- Clean up orphaned tag links.
- clearItemsForTag() : int
- Remove all associations for a tag.
- clearTagsForItem() : int
- Remove all associations for an item.
- getItemCount() : int
- Get count of items associated with a tag.
- getTagIdsForItem() : array<string|int, int>
- Get all tag IDs associated with an item.
- getTagTextsForItem() : array<string|int, string>
- Get all tag texts associated with an item.
- hasTag() : bool
- Check if a tag is associated with an item.
- removeTag() : bool
- Remove a tag from an item.
- removeTagFromItems() : int
- Remove a tag from multiple items.
- setTagsByName() : void
- Set tags for an item by tag names.
- setTagsForItem() : void
- Set tags for an item (replaces existing associations).
Methods
addTag()
Add a tag to an item.
public
addTag(int $itemId, int $tagId) : bool
Parameters
- $itemId : int
-
The item ID
- $tagId : int
-
The tag ID
Return values
bool —True if added, false if already exists
addTagToItems()
Add a tag to multiple items.
public
addTagToItems(int $tagId, array<string|int, int> $itemIds) : int
Parameters
- $tagId : int
-
The tag ID
- $itemIds : array<string|int, int>
-
Item IDs to add the tag to
Return values
int —Number of items the tag was added to
cleanupOrphanedLinks()
Clean up orphaned tag links.
public
cleanupOrphanedLinks() : int
Removes associations where the tag no longer exists.
Return values
int —Number of removed orphaned links
clearItemsForTag()
Remove all associations for a tag.
public
clearItemsForTag(int $tagId) : int
Called when a tag is deleted.
Parameters
- $tagId : int
-
The tag ID
Return values
int —Number of removed associations
clearTagsForItem()
Remove all associations for an item.
public
clearTagsForItem(int $itemId) : int
Parameters
- $itemId : int
-
The item ID
Return values
int —Number of removed associations
getItemCount()
Get count of items associated with a tag.
public
getItemCount(int $tagId) : int
Parameters
- $tagId : int
-
The tag ID
Return values
intgetTagIdsForItem()
Get all tag IDs associated with an item.
public
getTagIdsForItem(int $itemId) : array<string|int, int>
Parameters
- $itemId : int
-
The item ID (word, text, or archived text)
Return values
array<string|int, int> —Array of tag IDs
getTagTextsForItem()
Get all tag texts associated with an item.
public
getTagTextsForItem(int $itemId) : array<string|int, string>
Parameters
- $itemId : int
-
The item ID
Return values
array<string|int, string> —Array of tag texts
hasTag()
Check if a tag is associated with an item.
public
hasTag(int $itemId, int $tagId) : bool
Parameters
- $itemId : int
-
The item ID
- $tagId : int
-
The tag ID
Return values
boolremoveTag()
Remove a tag from an item.
public
removeTag(int $itemId, int $tagId) : bool
Parameters
- $itemId : int
-
The item ID
- $tagId : int
-
The tag ID
Return values
bool —True if removed, false if not found
removeTagFromItems()
Remove a tag from multiple items.
public
removeTagFromItems(int $tagId, array<string|int, int> $itemIds) : int
Parameters
- $tagId : int
-
The tag ID
- $itemIds : array<string|int, int>
-
Item IDs to remove the tag from
Return values
int —Number of items the tag was removed from
setTagsByName()
Set tags for an item by tag names.
public
setTagsByName(int $itemId, array<string|int, string> $tagNames) : void
Creates tags if they don't exist.
Parameters
- $itemId : int
-
The item ID
- $tagNames : array<string|int, string>
-
Tag names to associate
setTagsForItem()
Set tags for an item (replaces existing associations).
public
setTagsForItem(int $itemId, array<string|int, int> $tagIds) : void
Parameters
- $itemId : int
-
The item ID
- $tagIds : array<string|int, int>
-
Tag IDs to associate