VuFind API Documentation

Tags extends TagsService
in package

VuFind tag processing logic

Tags
category

VuFind

author

Demian Katz demian.katz@villanova.edu

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Wiki

deprecated

Use \VuFind\Tags\TagsService

Table of Contents

$caseSensitive  : bool
$maxLength  : int
$resourcePopulator  : ResourcePopulator
$resourceTagsService  : ResourceTagsServiceInterface|TransactionInterface
$tableManager  : PluginManager
Database table plugin manager
$tagDbService  : TagServiceInterface
$userListService  : UserListServiceInterface
__construct()  : mixed
Constructor
deleteOrphanedTags()  : void
Delete orphaned tags (those not present in resource_tags) from the tags table.
fixDuplicateTags()  : void
Repair duplicate tags in the database (if any).
getDbTable()  : Gateway
Get a database table object.
getDbTableManager()  : PluginManager
Get the table plugin manager. Throw an exception if it is missing.
getDuplicateTags()  : array<string|int, mixed>
Get a list of duplicate tags (this should never happen, but past bugs and the introduction of case-insensitive tags have introduced problems).
getListTags()  : array<string|int, array<string|int, mixed>>
Get tags assigned to a user list. Returns an array of arrays with id and tag keys.
getNonListTagsFuzzilyMatchingString()  : array<string|int, mixed>
Get the tags that match a string
getOrCreateTagByText()  : TagsEntityInterface
Get a tag entity if it exists; create it otherwise.
getRecordTags()  : array<string|int, mixed>
Get all tags associated with the specified record (and matching provided filters).
getRecordTagsFromFavorites()  : array<string|int, mixed>
Get all tags from favorite lists associated with the specified record (and matching provided filters).
getRecordTagsNotInFavorites()  : array<string|int, mixed>
Get all tags outside of favorite lists associated with the specified record (and matching provided filters).
getResourcesMatchingTagQuery()  : array<string|int, mixed>
Get all resources associated with the provided tag query.
getResourceTagsPaginator()  : Paginator
Get Resource Tags Paginator
getStatistics()  : array<string|int, mixed>
Get statistics on use of tags.
getTagBrowseList()  : array<string|int, mixed>
Get a list of tags for the browse interface.
getTagByText()  : array<string|int, TagsEntityInterface>
Get the first available matching tag by text; return null if no match is found.
getTagsByText()  : array<string|int, TagsEntityInterface>
Get all matching tags by text. Normally, 0 or 1 results will be retrieved, but more may be retrieved under exceptional circumstances (e.g. if retrieving case-insensitively after storing data case-sensitively).
getUniqueTags()  : array<string|int, array<string|int, mixed>>
Gets unique tags from the database.
getUserListsByTagAndId()  : array<string|int, UserListEntityInterface>
Get lists associated with a particular tag and/or list of IDs. If IDs and tags are both provided, only the intersection of matches will be returned.
getUserTagsFromFavorites()  : array<string|int, mixed>
Get a list of all tags generated by the user in favorites lists. Note that the returned list WILL NOT include tags attached to records that are not saved in favorites lists. Returns an array of arrays with id and tag keys.
hasCaseSensitiveTags()  : bool
Are tags case-sensitive?
linkTagsToRecord()  : void
Add tags to the record.
linkTagToResource()  : void
Unlink a tag from a resource object.
parse()  : array<string|int, mixed>
Parse a user-submitted tag string into an array of separate tags.
setDbTableManager()  : void
Set the table plugin manager.
unlinkTagFromResource()  : void
Unlink a tag from a resource object.
unlinkTagsFromRecord()  : void
Remove tags from the record.

Properties

$caseSensitive

protected bool $caseSensitive = false

Methods

__construct()

Constructor

public __construct(TagServiceInterface $tagDbService, ResourceTagsServiceInterface|TransactionInterface $resourceTagsService, UserListServiceInterface $userListService, ResourcePopulator $resourcePopulator[, int $maxLength = 64 ][, bool $caseSensitive = false ]) : mixed
Parameters
$tagDbService : TagServiceInterface

Tag database service

$resourceTagsService : ResourceTagsServiceInterface|TransactionInterface

Resource/Tags database service

$userListService : UserListServiceInterface

User list database service

$resourcePopulator : ResourcePopulator

Resource populator service

$maxLength : int = 64

Maximum tag length

$caseSensitive : bool = false

Are tags case sensitive?

Return values
mixed

deleteOrphanedTags()

Delete orphaned tags (those not present in resource_tags) from the tags table.

public deleteOrphanedTags() : void
Return values
void

fixDuplicateTags()

Repair duplicate tags in the database (if any).

public fixDuplicateTags() : void
Return values
void

getDbTable()

Get a database table object.

public getDbTable(string $table) : Gateway
Parameters
$table : string

Table to load.

Return values
Gateway

getDuplicateTags()

Get a list of duplicate tags (this should never happen, but past bugs and the introduction of case-insensitive tags have introduced problems).

public getDuplicateTags() : array<string|int, mixed>
Return values
array<string|int, mixed>

getListTags()

Get tags assigned to a user list. Returns an array of arrays with id and tag keys.

public getListTags(UserListEntityInterface|int $listOrId[, UserEntityInterface|int|null $userOrId = null ]) : array<string|int, array<string|int, mixed>>
Parameters
$listOrId : UserListEntityInterface|int

List ID or entity

$userOrId : UserEntityInterface|int|null = null

User ID or entity to look up (null for no filter).

Return values
array<string|int, array<string|int, mixed>>

getNonListTagsFuzzilyMatchingString()

Get the tags that match a string

public getNonListTagsFuzzilyMatchingString(string $text[, string $sort = 'alphabetical' ][, int $limit = 100 ]) : array<string|int, mixed>
Parameters
$text : string

Tag to look up.

$sort : string = 'alphabetical'

Sort type

$limit : int = 100

Maximum results to retrieve

Return values
array<string|int, mixed>

getRecordTags()

Get all tags associated with the specified record (and matching provided filters).

public getRecordTags(string $id[, string $source = DEFAULT_SEARCH_BACKEND ], int $limit[, UserListEntityInterface|int|null $listOrId = null ][, UserEntityInterface|int|null $userOrId = null ][, string $sort = 'count' ][, UserEntityInterface|int|null $ownerOrId = null ]) : array<string|int, mixed>
Parameters
$id : string

Record ID to look up

$source : string = DEFAULT_SEARCH_BACKEND

Source of record to look up

$limit : int

Max. number of tags to return (0 = no limit)

$listOrId : UserListEntityInterface|int|null = null

ID of list to load tags from (null for no restriction)

$userOrId : UserEntityInterface|int|null = null

ID of user to load tags from (null for all users)

$sort : string = 'count'

Sort type ('count' or 'tag')

$ownerOrId : UserEntityInterface|int|null = null

ID of user to check for ownership

Return values
array<string|int, mixed>

getRecordTagsFromFavorites()

Get all tags from favorite lists associated with the specified record (and matching provided filters).

public getRecordTagsFromFavorites(string $id[, string $source = DEFAULT_SEARCH_BACKEND ], int $limit[, UserListEntityInterface|int|null $listOrId = null ][, UserEntityInterface|int|null $userOrId = null ][, string $sort = 'count' ][, UserEntityInterface|int|null $ownerOrId = null ]) : array<string|int, mixed>
Parameters
$id : string

Record ID to look up

$source : string = DEFAULT_SEARCH_BACKEND

Source of record to look up

$limit : int

Max. number of tags to return (0 = no limit)

$listOrId : UserListEntityInterface|int|null = null

ID of list to load tags from (null for tags that are associated with ANY list, but excluding non-list tags)

$userOrId : UserEntityInterface|int|null = null

ID of user to load tags from (null for all users)

$sort : string = 'count'

Sort type ('count' or 'tag')

$ownerOrId : UserEntityInterface|int|null = null

ID of user to check for ownership (this will not filter the result list, but rows owned by this user will have an is_me column set to 1)

Return values
array<string|int, mixed>

getRecordTagsNotInFavorites()

Get all tags outside of favorite lists associated with the specified record (and matching provided filters).

public getRecordTagsNotInFavorites(string $id[, string $source = DEFAULT_SEARCH_BACKEND ], int $limit[, UserEntityInterface|int|null $userOrId = null ][, string $sort = 'count' ][, UserEntityInterface|int|null $ownerOrId = null ]) : array<string|int, mixed>
Parameters
$id : string

Record ID to look up

$source : string = DEFAULT_SEARCH_BACKEND

Source of record to look up

$limit : int

Max. number of tags to return (0 = no limit)

$userOrId : UserEntityInterface|int|null = null

User entity/ID to load tags from (null for all users)

$sort : string = 'count'

Sort type ('count' or 'tag')

$ownerOrId : UserEntityInterface|int|null = null

ID of user to check for ownership (this will not filter the result list, but rows owned by this user will have an is_me column set to 1)

Return values
array<string|int, mixed>

getResourcesMatchingTagQuery()

Get all resources associated with the provided tag query.

public getResourcesMatchingTagQuery(string $q[, string $source = null ][, string $sort = null ], int $offset[, int|null $limit = null ][, bool $fuzzy = true ]) : array<string|int, mixed>
Parameters
$q : string

Search query

$source : string = null

Record source (optional limiter)

$sort : string = null

Resource field to sort on (optional)

$offset : int

Offset for results

$limit : int|null = null

Limit for results (null for none)

$fuzzy : bool = true

Are we doing an exact (false) or fuzzy (true) search?

Return values
array<string|int, mixed>

getResourceTagsPaginator()

Get Resource Tags Paginator

public getResourceTagsPaginator([int|null $userId = null ][, int|null $resourceId = null ][, int|null $tagId = null ][, string|null $order = null ][, int|null $page = null ][, int $limit = 20 ]) : Paginator
Parameters
$userId : int|null = null

ID of user (null for any)

$resourceId : int|null = null

ID of the resource (null for any)

$tagId : int|null = null

ID of the tag (null for any)

$order : string|null = null

The order in which to return the data

$page : int|null = null

The page number to select

$limit : int = 20

The number of items to fetch

Return values
Paginator

getStatistics()

Get statistics on use of tags.

public getStatistics([bool $extended = false ]) : array<string|int, mixed>
Parameters
$extended : bool = false

Include extended (unique/anonymous) stats.

Return values
array<string|int, mixed>

getTagBrowseList()

Get a list of tags for the browse interface.

public getTagBrowseList(string $sort, int $limit) : array<string|int, mixed>
Parameters
$sort : string

Sort/search parameter

$limit : int

Maximum number of tags (default = 100, < 1 = no limit)

Return values
array<string|int, mixed>

getTagByText()

Get the first available matching tag by text; return null if no match is found.

public getTagByText(string $text) : array<string|int, TagsEntityInterface>
Parameters
$text : string

Tag text to match

Return values
array<string|int, TagsEntityInterface>

getTagsByText()

Get all matching tags by text. Normally, 0 or 1 results will be retrieved, but more may be retrieved under exceptional circumstances (e.g. if retrieving case-insensitively after storing data case-sensitively).

public getTagsByText(string $text) : array<string|int, TagsEntityInterface>
Parameters
$text : string

Tag text to match

Return values
array<string|int, TagsEntityInterface>

getUniqueTags()

Gets unique tags from the database.

public getUniqueTags([int|null $userId = null ][, int|null $resourceId = null ][, int|null $tagId = null ]) : array<string|int, array<string|int, mixed>>
Parameters
$userId : int|null = null

ID of user (null for any)

$resourceId : int|null = null

ID of the resource (null for any)

$tagId : int|null = null

ID of the tag (null for any)

Return values
array<string|int, array<string|int, mixed>>

getUserListsByTagAndId()

Get lists associated with a particular tag and/or list of IDs. If IDs and tags are both provided, only the intersection of matches will be returned.

public getUserListsByTagAndId([string|array<string|int, string>|null $tag = null ][, int|array<string|int, int>|null $listId = null ][, bool $publicOnly = true ][, bool $andTags = true ]) : array<string|int, UserListEntityInterface>
Parameters
$tag : string|array<string|int, string>|null = null

Tag or tags to match (by text, not ID; null for all)

$listId : int|array<string|int, int>|null = null

List ID or IDs to match (null for all)

$publicOnly : bool = true

Whether to return only public lists

$andTags : bool = true

Use AND operator when filtering by tag.

Return values
array<string|int, UserListEntityInterface>

getUserTagsFromFavorites()

Get a list of all tags generated by the user in favorites lists. Note that the returned list WILL NOT include tags attached to records that are not saved in favorites lists. Returns an array of arrays with id and tag keys.

public getUserTagsFromFavorites(UserEntityInterface|int $userOrId[, UserListEntityInterface|int|null $listOrId = null ][, string|null $recordId = null ][, string|null $source = null ]) : array<string|int, mixed>
Parameters
$userOrId : UserEntityInterface|int

User ID to look up.

$listOrId : UserListEntityInterface|int|null = null

Filter for tags tied to a specific list (null for no filter).

$recordId : string|null = null

Filter for tags tied to a specific resource (null for no filter).

$source : string|null = null

Filter for tags tied to a specific record source (null for no filter).

Return values
array<string|int, mixed>

hasCaseSensitiveTags()

Are tags case-sensitive?

public hasCaseSensitiveTags() : bool
Return values
bool

linkTagsToRecord()

Add tags to the record.

public linkTagsToRecord(AbstractBase $driver, UserEntityInterface $user, string|array<string|int, string> $tags) : void
Parameters
$driver : AbstractBase

Driver representing record being tagged

$user : UserEntityInterface

The user adding the tag(s)

$tags : string|array<string|int, string>

The user-provided tag(s), either as a string (to parse) or an array (already parsed)

Return values
void

linkTagToResource()

Unlink a tag from a resource object.

public linkTagToResource(string $tagText, ResourceEntityInterface|int $resourceOrId, UserEntityInterface|int $userOrId[, null|UserListEntityInterface|int $listOrId = null ]) : void
Parameters
$tagText : string

Text of tag to link (empty strings will be ignored)

$resourceOrId : ResourceEntityInterface|int

Resource entity or ID to link

$userOrId : UserEntityInterface|int

Owner of tag link

$listOrId : null|UserListEntityInterface|int = null

Optional list (omit to tag at resource level)

Return values
void

parse()

Parse a user-submitted tag string into an array of separate tags.

public parse(string $tags) : array<string|int, mixed>
Parameters
$tags : string

User-provided tags

Return values
array<string|int, mixed>

unlinkTagFromResource()

Unlink a tag from a resource object.

public unlinkTagFromResource(string $tagText, ResourceEntityInterface|int $resourceOrId, UserEntityInterface|int $userOrId[, null|UserListEntityInterface|int $listOrId = null ]) : void
Parameters
$tagText : string

Text of tag to unlink

$resourceOrId : ResourceEntityInterface|int

Resource entity or ID to unlink

$userOrId : UserEntityInterface|int

Owner of tag to unlink

$listOrId : null|UserListEntityInterface|int = null

Optional filter (only unlink from this list if provided)

Return values
void

unlinkTagsFromRecord()

Remove tags from the record.

public unlinkTagsFromRecord(AbstractBase $driver, UserEntityInterface $user, array<string|int, string> $tags) : void
Parameters
$driver : AbstractBase

Driver representing record being tagged

$user : UserEntityInterface

The user deleting the tag(s)

$tags : array<string|int, string>

The user-provided tag(s)

Return values
void

Search results