Back to TagsHelper class

Method getItemTags

public array
getItemTags
(mixed $contentType, mixed $id, mixed $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.
  • int $id Id of the item to retrieve tags for.
  • bool $getTagData If true, data from the tags table will be included, defaults to true.
Returns
  • array Array of of tag objects
Since
  • 3.1
Class: TagsHelper
Project: Joomla

Method getItemTags - Source code

/**
 * Method to get a list of tags for an item, optionally with the tag data.
 *
 * @param   string   $contentType  Content type alias. Dot separated.
 * @param   integer  $id           Id of the item to retrieve tags for.
 * @param   boolean  $getTagData   If true, data from the tags table will be included, defaults to true.
 *
 * @return  array    Array of of tag objects
 *
 * @since   3.1
 */
public function getItemTags($contentType, $id, $getTagData = true)
{
    // Cast as integer until method is typehinted.
    $id = (int) $id;
    // Initialize some variables.
    $db = Factory::getDbo();
    $query = $db->getQuery(true)->select($db->quoteName('m.tag_id'))->from($db->quoteName('#__contentitem_tag_map', 'm'))->where([$db->quoteName('m.type_alias') . ' = :contentType', $db->quoteName('m.content_item_id') . ' = :id', $db->quoteName('t.published') . ' = 1'])->bind(':contentType', $contentType)->bind(':id', $id, ParameterType::INTEGER);
    $user = Factory::getUser();
    $groups = $user->getAuthorisedViewLevels();
    $query->whereIn($db->quoteName('t.access'), $groups);
    // Optionally filter on language
    $language = ComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');
    if ($language !== 'all') {
        if ($language === 'current_language') {
            $language = $this->getCurrentLanguage();
        }
        $query->whereIn($db->quoteName('language'), [$language, '*'], ParameterType::STRING);
    }
    if ($getTagData) {
        $query->select($db->quoteName('t') . '.*');
    }
    $query->join('INNER', $db->quoteName('#__tags', 't'), $db->quoteName('m.tag_id') . ' = ' . $db->quoteName('t.id'));
    $db->setQuery($query);
    $this->itemTags = $db->loadObjectList();
    return $this->itemTags;
}