public static function is_item_tagged_with($component, $itemtype, $itemid, $tagname) {
        global $DB;
        $tagcollid = core_tag_area::get_collection($component, $itemtype);
        $query = 'SELECT 1 FROM {tag} t
                    JOIN {tag_instance} ti ON ti.tagid = t.id
                    WHERE t.name = ? AND t.tagcollid = ? AND ti.itemtype = ? AND ti.itemid = ?';
        $cleanname = core_text::strtolower(clean_param($tagname, PARAM_TAG));
        $params = array($cleanname, $tagcollid, $itemtype, $itemid);
        if ($component) {
            $query .= ' AND ti.component = ?';
            $params[] = $component;
        }
        return $DB->record_exists_sql($query, $params) ? 1 : 0;
    }
public static function is_item_tagged_with($component, $itemtype, $itemid, $tagname) {
        global $DB;
        $tagcollid = core_tag_area::get_collection($component, $itemtype);
        $query = 'SELECT 1 FROM {tag} t
                    JOIN {tag_instance} ti ON ti.tagid = t.id
                    WHERE t.name = ? AND t.tagcollid = ? AND ti.itemtype = ? AND ti.itemid = ?';
        $cleanname = core_text::strtolower(clean_param($tagname, PARAM_TAG));
        $params = array($cleanname, $tagcollid, $itemtype, $itemid);
        if ($component) {
            $query .= ' AND ti.component = ?';
            $params[] = $component;
        }
        return $DB->record_exists_sql($query, $params) ? 1 : 0;
    }
public static function is_item_tagged_with ( $ component , $ itemtype , $ itemid , $ tagname ) { global $ DB ; $ tagcollid = core_tag_area :: get_collection ( $ component , $ itemtype ) ; $ query = 'SELECT 1 FROM {tag} t
                    JOIN {tag_instance} ti ON ti.tagid = t.id
                    WHERE t.name = ? AND t.tagcollid = ? AND ti.itemtype = ? AND ti.itemid = ?' ; $ cleanname = core_text :: strtolower ( clean_param ( $ tagname , PARAM_TAG ) ) ; $ params = array ( $ cleanname , $ tagcollid , $ itemtype , $ itemid ) ; if ( $ component ) { $ query .= ' AND ti.component = ?' ; $ params [ ] = $ component ; } return $ DB -> record_exists_sql ( $ query , $ params ) ? 1 : 0 ; }
Determine if an item is tagged with a specific tag

Note that this is a static method and not a method of core_tag object because the tag might not exist yet,
for example user searches for "php" and we offer him to add "php" to his interests.

@param   string   $component component responsible for tagging. For BC it can be empty but in this case the
query will be slow because DB index will not be used.
@param   string   $itemtype    the record type to look for
@param   int      $itemid      the record id to look for
@param   string   $tagname     a tag name
@return  int                   1 if it is tagged, 0 otherwise
Determine if an item is tagged with a specific tag