\OCPITags

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.

Summary

Methods
Constants
isEmpty()
getTag()
getTags()
getTagsForObjects()
getIdsForTag()
hasTag()
userHasTag()
add()
rename()
addMultiple()
purgeObjects()
getFavorites()
addToFavorites()
removeFromFavorites()
tagAs()
unTag()
delete()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

isEmpty()

isEmpty() : boolean

Check if any tags are saved for this type and user.

Returns

boolean

getTag()

getTag(string  $id) : array|false

Returns an array mapping a given tag's properties to its values: ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']

Parameters

string $id

The ID of the tag that is going to be mapped

Returns

array|false

getTags()

getTags() : array

Get the tags for a specific user.

This returns an array with id/name maps: [ ['id' => 0, 'name' = 'First tag'], ['id' => 1, 'name' = 'Second tag'], ]

Returns

array

getTagsForObjects()

getTagsForObjects(array  $objIds) : array|boolean

Get a list of tags for the given item ids.

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

array $objIds

item ids

Returns

array|boolean —

with object id as key and an array of tag names as value or false if an error occurred

getIdsForTag()

getIdsForTag(string|integer  $tag) : array|false

Get a list of items tagged with $tag.

Throws an exception if the tag could not be found.

Parameters

string|integer $tag

Tag id or name.

Returns

array|false —

An array of object ids or false on error.

hasTag()

hasTag(string  $name) : boolean

Checks whether a tag is already saved.

Parameters

string $name

The name to check for.

Returns

boolean

userHasTag()

userHasTag(string  $name, string  $user) : boolean

Checks whether a tag is saved for the given user, disregarding the ones shared with him or her.

Parameters

string $name

The tag name to check for.

string $user

The user whose tags are to be checked.

Returns

boolean

add()

add(string  $name) : integer|false

Add a new tag.

Parameters

string $name

A string with a name of the tag

Returns

integer|false —

the id of the added tag or false if it already exists.

rename()

rename(string|integer  $from, string  $to) : boolean

Rename tag.

Parameters

string|integer $from

The name or ID of the existing tag

string $to

The new name of the tag.

Returns

boolean

addMultiple()

addMultiple(array<mixed,string>  $names, boolean  $sync = false, integer|null  $id = null) : boolean

Add a list of new tags.

Parameters

array<mixed,string> $names

A string with a name or an array of strings containing the name(s) of the to add.

boolean $sync

When true, save the tags

integer|null $id

int Optional object id to add to this|these tag(s)

Returns

boolean —

Returns false on error.

purgeObjects()

purgeObjects(array  $ids) : boolean

Delete tag/object relations from the db

Parameters

array $ids

The ids of the objects

Returns

boolean —

Returns false on error.

getFavorites()

getFavorites() : array|false

Get favorites for an object type

Returns

array|false —

An array of object ids.

addToFavorites()

addToFavorites(integer  $objid) : boolean

Add an object to favorites

Parameters

integer $objid

The id of the object

Returns

boolean

removeFromFavorites()

removeFromFavorites(integer  $objid) : boolean

Remove an object from favorites

Parameters

integer $objid

The id of the object

Returns

boolean

tagAs()

tagAs(integer  $objid, string  $tag) : boolean

Creates a tag/object relation.

Parameters

integer $objid

The id of the object

string $tag

The id or name of the tag

Returns

boolean —

Returns false on database error.

unTag()

unTag(integer  $objid, string  $tag) : boolean

Delete single tag/object relation from the db

Parameters

integer $objid

The id of the object

string $tag

The id or name of the tag

Returns

boolean

delete()

delete(array<mixed,string>|array<mixed,integer>  $names) : boolean

Delete tags from the database

Parameters

array<mixed,string>|array<mixed,integer> $names

An array of tags (names or IDs) to delete

Returns

boolean —

Returns false on error