FavoritesService
in package
implements
TranslatorAwareInterface
Uses
TranslatorAwareTrait
Favorites service
Tags
Interfaces, Classes, Traits and Enums
- TranslatorAwareInterface
- Lightweight translator aware marker interface (used as an alternative to \Laminas\I18n\Translator\TranslatorAwareInterface, which requires an excessive number of methods to be implemented).
Table of Contents
- $recordCache : Cache|null
- $recordLoader : Loader
- $resourcePopulator : ResourcePopulator
- $resourceService : ResourceServiceInterface
- $resourceTagsService : ResourceTagsServiceInterface|TransactionInterface
- $session : Container|null
- $tagsService : TagsService
- $translator : TranslatorInterface
- Translator
- $userListService : UserListServiceInterface
- $userResourceService : UserResourceServiceInterface
- $userService : UserServiceInterface
- __construct() : mixed
- Constructor
- addListTag() : void
- Add a tag to a list.
- createListForUser() : UserListEntityInterface
- Create a new list object for the specified user.
- deleteFavorites() : void
- Delete a group of favorites.
- destroyList() : void
- Destroy a list.
- formatTagStringForEditing() : string
- Convert an array representing tags into a string for an edit form
- getAndRememberListObject() : UserListEntityInterface
- Get a list object for the specified ID (or null to create a new list).
- getLastUsedList() : int|null
- Retrieve the ID of the last list that was accessed, if any.
- getListIdFromParams() : int|null
- Given an array of parameters, extract a list ID if possible. Return null if no valid ID is found or if a "NEW" record is requested.
- getTagStringForEditing() : string
- Call TagsService::getUserTagsFromFavorites() and format the results for editing.
- getTranslator() : TranslatorInterface
- Get translator object.
- getTranslatorLocale() : string
- Get the locale from the translator.
- rememberLastUsedList() : void
- Remember that this list was used so that it can become the default in dialog boxes.
- removeListResourcesById() : void
- Given an array of item ids, remove them from the specified list.
- removeUserResourcesById() : void
- Given an array of item ids, remove them from all of the specified user's lists
- save() : array<string|int, mixed>
- Legacy name for saveRecordToFavorites()
- saveListForUser() : void
- Saves the provided list to the database and remembers it in the session if it is valid; throws an exception otherwise.
- saveRecordsToFavorites() : array<string|int, mixed>
- Save a group of records to the user's favorites.
- saveRecordToFavorites() : array<string|int, mixed>
- Save this record to the user's favorites.
- saveResourceToFavorites() : void
- Add/update a resource in the user's account.
- setTranslator() : TranslatorAwareInterface
- Set a translator
- translate() : string
- Translate a string (or string-castable object)
- translateWithPrefix() : string
- Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
- updateListFromRequest() : int
- Update and save the list object using a request object -- useful for sharing form processing between multiple actions.
- userCanEditList() : bool
- Is the provided user allowed to edit the provided list?
- cacheBatch() : void
- Support method for saveBulk() -- save a batch of records to the cache.
- extractTextDomain() : array<string|int, mixed>
- Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
- getDebugTranslation() : string
- Build a debug-mode translation
- persistToCache() : void
- Persist a resource to the record cache (if applicable).
- sanitizeTranslationKey() : string
- Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
- translateString() : string
- Get translation for a string
Properties
$recordCache
protected
Cache|null
$recordCache
= null
$recordLoader
protected
Loader
$recordLoader
$resourcePopulator
protected
ResourcePopulator
$resourcePopulator
$resourceService
protected
ResourceServiceInterface
$resourceService
$resourceTagsService
protected
ResourceTagsServiceInterface|TransactionInterface
$resourceTagsService
$session
protected
Container|null
$session
= null
$tagsService
protected
TagsService
$tagsService
$translator
Translator
protected
TranslatorInterface
$translator
= null
$userListService
protected
UserListServiceInterface
$userListService
$userResourceService
protected
UserResourceServiceInterface
$userResourceService
$userService
protected
UserServiceInterface
$userService
Methods
__construct()
Constructor
public
__construct(ResourceServiceInterface $resourceService, ResourceTagsServiceInterface|TransactionInterface $resourceTagsService, UserListServiceInterface $userListService, UserResourceServiceInterface $userResourceService, UserServiceInterface $userService, ResourcePopulator $resourcePopulator, TagsService $tagsService, Loader $recordLoader[, Cache|null $recordCache = null ][, Container|null $session = null ]) : mixed
Parameters
- $resourceService : ResourceServiceInterface
-
Resource database service
- $resourceTagsService : ResourceTagsServiceInterface|TransactionInterface
-
Resource tags database service
- $userListService : UserListServiceInterface
-
UserList database service
- $userResourceService : UserResourceServiceInterface
-
UserResource database service
- $userService : UserServiceInterface
-
User database service
- $resourcePopulator : ResourcePopulator
-
Resource populator service
- $tagsService : TagsService
-
Tags service
- $recordLoader : Loader
-
Record loader
- $recordCache : Cache|null = null
-
Record cache (optional)
- $session : Container|null = null
-
Session container for remembering state (optional)
Return values
mixed —addListTag()
Add a tag to a list.
public
addListTag(string $tagText, UserListEntityInterface $list, UserEntityInterface $user) : void
Parameters
- $tagText : string
-
The tag to save.
- $list : UserListEntityInterface
-
The list being tagged.
- $user : UserEntityInterface
-
The user posting the tag.
Return values
void —createListForUser()
Create a new list object for the specified user.
public
createListForUser(UserEntityInterface|null $user) : UserListEntityInterface
Parameters
- $user : UserEntityInterface|null
-
Logged in user (null if logged out)
Tags
Return values
UserListEntityInterface —deleteFavorites()
Delete a group of favorites.
public
deleteFavorites(array<string|int, string> $ids, int|null $listID, UserEntityInterface $user) : void
Parameters
- $ids : array<string|int, string>
-
Array of IDs in source|id format.
- $listID : int|null
-
ID of list to delete from (null for all lists)
- $user : UserEntityInterface
-
Logged in user
Return values
void —destroyList()
Destroy a list.
public
destroyList(UserListEntityInterface $list[, UserEntityInterface|null $user = null ][, bool $force = false ]) : void
Parameters
- $list : UserListEntityInterface
-
List to destroy
- $user : UserEntityInterface|null = null
-
Logged-in user (null if none)
- $force : bool = false
-
Should we force the delete without checking permissions?
Tags
Return values
void —formatTagStringForEditing()
Convert an array representing tags into a string for an edit form
public
formatTagStringForEditing(array<string|int, mixed> $tags) : string
Parameters
- $tags : array<string|int, mixed>
-
Tags
Return values
string —getAndRememberListObject()
Get a list object for the specified ID (or null to create a new list).
public
getAndRememberListObject(int|null $listId, UserEntityInterface $user) : UserListEntityInterface
Ensure that the object is persisted to the database if it does not already exist, and remember it as the user's last-accessed list.
Parameters
- $listId : int|null
-
List ID (or null to create a new list)
- $user : UserEntityInterface
-
The user saving the record
Tags
Return values
UserListEntityInterface —getLastUsedList()
Retrieve the ID of the last list that was accessed, if any.
public
getLastUsedList() : int|null
Return values
int|null —Identifier value of a UserListEntityInterface object (if set) or null (if not available).
getListIdFromParams()
Given an array of parameters, extract a list ID if possible. Return null if no valid ID is found or if a "NEW" record is requested.
public
getListIdFromParams(array<string|int, mixed> $params) : int|null
Parameters
- $params : array<string|int, mixed>
-
Parameters to process
Return values
int|null —getTagStringForEditing()
Call TagsService::getUserTagsFromFavorites() and format the results for editing.
public
getTagStringForEditing(UserEntityInterface|int $userOrId[, UserListEntityInterface|int|null $listOrId = null ][, string|null $recordId = null ][, string|null $source = null ]) : string
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
string —getTranslator()
Get translator object.
public
getTranslator() : TranslatorInterface
Return values
TranslatorInterface —getTranslatorLocale()
Get the locale from the translator.
public
getTranslatorLocale([string $default = 'en' ]) : string
Parameters
- $default : string = 'en'
-
Default to use if translator absent.
Return values
string —rememberLastUsedList()
Remember that this list was used so that it can become the default in dialog boxes.
public
rememberLastUsedList(UserListEntityInterface $list) : void
Parameters
- $list : UserListEntityInterface
-
List to remember
Return values
void —removeListResourcesById()
Given an array of item ids, remove them from the specified list.
public
removeListResourcesById(UserListEntityInterface $list, UserEntityInterface|null $user, array<string|int, string> $ids[, string $source = DEFAULT_SEARCH_BACKEND ]) : void
Parameters
- $list : UserListEntityInterface
-
List being updated
- $user : UserEntityInterface|null
-
Logged-in user (null if none)
- $ids : array<string|int, string>
-
IDs to remove from the list
- $source : string = DEFAULT_SEARCH_BACKEND
-
Type of resource identified by IDs
Return values
void —removeUserResourcesById()
Given an array of item ids, remove them from all of the specified user's lists
public
removeUserResourcesById(UserEntityInterface $user, array<string|int, string> $ids[, string $source = DEFAULT_SEARCH_BACKEND ]) : void
Parameters
- $user : UserEntityInterface
-
User owning lists
- $ids : array<string|int, string>
-
IDs to remove from the list
- $source : string = DEFAULT_SEARCH_BACKEND
-
Type of resource identified by IDs
Return values
void —save()
Legacy name for saveRecordToFavorites()
public
save() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —saveListForUser()
Saves the provided list to the database and remembers it in the session if it is valid; throws an exception otherwise.
public
saveListForUser(UserListEntityInterface $list, UserEntityInterface|null $user) : void
Parameters
- $list : UserListEntityInterface
-
List to save
- $user : UserEntityInterface|null
-
Logged-in user (null if none)
Tags
Return values
void —saveRecordsToFavorites()
Save a group of records to the user's favorites.
public
saveRecordsToFavorites(array<string|int, mixed> $params, UserEntityInterface $user) : array<string|int, mixed>
Parameters
- $params : array<string|int, mixed>
-
Array with some or all of these keys:
- ids - Array of IDs in source|id format
- mytags - Unparsed tag string to associate with record (optional)
- list - ID of list to save record into (omit to create new list)
- $user : UserEntityInterface
-
The user saving the record
Return values
array<string|int, mixed> —list information
saveRecordToFavorites()
Save this record to the user's favorites.
public
saveRecordToFavorites(array<string|int, mixed> $params, UserEntityInterface $user, AbstractBase $driver) : array<string|int, mixed>
Parameters
- $params : array<string|int, mixed>
-
Array with some or all of these keys:
- mytags - Tag array to associate with record (optional)
- notes - Notes to associate with record (optional)
- list - ID of list to save record into (omit to create new list)
- $user : UserEntityInterface
-
The user saving the record
- $driver : AbstractBase
-
Record driver for record being saved
Return values
array<string|int, mixed> —list information
saveResourceToFavorites()
Add/update a resource in the user's account.
public
saveResourceToFavorites(UserEntityInterface|int $userOrId, ResourceEntityInterface|int $resourceOrId, UserListEntityInterface|int $listOrId, array<string|int, mixed> $tagArray, string $notes[, bool $replaceExisting = true ]) : void
Parameters
- $userOrId : UserEntityInterface|int
-
The user entity or ID saving the favorites
- $resourceOrId : ResourceEntityInterface|int
-
The resource entity or ID to add/update
- $listOrId : UserListEntityInterface|int
-
The list entity or ID to store the resource in.
- $tagArray : array<string|int, mixed>
-
An array of tags to associate with the resource.
- $notes : string
-
User notes about the resource.
- $replaceExisting : bool = true
-
Whether to replace all existing tags (true) or append to the existing list (false).
Return values
void —setTranslator()
Set a translator
public
setTranslator(TranslatorInterface $translator) : TranslatorAwareInterface
Parameters
- $translator : TranslatorInterface
-
Translator
Return values
TranslatorAwareInterface —translate()
Translate a string (or string-castable object)
public
translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —translateWithPrefix()
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
public
translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $prefix : string
-
Translation key prefix
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —updateListFromRequest()
Update and save the list object using a request object -- useful for sharing form processing between multiple actions.
public
updateListFromRequest(UserListEntityInterface $list, UserEntityInterface|null $user, Parameters $request) : int
Parameters
- $list : UserListEntityInterface
-
List to update
- $user : UserEntityInterface|null
-
Logged-in user (false if none)
- $request : Parameters
-
Request to process
Tags
Return values
int —ID of newly created row
userCanEditList()
Is the provided user allowed to edit the provided list?
public
userCanEditList(UserEntityInterface|null $user, UserListEntityInterface $list) : bool
Parameters
- $user : UserEntityInterface|null
-
Logged-in user (null if none)
- $list : UserListEntityInterface
-
List to check
Return values
bool —cacheBatch()
Support method for saveBulk() -- save a batch of records to the cache.
protected
cacheBatch(array<string|int, mixed> $cacheRecordIds) : void
Parameters
- $cacheRecordIds : array<string|int, mixed>
-
Array of IDs in source|id format
Return values
void —extractTextDomain()
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
protected
extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
Return values
array<string|int, mixed> —getDebugTranslation()
Build a debug-mode translation
protected
getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
- $domain : string
-
Text domain
- $str : string
-
String to translate
- $tokens : array<string|int, mixed>
-
Tokens to inject into the translated string
Return values
string —persistToCache()
Persist a resource to the record cache (if applicable).
protected
persistToCache(AbstractBase $driver, ResourceEntityInterface $resource) : void
Parameters
- $driver : AbstractBase
-
Record driver to persist
- $resource : ResourceEntityInterface
-
Resource row
Return values
void —sanitizeTranslationKey()
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
protected
sanitizeTranslationKey(string $key) : string
Parameters
- $key : string
-
Key to sanitize
Return values
string —Sanitized key
translateString()
Get translation for a string
protected
translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
- $rawStr : string
-
String to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $domain : string = 'default'
-
Text domain (omit for default)
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?