ITags
in
Class for easily tagging objects by their id
A tag can be e.g. 'Family', 'Work', 'Chore', 'Special Occation' or anything else that is either parsed from a vobject or that the user chooses to add. Tag names are not case-sensitive, but will be saved with the case they are entered in. If a user already has a tag 'family' for a type, and tries to add a tag named 'Family' it will be silently ignored.
Tags
Table of Contents
Constants
- TAG_FAVORITE = '_$!<Favorite>!$_'
Methods
- add() : int|false
- Add a new tag.
- addMultiple() : bool
- Add a list of new tags.
- addToFavorites() : bool
- Add an object to favorites
- delete() : bool
- Delete tags from the database
- getFavorites() : array<string|int, mixed>|false
- Get favorites for an object type
- getIdsForTag() : array<string|int, mixed>|false
- Get a list of items tagged with $tag.
- getTag() : array<string|int, mixed>|false
- Returns an array mapping a given tag's properties to its values: ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
- getTags() : array<string|int, array{id: int, name: string}>
- Get the tags for a specific user.
- getTagsForObjects() : array<int, array<int, string>>|false
- Get a list of tags for the given item ids.
- hasTag() : bool
- Checks whether a tag is already saved.
- isEmpty() : bool
- Check if any tags are saved for this type and user.
- purgeObjects() : bool
- Delete tag/object relations from the db
- removeFromFavorites() : bool
- Remove an object from favorites
- rename() : bool
- Rename tag.
- tagAs() : bool
- Creates a tag/object relation.
- unTag() : bool
- Delete single tag/object relation from the db
- userHasTag() : bool
- Checks whether a tag is saved for the given user, disregarding the ones shared with them.
Constants
TAG_FAVORITE
public
mixed
TAG_FAVORITE
= '_$!<Favorite>!$_'
Tags
Methods
add()
Add a new tag.
public
add(string $name) : int|false
Parameters
- $name : string
-
A string with a name of the tag
Tags
Return values
int|false —the id of the added tag or false if it already exists.
addMultiple()
Add a list of new tags.
public
addMultiple(string|array<string|int, string> $names[, bool $sync = false ][, int|null $id = null ]) : bool
Parameters
- $names : string|array<string|int, string>
-
A string with a name or an array of strings containing the name(s) of the to add.
- $sync : bool = false
-
When true, save the tags
- $id : int|null = null
-
int Optional object id to add to this|these tag(s)
Tags
Return values
bool —Returns false on error.
addToFavorites()
Add an object to favorites
public
addToFavorites(int $objid) : bool
Parameters
- $objid : int
-
The id of the object
Tags
Return values
booldelete()
Delete tags from the database
public
delete(array<string|int, string>|array<string|int, int> $names) : bool
Parameters
- $names : array<string|int, string>|array<string|int, int>
-
An array of tags (names or IDs) to delete
Tags
Return values
bool —Returns false on error
getFavorites()
Get favorites for an object type
public
getFavorites() : array<string|int, mixed>|false
Tags
Return values
array<string|int, mixed>|false —An array of object ids.
getIdsForTag()
Get a list of items tagged with $tag.
public
getIdsForTag(string|int $tag) : array<string|int, mixed>|false
Throws an exception if the tag could not be found.
Parameters
- $tag : string|int
-
Tag id or name.
Tags
Return values
array<string|int, mixed>|false —An array of object ids or false on error.
getTag()
Returns an array mapping a given tag's properties to its values: ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
public
getTag(string $id) : array<string|int, mixed>|false
Parameters
- $id : string
-
The ID of the tag that is going to be mapped
Tags
Return values
array<string|int, mixed>|falsegetTags()
Get the tags for a specific user.
public
getTags() : array<string|int, array{id: int, name: string}>
This returns an array with id/name maps:
[
['id' => 0, 'name' = 'First tag'],
['id' => 1, 'name' = 'Second tag'],
]
Tags
Return values
array<string|int, array{id: int, name: string}>getTagsForObjects()
Get a list of tags for the given item ids.
public
getTagsForObjects(array<int, int> $objIds) : array<int, array<int, string>>|false
This returns an array with object id / tag names:
[
1 => array('First tag', 'Second tag'),
2 => array('Second tag'),
3 => array('Second tag', 'Third tag'),
]
Parameters
- $objIds : array<int, int>
-
item ids
Tags
Return values
array<int, array<int, string>>|false —with object id as key and an array of tag names as value or false if an error occurred
hasTag()
Checks whether a tag is already saved.
public
hasTag(string $name) : bool
Parameters
- $name : string
-
The name to check for.
Tags
Return values
boolisEmpty()
Check if any tags are saved for this type and user.
public
isEmpty() : bool
Tags
Return values
boolpurgeObjects()
Delete tag/object relations from the db
public
purgeObjects(array<string|int, mixed> $ids) : bool
Parameters
- $ids : array<string|int, mixed>
-
The ids of the objects
Tags
Return values
bool —Returns false on error.
removeFromFavorites()
Remove an object from favorites
public
removeFromFavorites(int $objid) : bool
Parameters
- $objid : int
-
The id of the object
Tags
Return values
boolrename()
Rename tag.
public
rename(string|int $from, string $to) : bool
Parameters
- $from : string|int
-
The name or ID of the existing tag
- $to : string
-
The new name of the tag.
Tags
Return values
booltagAs()
Creates a tag/object relation.
public
tagAs(int $objid, string $tag) : bool
Parameters
- $objid : int
-
The id of the object
- $tag : string
-
The id or name of the tag
Tags
Return values
bool —Returns false on database error.
unTag()
Delete single tag/object relation from the db
public
unTag(int $objid, string $tag) : bool
Parameters
- $objid : int
-
The id of the object
- $tag : string
-
The id or name of the tag
Tags
Return values
booluserHasTag()
Checks whether a tag is saved for the given user, disregarding the ones shared with them.
public
userHasTag(string $name, string $user) : bool
Parameters
- $name : string
-
The tag name to check for.
- $user : string
-
The user whose tags are to be checked.