Back to TagsHelper class

Method getTagIds

public string
getTagIds
(mixed $ids, mixed $prefix)
Method to get a list of tags for a given item.
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.
Returns
  • string Comma separated list of tag Ids.
Since
  • 3.1
Class: TagsHelper
Project: Joomla

Method getTagIds - Source code

/**
 * Method to get a list of tags for a given item.
 * Normally used for displaying a list of tags within a layout
 *
 * @param   mixed   $ids     The id or array of ids (primary key) of the item to be tagged.
 * @param   string  $prefix  Dot separated string with the option and view to be used for a url.
 *
 * @return  string   Comma separated list of tag Ids.
 *
 * @since   3.1
 */
public function getTagIds($ids, $prefix)
{
    if (empty($ids)) {
        return;
    }
    /**
     * Ids possible formats:
     * ---------------------
     * 	$id = 1;
     *  $id = array(1,2);
     *  $id = array('1,3,4,19');
     *  $id = '1,3';
     */
    $ids = (array) $ids;
    $ids = implode(',', $ids);
    $ids = explode(',', $ids);
    $ids = ArrayHelper::toInteger($ids);
    $db = Factory::getDbo();
    // Load the tags.
    $query = $db->getQuery(true)->select($db->quoteName('t.id'))->from($db->quoteName('#__tags', 't'))->join('INNER', $db->quoteName('#__contentitem_tag_map', 'm'), $db->quoteName('m.tag_id') . ' = ' . $db->quoteName('t.id'))->where($db->quoteName('m.type_alias') . ' = :prefix')->whereIn($db->quoteName('m.content_item_id'), $ids)->bind(':prefix', $prefix);
    $db->setQuery($query);
    // Add the tags to the content data.
    $tagsList = $db->loadColumn();
    $this->tags = implode(',', $tagsList);
    return $this->tags;
}