original_string: public static function count_templates($competencyid, $onlyvisible) {
          global $DB;
  
          $sql = 'SELECT COUNT(tpl.id)
                    FROM {' . self::TABLE . '} tplcomp
                    JOIN {' . template::TABLE . '} tpl
                      ON tplcomp.templateid = tpl.id
                   WHERE tplcomp.competencyid = ? ';
          $params = array($competencyid);
  
          if ($onlyvisible) {
              $sql .= ' AND tpl.visible = ?';
              $params[] = 1;
          }
  
          $results = $DB->count_records_sql($sql, $params);
  
          return $results;
      }
code: public static function count_templates($competencyid, $onlyvisible) {
          global $DB;
  
          $sql = 'SELECT COUNT(tpl.id)
                    FROM {' . self::TABLE . '} tplcomp
                    JOIN {' . template::TABLE . '} tpl
                      ON tplcomp.templateid = tpl.id
                   WHERE tplcomp.competencyid = ? ';
          $params = array($competencyid);
  
          if ($onlyvisible) {
              $sql .= ' AND tpl.visible = ?';
              $params[] = 1;
          }
  
          $results = $DB->count_records_sql($sql, $params);
  
          return $results;
      }
code_tokens: public static function count_templates ( $ competencyid , $ onlyvisible ) { global $ DB ; $ sql = 'SELECT COUNT(tpl.id)
                    FROM {' . self :: TABLE . '} tplcomp
                    JOIN {' . template :: TABLE . '} tpl
                      ON tplcomp.templateid = tpl.id
                   WHERE tplcomp.competencyid = ? ' ; $ params = array ( $ competencyid ) ; if ( $ onlyvisible ) { $ sql .= ' AND tpl.visible = ?' ; $ params [ ] = 1 ; } $ results = $ DB -> count_records_sql ( $ sql , $ params ) ; return $ results ; }
docstring: Count the templates using a competency.
  
  @param int $competencyid The competency id
  @param bool $onlyvisible If true, only count visible templates using this competency.
  @return int
docstring_tokens: Count the templates using a competency .