public function count_tagged_items($component, $itemtype, $subquery = '', $params = array()) {
        global $DB;

        if (empty($itemtype) || !$DB->get_manager()->table_exists($itemtype)) {
            return 0;
        }
        $params = $params ? $params : array();

        $query = "SELECT COUNT(it.id)
                    FROM {".$itemtype."} it INNER JOIN {tag_instance} tt ON it.id = tt.itemid
                   WHERE tt.itemtype = :itemtype AND tt.tagid = :tagid";
        $params['itemtype'] = $itemtype;
        $params['tagid'] = $this->id;
        if ($component) {
            $query .= ' AND tt.component = :component';
            $params['component'] = $component;
        }
        if ($subquery) {
            $query .= ' AND ' . $subquery;
        }

        return $DB->get_field_sql($query, $params);
    }
public function count_tagged_items($component, $itemtype, $subquery = '', $params = array()) {
        global $DB;

        if (empty($itemtype) || !$DB->get_manager()->table_exists($itemtype)) {
            return 0;
        }
        $params = $params ? $params : array();

        $query = "SELECT COUNT(it.id)
                    FROM {".$itemtype."} it INNER JOIN {tag_instance} tt ON it.id = tt.itemid
                   WHERE tt.itemtype = :itemtype AND tt.tagid = :tagid";
        $params['itemtype'] = $itemtype;
        $params['tagid'] = $this->id;
        if ($component) {
            $query .= ' AND tt.component = :component';
            $params['component'] = $component;
        }
        if ($subquery) {
            $query .= ' AND ' . $subquery;
        }

        return $DB->get_field_sql($query, $params);
    }
public function count_tagged_items ( $ component , $ itemtype , $ subquery = '' , $ params = array ( ) ) { global $ DB ; if ( empty ( $ itemtype ) || ! $ DB -> get_manager ( ) -> table_exists ( $ itemtype ) ) { return 0 ; } $ params = $ params ? $ params : array ( ) ; $ query = "SELECT COUNT(it.id)
                    FROM {" . $ itemtype . "} it INNER JOIN {tag_instance} tt ON it.id = tt.itemid
                   WHERE tt.itemtype = :itemtype AND tt.tagid = :tagid" ; $ params [ 'itemtype' ] = $ itemtype ; $ params [ 'tagid' ] = $ this -> id ; if ( $ component ) { $ query .= ' AND tt.component = :component' ; $ params [ 'component' ] = $ component ; } if ( $ subquery ) { $ query .= ' AND ' . $ subquery ; } return $ DB -> get_field_sql ( $ query , $ params ) ; }
Count how many items are tagged with a specific tag.

@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  type to restrict search to
@param    string   $subquery additional query to be appended to WHERE clause, refer to the itemtable as 'it'
@param    array    $params additional parameters for the DB query
@return   int      number of mathing tags.
Count how many items are tagged with a specific tag .