PHP Class Content_Tagger, horde

Show file Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_db Horde_Db_Adapter Database connection
$_defaultRadius integer Default radius for relationship queries.
$_objectManager Content_Objects_Manager Object manager
$_tables array Tables
$_typeManager Content_Types_Manager Type management object
$_userManager Content_Users_Manager User manager object

Public Methods

Method Description
__construct ( Horde_Db_Adapter $db, Content_Users_Manager $userManager, Content_Types_Manager $typeManager, Content_Objects_Manager $objectManager ) Constructor
browseTags ( array $ids, $object_type, string $user ) : array Retrieve a set of tags with relationships to the specified set of tags.
ensureTags ( array $tags ) : array Ensure that an array of tags exist, create any that don't, and return ids for all of them.
getObjects ( array $args ) : array Get objects matching search criteria.
getRecentObjects ( array $args = [] ) : array Get the most recently tagged objects.
getRecentTags ( array $args = [] ) : array Get the most recently used tags.
getRecentUsers ( array $args = [] ) : array Get the users who have most recently tagged objects.
getSimilarObjects ( mixed $object_id, array $args = [] ) : array Return objects related to the given object via tags, along with a similarity rank.
getSimilarUsers ( $args ) Return users related to a given user along with a similarity rank.
getTagCloud ( array $args = [] ) : array Generate a tag cloud. Same syntax as getTags, except that fetching a cloud for a userId + objectId combination doesn't make sense - the counts would all be one. In addition, this method returns counts for each tag.
getTagIds ( $tags )
getTags ( array $args ) : array Retrieve tags based on criteria.
getTagsByObjects ( $objects, mixed $type ) : array Obtain all the tags for a given set of objects.
getUsers ( $args ) Find users through objects, tags, or other users.
removeTagFromObject ( $objectId, mixed $tags ) : void Remove all occurrences of a specific tag from an object regardless of the username who tagged the object originally.
splitTags ( string $text ) : array Split a string into an array of tag names, respecting tags with spaces and ones that are quoted in some way. For example: this, "somecompany, llc", "and ""this"" w,o.rks", foo bar
tag ( mixed $userId, mixed $objectId, array $tags, Horde_Date $created = null ) : void Adds a tag or several tags to an object_id. This method does not remove other tags.
toDriver ( $value )
untag ( mixed $userId, mixed $objectId, array $tags ) Undo a user's tagging of an object.

Protected Methods

Method Description
_checkTags ( string | array $tags, boolean $create = true ) : array Check if tags exists, optionally create them if they don't and return ids for all that exist (including those that are optionally created).
_ensureObject ( $object ) Convenience method - if $object is an array, it is taken as an array of 'object' and 'type' to pass to objectManager::ensureObjects() if it's a scalar value, it's taken as the object_id and simply returned.
_t ( string $tableType ) : string Shortcut for getting a table name.

Method Details

__construct() public method

Constructor
public __construct ( Horde_Db_Adapter $db, Content_Users_Manager $userManager, Content_Types_Manager $typeManager, Content_Objects_Manager $objectManager )
$db Horde_Db_Adapter
$userManager Content_Users_Manager
$typeManager Content_Types_Manager
$objectManager Content_Objects_Manager

_checkTags() protected method

Check if tags exists, optionally create them if they don't and return ids for all that exist (including those that are optionally created).
protected _checkTags ( string | array $tags, boolean $create = true ) : array
$tags string | array The tag names to check.
$create boolean If true, create the tag in the tags table.
return array A hash of tag_name => tag_id values.

_ensureObject() protected method

Convenience method - if $object is an array, it is taken as an array of 'object' and 'type' to pass to objectManager::ensureObjects() if it's a scalar value, it's taken as the object_id and simply returned.
protected _ensureObject ( $object )

_t() protected method

Shortcut for getting a table name.
protected _t ( string $tableType ) : string
$tableType string
return string Configured table name.

browseTags() public method

Retrieve a set of tags with relationships to the specified set of tags.
public browseTags ( array $ids, $object_type, string $user ) : array
$ids array An array of tag_ids.
$user string The user to limit to.
return array A hash of tag_id -> tag_name

ensureTags() public method

Ensure that an array of tags exist, create any that don't, and return ids for all of them.
public ensureTags ( array $tags ) : array
$tags array Array of tag names or ids.
return array Hash of tag_name => tag_id values.

getObjects() public method

Get objects matching search criteria.
public getObjects ( array $args ) : array
$args array Search criteria: limit Maximum number of objects to return. offset Offset the results. Only useful for paginating, and not recommended. tagId Return objects related through one or more tags. notTagId Don't return objects tagged with one or more tags. typeId Only return objects with a specific type. objectId Return objects with the same tags as $objectId. userId Limit results to objects tagged by a specific user. radius Radius setting for relationship queries e.g., objectId
return array An array of object ids.

getRecentObjects() public method

Get the most recently tagged objects.
public getRecentObjects ( array $args = [] ) : array
$args array Search criteria: limit Maximum number of objects to return. offset Offset the results. Only useful for paginating, and not recommended. userId Only return objects that have been tagged by a specific user. typeId Only return objects of a specific object type.
return array

getRecentTags() public method

Get the most recently used tags.
public getRecentTags ( array $args = [] ) : array
$args array Search criteria: limit Maximum number of tags to return. offset Offset the results. Only useful for paginating, and not recommended. userId Only return tags that have been used by a specific user. typeId Only return tags applied to objects of a specific type.
return array

getRecentUsers() public method

Get the users who have most recently tagged objects.
public getRecentUsers ( array $args = [] ) : array
$args array Search criteria: limit Maximum number of users to return. offset Offset the results. Only useful for paginating, and not recommended. typeId Only return users who have tagged objects of a specific object type.
return array

getSimilarObjects() public method

Return objects related to the given object via tags, along with a similarity rank.
public getSimilarObjects ( mixed $object_id, array $args = [] ) : array
$object_id mixed The object to find relations for.
$args array limit Maximum number of objects to return (default 10). userId Only return objects that have been tagged by a specific user. typeId Only return objects of a specific type. threshold Number of tags-in-common objects must have to match (default 1).
return array An array of (client) object ids => similarity rank

getSimilarUsers() public method

Return users related to a given user along with a similarity rank.
public getSimilarUsers ( $args )

getTagCloud() public method

Generate a tag cloud. Same syntax as getTags, except that fetching a cloud for a userId + objectId combination doesn't make sense - the counts would all be one. In addition, this method returns counts for each tag.
public getTagCloud ( array $args = [] ) : array
$args array Search criteria: - limit: (integer) Maximum number of tags to return. - offset: (integet) Offset the results. Only useful for paginating, and not recommended. - userId: (string) Only return tags that have been applied by a specific user. - typeId: (array) Only return tags that have been applied by specific object types. - objectId: (array) Only return tags that have been applied to specific objects all objects must be of the same type and specified by typeId. - tagIds: (array) Only return information on specific tag (an array of tag ids).
return array An array of hashes, each containing tag_id, tag_name, and count.

getTagIds() public method

public getTagIds ( $tags )

getTags() public method

Retrieve tags based on criteria.
public getTags ( array $args ) : array
$args array Search criteria: q Starts-with search on tag_name. limit Maximum number of tags to return. offset Offset the results. Only useful for paginating, and not recommended. userId Only return tags that have been applied by a specific user. typeId Only return tags that have been applied by a specific object type. objectId Only return tags that have been applied to a specific object.
return array An array of tags, id => name.

getTagsByObjects() public method

Obtain all the tags for a given set of objects.
public getTagsByObjects ( $objects, mixed $type ) : array
$type mixed Either a string type description, or an integer content type_id
return array An array in the form of:
     array('localobjectId' => array('tagone', 'tagtwo'),
           'anotherobjectid' => array('anothertag', 'yetanother'))

getUsers() public method

Find users through objects, tags, or other users.
public getUsers ( $args )

removeTagFromObject() public method

Remove all occurrences of a specific tag from an object regardless of the username who tagged the object originally.
public removeTagFromObject ( $objectId, mixed $tags ) : void
$tags mixed The tags to remove. @see Content_Tagger::tag()
return void

splitTags() public method

Would parse to: array('this', 'somecompany, llc', 'and "this" w,o.rks', 'foo bar')
public splitTags ( string $text ) : array
$text string String to split into 1 or more tags.
return array Split tag array.

tag() public method

Adds a tag or several tags to an object_id. This method does not remove other tags.
public tag ( mixed $userId, mixed $objectId, array $tags, Horde_Date $created = null ) : void
$userId mixed The user tagging the object.
$objectId mixed The object id to tag or an array containing the object_name and type.
$tags array An array of tag name or ids.
$created Horde_Date The datetime of the tagging operation.
return void

toDriver() public method

public toDriver ( $value )

untag() public method

Undo a user's tagging of an object.
public untag ( mixed $userId, mixed $objectId, array $tags )
$userId mixed The user who tagged the object.
$objectId mixed The object to remove the tag from.
$tags array An array of tag name or ids to remove.

Property Details

$_db protected property

Database connection
protected Horde_Db_Adapter $_db
return Horde_Db_Adapter

$_defaultRadius protected property

Default radius for relationship queries.
protected int $_defaultRadius
return integer

$_objectManager protected property

Object manager
protected Content_Objects_Manager $_objectManager
return Content_Objects_Manager

$_tables protected property

Tables
protected array $_tables
return array

$_typeManager protected property

Type management object
protected Content_Types_Manager $_typeManager
return Content_Types_Manager

$_userManager protected property

User manager object
protected Content_Users_Manager $_userManager
return Content_Users_Manager