TagsFacade
in package
Facade for tag module operations.
Provides a unified interface to all tag-related use cases. Designed for backward compatibility with existing TagService callers.
Tags
Table of Contents
Properties
- $archivedTextAssociation : TagAssociationInterface|null
- $association : TagAssociationInterface
- $getAllTagNames : GetAllTagNames|null
- $repository : TagRepositoryInterface
- $tagType : TagType
- $termRepository : TagRepositoryInterface|null
- $textAssociation : TagAssociationInterface|null
- $textRepository : TagRepositoryInterface|null
- $wordAssociation : TagAssociationInterface|null
Methods
- __construct() : mixed
- Constructor.
- addTagToArchivedTexts() : array{count: int, error: ?string}
- Add a tag to multiple archived texts.
- addTagToTexts() : array{count: int, error: ?string}
- Add a tag to multiple texts.
- addTagToWords() : array{count: int, error: ?string}
- Add a tag to multiple words.
- buildWhereClause() : array{clause: string, params: array}
- Build WHERE clause for query filtering.
- cleanupOrphanedLinks() : void
- Cleanup orphaned tag links.
- create() : Tag, error: ?string}
- Create a new tag.
- delete() : array{success: bool, count: int}
- Delete a single tag.
- deleteAll() : array{success: bool, count: int}
- Delete all tags matching filter.
- deleteMultiple() : array{success: bool, count: int}
- Delete multiple tags.
- formatDuplicateError() : string
- Format duplicate entry error message for display.
- forTermTags() : self
- Create a facade for term tags.
- forTextTags() : self
- Create a facade for text tags.
- getAllTermTags() : array<string|int, string>
- Get all term tag names with session caching.
- getAllTextTags() : array<string|int, string>
- Get all text tag names with session caching.
- getArchivedItemsUrl() : string
- Get URL to view archived texts with a tag.
- getArchivedTextTagSelectOptions() : string
- Get archived text tag select options HTML for filtering.
- getArchivedTextTagsHtml() : string
- Get HTML list of tags for an archived text.
- getArchivedUsageCount() : int
- Get archived text usage count (text tags only).
- getBaseUrl() : string
- Get the base URL for this tag type.
- getById() : array<string|int, mixed>|null
- Get a tag by ID.
- getCount() : int
- Get total count of tags.
- getItemsUrl() : string
- Get URL to view items with a tag.
- getList() : array<string|int, mixed>
- Get paginated list of tags.
- getMaxPerPage() : int
- Get maximum items per page.
- getPagination() : array{pages: int, currentPage: int, perPage: int}
- Get pagination info.
- getSortColumn() : string
- Get sort column from index.
- getSortOptions() : array<string|int, mixed>
- Get sort options for dropdown.
- getTagType() : TagType
- Get the current tag type.
- getTagTypeLabel() : string
- Get the tag type label.
- getTermTagSelectOptions() : string
- Get term tag select options HTML for filtering.
- getTextTagSelectOptions() : string
- Get text tag select options HTML for filtering.
- getTextTagSelectOptionsWithTextIds() : string
- Get text tag select options with text IDs for word list filtering.
- getTextTagsHtml() : string
- Get HTML list of tags for a text.
- getUsageCount() : int
- Get usage count for a tag.
- getWordTagList() : string
- Get comma-separated tag list for a word.
- getWordTagListHtml() : string
- Get formatted tag list as Bulma tag components for a word.
- getWordTagsArray() : array<string|int, string>
- Get word tags as array.
- getWordTagsHtml() : string
- Get HTML list of tags for a word.
- parseDuplicateError() : array{isDuplicate: bool, tagName: string, tagType: string}|null
- Parse duplicate entry error and extract tag details.
- removeTagFromArchivedTexts() : array{count: int, error: ?string}
- Remove a tag from multiple archived texts.
- removeTagFromTexts() : array{count: int, error: ?string}
- Remove a tag from multiple texts.
- removeTagFromWords() : array{count: int, error: ?string}
- Remove a tag from multiple words.
- saveArchivedTextTags() : void
- Save tags for an archived text.
- saveArchivedTextTagsFromForm() : void
- Save tags for an archived text from form input.
- saveTextTags() : void
- Save tags for a text.
- saveTextTagsFromForm() : void
- Save tags for a text from form input.
- saveWordTags() : void
- Save tags for a word.
- saveWordTagsFromArray() : void
- Save tags for a word from an array of tag names.
- saveWordTagsFromForm() : void
- Save tags for a word from form input.
- update() : Tag, error: ?string}
- Update an existing tag.
- getArchivedTextAssociation() : TagAssociationInterface
- getGetAllTagNames() : GetAllTagNames
- getOrCreateTermTag() : int|null
- Get or create a term tag, returning its ID.
- getOrCreateTextTag() : int|null
- Get or create a text tag, returning its ID.
- getTermRepository() : TagRepositoryInterface
- getTextAssociation() : TagAssociationInterface
- getTextRepository() : TagRepositoryInterface
- getWordAssociation() : TagAssociationInterface
Properties
$archivedTextAssociation
private
static TagAssociationInterface|null
$archivedTextAssociation
= null
$association
private
TagAssociationInterface
$association
$getAllTagNames
private
static GetAllTagNames|null
$getAllTagNames
= null
$repository
private
TagRepositoryInterface
$repository
$tagType
private
TagType
$tagType
$termRepository
private
static TagRepositoryInterface|null
$termRepository
= null
$textAssociation
private
static TagAssociationInterface|null
$textAssociation
= null
$textRepository
private
static TagRepositoryInterface|null
$textRepository
= null
$wordAssociation
private
static TagAssociationInterface|null
$wordAssociation
= null
Methods
__construct()
Constructor.
public
__construct([TagType $tagType = TagType::TERM ][, TagRepositoryInterface|null $repository = null ][, TagAssociationInterface|null $association = null ]) : mixed
Parameters
- $tagType : TagType = TagType::TERM
-
Tag type (TERM or TEXT)
- $repository : TagRepositoryInterface|null = null
-
Tag repository
- $association : TagAssociationInterface|null = null
-
Tag association handler
addTagToArchivedTexts()
Add a tag to multiple archived texts.
public
static addTagToArchivedTexts(string $tagText, string $idList) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to add
- $idList : string
-
SQL list of archived text IDs, e.g. "(1,2,3)"
Return values
array{count: int, error: ?string} —Result with count and optional error
addTagToTexts()
Add a tag to multiple texts.
public
static addTagToTexts(string $tagText, string $idList) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to add
- $idList : string
-
SQL list of text IDs, e.g. "(1,2,3)"
Return values
array{count: int, error: ?string} —Result with count and optional error
addTagToWords()
Add a tag to multiple words.
public
static addTagToWords(string $tagText, string $idList) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to add
- $idList : string
-
SQL list of word IDs, e.g. "(1,2,3)"
Return values
array{count: int, error: ?string} —Result with count and optional error
buildWhereClause()
Build WHERE clause for query filtering.
public
buildWhereClause(string $query) : array{clause: string, params: array}
Parameters
- $query : string
-
Filter query string
Return values
array{clause: string, params: array} —Array with SQL clause and parameters
cleanupOrphanedLinks()
Cleanup orphaned tag links.
public
cleanupOrphanedLinks() : void
create()
Create a new tag.
public
create(string $text[, string $comment = '' ]) : Tag, error: ?string}
Parameters
- $text : string
-
Tag text
- $comment : string = ''
-
Tag comment
Return values
Tag, error: ?string} —Result
delete()
Delete a single tag.
public
delete(int $id) : array{success: bool, count: int}
Parameters
- $id : int
-
Tag ID
Return values
array{success: bool, count: int} —Result
deleteAll()
Delete all tags matching filter.
public
deleteAll([string $query = '' ]) : array{success: bool, count: int}
Parameters
- $query : string = ''
-
Filter query
Return values
array{success: bool, count: int} —Result
deleteMultiple()
Delete multiple tags.
public
deleteMultiple(array<string|int, int> $ids) : array{success: bool, count: int}
Parameters
- $ids : array<string|int, int>
-
Tag IDs
Return values
array{success: bool, count: int} —Result
formatDuplicateError()
Format duplicate entry error message for display.
public
formatDuplicateError(string $message) : string
Parameters
- $message : string
-
Original error message
Return values
string —Formatted error message
forTermTags()
Create a facade for term tags.
public
static forTermTags() : self
Return values
selfforTextTags()
Create a facade for text tags.
public
static forTextTags() : self
Return values
selfgetAllTermTags()
Get all term tag names with session caching.
public
static getAllTermTags([bool $refresh = false ]) : array<string|int, string>
Parameters
- $refresh : bool = false
-
Force refresh
Return values
array<string|int, string>getAllTextTags()
Get all text tag names with session caching.
public
static getAllTextTags([bool $refresh = false ]) : array<string|int, string>
Parameters
- $refresh : bool = false
-
Force refresh
Return values
array<string|int, string>getArchivedItemsUrl()
Get URL to view archived texts with a tag.
public
getArchivedItemsUrl(int $tagId) : string
Parameters
- $tagId : int
-
Tag ID
Return values
stringgetArchivedTextTagSelectOptions()
Get archived text tag select options HTML for filtering.
public
static getArchivedTextTagSelectOptions(int|string|null $selected, int|string $langId) : string
Parameters
- $selected : int|string|null
-
Currently selected value
- $langId : int|string
-
Language ID filter ('' for all)
Return values
string —HTML options
getArchivedTextTagsHtml()
Get HTML list of tags for an archived text.
public
static getArchivedTextTagsHtml(int $textId) : string
Parameters
- $textId : int
-
Archived text ID
Return values
string —HTML UL element
getArchivedUsageCount()
Get archived text usage count (text tags only).
public
getArchivedUsageCount(int $tagId) : int
Parameters
- $tagId : int
-
Tag ID
Return values
intgetBaseUrl()
Get the base URL for this tag type.
public
getBaseUrl() : string
Return values
stringgetById()
Get a tag by ID.
public
getById(int $id) : array<string|int, mixed>|null
Parameters
- $id : int
-
Tag ID
Return values
array<string|int, mixed>|null —Tag data or null
getCount()
Get total count of tags.
public
getCount([string $query = '' ]) : int
Parameters
- $query : string = ''
-
Filter query
Return values
intgetItemsUrl()
Get URL to view items with a tag.
public
getItemsUrl(int $tagId) : string
Parameters
- $tagId : int
-
Tag ID
Return values
stringgetList()
Get paginated list of tags.
public
getList([string $query = '' ][, string $orderBy = 'text' ][, int $page = 1 ][, int $perPage = 0 ]) : array<string|int, mixed>
Parameters
- $query : string = ''
-
Filter query
- $orderBy : string = 'text'
-
Sort column
- $page : int = 1
-
Page number
- $perPage : int = 0
-
Items per page
Return values
array<string|int, mixed> —Tag list with usage counts
getMaxPerPage()
Get maximum items per page.
public
getMaxPerPage() : int
Return values
intgetPagination()
Get pagination info.
public
getPagination(int $totalCount, int $currentPage) : array{pages: int, currentPage: int, perPage: int}
Parameters
- $totalCount : int
-
Total count
- $currentPage : int
-
Current page
Return values
array{pages: int, currentPage: int, perPage: int}getSortColumn()
Get sort column from index.
public
getSortColumn(int $index) : string
Parameters
- $index : int
-
Sort index
Return values
stringgetSortOptions()
Get sort options for dropdown.
public
getSortOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getTagType()
Get the current tag type.
public
getTagType() : TagType
Return values
TagTypegetTagTypeLabel()
Get the tag type label.
public
getTagTypeLabel() : string
Return values
stringgetTermTagSelectOptions()
Get term tag select options HTML for filtering.
public
static getTermTagSelectOptions(int|string|null $selected, int|string $langId) : string
Parameters
- $selected : int|string|null
-
Currently selected value
- $langId : int|string
-
Language ID filter ('' for all)
Return values
string —HTML options
getTextTagSelectOptions()
Get text tag select options HTML for filtering.
public
static getTextTagSelectOptions(int|string|null $selected, int|string $langId) : string
Parameters
- $selected : int|string|null
-
Currently selected value
- $langId : int|string
-
Language ID filter ('' for all)
Return values
string —HTML options
getTextTagSelectOptionsWithTextIds()
Get text tag select options with text IDs for word list filtering.
public
static getTextTagSelectOptionsWithTextIds(int|string $langId, int|string|null $selected) : string
Parameters
- $langId : int|string
-
Language ID filter
- $selected : int|string|null
-
Currently selected value
Return values
string —HTML options
getTextTagsHtml()
Get HTML list of tags for a text.
public
static getTextTagsHtml(int $textId) : string
Parameters
- $textId : int
-
Text ID
Return values
string —HTML UL element
getUsageCount()
Get usage count for a tag.
public
getUsageCount(int $tagId) : int
Parameters
- $tagId : int
-
Tag ID
Return values
intgetWordTagList()
Get comma-separated tag list for a word.
public
static getWordTagList(int $wordId[, bool $escapeHtml = true ]) : string
Parameters
- $wordId : int
-
Word ID
- $escapeHtml : bool = true
-
Whether to escape HTML
Return values
stringgetWordTagListHtml()
Get formatted tag list as Bulma tag components for a word.
public
static getWordTagListHtml(int $wordId[, string $size = 'is-small' ][, string $color = 'is-info' ][, bool $isLight = true ]) : string
Parameters
- $wordId : int
-
Word ID
- $size : string = 'is-small'
-
Bulma size class (e.g., 'is-small', 'is-normal')
- $color : string = 'is-info'
-
Bulma color class (e.g., 'is-info', 'is-primary')
- $isLight : bool = true
-
Whether to use light variant
Return values
string —HTML for Bulma tags
getWordTagsArray()
Get word tags as array.
public
static getWordTagsArray(int $wordId) : array<string|int, string>
Parameters
- $wordId : int
-
Word ID
Return values
array<string|int, string>getWordTagsHtml()
Get HTML list of tags for a word.
public
static getWordTagsHtml(int $wordId) : string
Parameters
- $wordId : int
-
Word ID
Return values
string —HTML UL element
parseDuplicateError()
Parse duplicate entry error and extract tag details.
public
parseDuplicateError(string $message) : array{isDuplicate: bool, tagName: string, tagType: string}|null
Parameters
- $message : string
-
Original error message
Return values
array{isDuplicate: bool, tagName: string, tagType: string}|null —Returns tag details if duplicate error, null otherwise
removeTagFromArchivedTexts()
Remove a tag from multiple archived texts.
public
static removeTagFromArchivedTexts(string $tagText, string $idList) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to remove
- $idList : string
-
SQL list of archived text IDs, e.g. "(1,2,3)"
Return values
array{count: int, error: ?string} —Result with count and optional error
removeTagFromTexts()
Remove a tag from multiple texts.
public
static removeTagFromTexts(string $tagText, string $idList) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to remove
- $idList : string
-
SQL list of text IDs, e.g. "(1,2,3)"
Return values
array{count: int, error: ?string} —Result with count and optional error
removeTagFromWords()
Remove a tag from multiple words.
public
static removeTagFromWords(string $tagText, string $idList) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to remove
- $idList : string
-
SQL list of word IDs, e.g. "(1,2,3)"
Return values
array{count: int, error: ?string} —Result with count and optional error
saveArchivedTextTags()
Save tags for an archived text.
public
static saveArchivedTextTags(int $textId, array<string|int, string> $tagNames) : void
Parameters
- $textId : int
-
Archived text ID
- $tagNames : array<string|int, string>
-
Tag names
saveArchivedTextTagsFromForm()
Save tags for an archived text from form input.
public
static saveArchivedTextTagsFromForm(int $textId) : void
Parameters
- $textId : int
-
Archived text ID
saveTextTags()
Save tags for a text.
public
static saveTextTags(int $textId, array<string|int, string> $tagNames) : void
Parameters
- $textId : int
-
Text ID
- $tagNames : array<string|int, string>
-
Tag names
saveTextTagsFromForm()
Save tags for a text from form input.
public
static saveTextTagsFromForm(int $textId[, array<string|int, mixed>|null $textTags = null ]) : void
Parameters
- $textId : int
-
Text ID
- $textTags : array<string|int, mixed>|null = null
-
Optional tags array. If null, reads from request.
saveWordTags()
Save tags for a word.
public
static saveWordTags(int $wordId, array<string|int, string> $tagNames) : void
Parameters
- $wordId : int
-
Word ID
- $tagNames : array<string|int, string>
-
Tag names
saveWordTagsFromArray()
Save tags for a word from an array of tag names.
public
static saveWordTagsFromArray(int $wordId, array<string|int, string> $tagNames) : void
Parameters
- $wordId : int
-
Word ID
- $tagNames : array<string|int, string>
-
Array of tag name strings
saveWordTagsFromForm()
Save tags for a word from form input.
public
static saveWordTagsFromForm(int $wordId) : void
Reads 'TermTags' from request and saves to word.
Parameters
- $wordId : int
-
Word ID
update()
Update an existing tag.
public
update(int $id, string $text, string $comment) : Tag, error: ?string}
Parameters
- $id : int
-
Tag ID
- $text : string
-
New tag text
- $comment : string
-
New tag comment
Return values
Tag, error: ?string} —Result
getArchivedTextAssociation()
private
static getArchivedTextAssociation() : TagAssociationInterface
Return values
TagAssociationInterfacegetGetAllTagNames()
private
static getGetAllTagNames() : GetAllTagNames
Return values
GetAllTagNamesgetOrCreateTermTag()
Get or create a term tag, returning its ID.
private
static getOrCreateTermTag(string $tagText) : int|null
Parameters
- $tagText : string
-
Tag text
Return values
int|null —Tag ID or null on failure
getOrCreateTextTag()
Get or create a text tag, returning its ID.
private
static getOrCreateTextTag(string $tagText) : int|null
Parameters
- $tagText : string
-
Tag text
Return values
int|null —Tag ID or null on failure
getTermRepository()
private
static getTermRepository() : TagRepositoryInterface
Return values
TagRepositoryInterfacegetTextAssociation()
private
static getTextAssociation() : TagAssociationInterface
Return values
TagAssociationInterfacegetTextRepository()
private
static getTextRepository() : TagRepositoryInterface
Return values
TagRepositoryInterfacegetWordAssociation()
private
static getWordAssociation() : TagAssociationInterface