class TagsHelper extends CMSHelper

Tags helper class, provides methods to perform various tasks relevant tagging of content.

Properties

string $typeAlias Alias for querying mapping and content type table.

Methods

string
getCurrentLanguage( boolean $detectBrowser = true)

Gets the current language

from CMSHelper
integer
getLanguageId( string $langCode)

Gets the associated language ID

from CMSHelper
array
getRowData( TableInterface $table)

Gets a row of data from a table

from CMSHelper
getDataObject( TableInterface $table)

Method to get an object containing all of the table columns and values.

from CMSHelper
boolean
addTagMapping( integer $ucmId, TableInterface $table, array $tags = array())

Method to add tag rows to mapping table.

static  array
convertPathsToNames( array $tags)

Function that converts tags paths into paths of names

mixed
createTagsFromField( array $tags)

Create any new tags by looking for #new# in the strings

mixed
createTagsFromMetadata( string $metadata)

Create any new tags by looking for #new# in the metadata

boolean
deleteTagData( TableInterface $table, integer|array $contentItemId)

Method to delete the tag mappings and #__ucm_content record for for an item

array
getItemTags( string $contentType, integer $id, boolean $getTagData = true)

Method to get a list of tags for an item, optionally with the tag data.

string
getTagIds( mixed $ids, string $prefix)

Method to get a list of tags for a given item.

getTagItemsQuery( mixed $tagId, mixed $typesr = null, boolean $includeChildren = false, string $orderByOption = 'c.core_title', string $orderDir = 'ASC', boolean $anyOrAll = true, string $languageFilter = 'all', string $stateFilter = '0,1')

Method to get a query to retrieve a detailed list of items for a tag.

array
getTagNames( array $tagIds)

Function that converts tag ids to their tag names

mixed
getTagTreeArray( integer $id, array $tagTreeArray = array())

Method to get an array of tag ids for the current tag and its children

string
getTypeId( string $typeAlias)

Method to get the type id for a type alias.

static  array
getTypes( string $arrayType = 'objectList', array $selectTypes = null, boolean $useAlias = true)

Method to get a list of types with associated data.

boolean
postStoreProcess( TableInterface $table, array $newTags = array(), boolean $replace = true)

Function that handles saving tags used in a table class after a store()

null
preStoreProcess( TableInterface $table, array $newTags = array())

Function that preProcesses data from a table prior to a store() to ensure proper tag handling

static  array
searchTags( array $filters = array())

Function to search tags

void
tagDeleteInstances( integer $tag_id)

Method to delete all instances of a tag from the mapping table. Generally used when a tag is deleted.

boolean
tagItem( integer $ucmId, TableInterface $table, array $tags = array(), boolean $replace = true)

Method to add or update tags associated with an item.

boolean
unTagItem( integer $contentId, TableInterface $table, array $tags = array())

Method to untag an item

Details

string getCurrentLanguage( boolean $detectBrowser = true)

Gets the current language

Parameters

boolean $detectBrowser Flag indicating whether to use the browser language as a fallback.

Return Value

string The language string

integer getLanguageId( string $langCode)

Gets the associated language ID

Parameters

string $langCode The language code to look up

Return Value

integer The language ID

array getRowData( TableInterface $table)

Gets a row of data from a table

Parameters

TableInterface $table Table instance for a row.

Return Value

array Associative array of all columns and values for a row in a table.

stdClass getDataObject( TableInterface $table)

Method to get an object containing all of the table columns and values.

Parameters

TableInterface $table Table object.

Return Value

stdClass Contains all of the columns and values.

boolean addTagMapping( integer $ucmId, TableInterface $table, array $tags = array())

Method to add tag rows to mapping table.

Parameters

integer $ucmId ID of the #__ucm_content item being tagged
TableInterface $table Table object being tagged
array $tags Array of tags to be applied.

Return Value

boolean true on success, otherwise false.

static array convertPathsToNames( array $tags)

Function that converts tags paths into paths of names

Parameters

array $tags Array of tags

Return Value

array

mixed createTagsFromField( array $tags)

Create any new tags by looking for #new# in the strings

Parameters

array $tags Tags text array from the field

Return Value

mixed If successful, metadata with new tag titles replaced by tag ids. Otherwise false.

mixed createTagsFromMetadata( string $metadata)

Create any new tags by looking for #new# in the metadata

Parameters

string $metadata Metadata JSON string

Return Value

mixed If successful, metadata with new tag titles replaced by tag ids. Otherwise false.

boolean deleteTagData( TableInterface $table, integer|array $contentItemId)

Method to delete the tag mappings and #__ucm_content record for for an item

Parameters

TableInterface $table Table object of content table where delete occurred
integer|array $contentItemId ID of the content item. Or an array of key/value pairs with array key being a primary key name and value being the content item ID. Note multiple primary keys are not supported

Return Value

boolean true on success, false on failure

Exceptions

InvalidArgumentException

array getItemTags( string $contentType, integer $id, boolean $getTagData = true)

Method to get a list of tags for an item, optionally with the tag data.

Parameters

string $contentType Content type alias. Dot separated.
integer $id Id of the item to retrieve tags for.
boolean $getTagData If true, data from the tags table will be included, defaults to true.

Return Value

array Array of of tag objects

string getTagIds( mixed $ids, string $prefix)

Method to get a list of tags for a given item.

Normally used for displaying a list of tags within a layout

Parameters

mixed $ids The id or array of ids (primary key) of the item to be tagged.
string $prefix Dot separated string with the option and view to be used for a url.

Return Value

string Comma separated list of tag Ids.

JDatabaseQuery getTagItemsQuery( mixed $tagId, mixed $typesr = null, boolean $includeChildren = false, string $orderByOption = 'c.core_title', string $orderDir = 'ASC', boolean $anyOrAll = true, string $languageFilter = 'all', string $stateFilter = '0,1')

Method to get a query to retrieve a detailed list of items for a tag.

Parameters

mixed $tagId Tag or array of tags to be matched
mixed $typesr Null, type or array of type aliases for content types to be included in the results
boolean $includeChildren True to include the results from child tags
string $orderByOption Column to order the results by
string $orderDir Direction to sort the results in
boolean $anyOrAll True to include items matching at least one tag, false to include items all tags in the array.
string $languageFilter Optional filter on language. Options are 'all', 'current' or any string.
string $stateFilter Optional filtering on publication state, defaults to published or unpublished.

Return Value

JDatabaseQuery Query to retrieve a list of tags

array getTagNames( array $tagIds)

Function that converts tag ids to their tag names

Parameters

array $tagIds Array of integer tag ids.

Return Value

array An array of tag names.

mixed getTagTreeArray( integer $id, array $tagTreeArray = array())

Method to get an array of tag ids for the current tag and its children

Parameters

integer $id An optional ID
array $tagTreeArray &$tagTreeArray Array containing the tag tree

Return Value

mixed

string getTypeId( string $typeAlias)

Method to get the type id for a type alias.

Parameters

string $typeAlias A type alias.

Return Value

string Name of the table for a type

static array getTypes( string $arrayType = 'objectList', array $selectTypes = null, boolean $useAlias = true)

Method to get a list of types with associated data.

Parameters

string $arrayType Optionally specify that the returned list consist of objects, associative arrays, or arrays. Options are: rowList, assocList, and objectList
array $selectTypes Optional array of type ids to limit the results to. Often from a request.
boolean $useAlias If true, the alias is used to match, if false the type_id is used.

Return Value

array Array of of types

boolean postStoreProcess( TableInterface $table, array $newTags = array(), boolean $replace = true)

Function that handles saving tags used in a table class after a store()

Parameters

TableInterface $table Table being processed
array $newTags Array of new tags
boolean $replace Flag indicating if all exising tags should be replaced

Return Value

boolean

null preStoreProcess( TableInterface $table, array $newTags = array())

Function that preProcesses data from a table prior to a store() to ensure proper tag handling

Parameters

TableInterface $table Table being processed
array $newTags Array of new tags

Return Value

null

static array searchTags( array $filters = array())

Function to search tags

Parameters

array $filters Filter to apply to the search

Return Value

array

void tagDeleteInstances( integer $tag_id)

Method to delete all instances of a tag from the mapping table. Generally used when a tag is deleted.

Parameters

integer $tag_id The tag_id (primary key) for the deleted tag.

Return Value

void

boolean tagItem( integer $ucmId, TableInterface $table, array $tags = array(), boolean $replace = true)

Method to add or update tags associated with an item.

Parameters

integer $ucmId Id of the #__ucm_content item being tagged
TableInterface $table Table object being tagged
array $tags Array of tags to be applied.
boolean $replace Flag indicating if all exising tags should be replaced

Return Value

boolean true on success, otherwise false.

boolean unTagItem( integer $contentId, TableInterface $table, array $tags = array())

Method to untag an item

Parameters

integer $contentId ID of the content item being untagged
TableInterface $table Table object being untagged
array $tags Array of tags to be untagged. Use an empty array to untag all existing tags.

Return Value

boolean true on success, otherwise false.