original_string: public static function count_competencies_with_no_courses($templateid) {
          global $DB;
  
          $sql = 'SELECT COUNT(comp.id)
                    FROM {' . self::TABLE . '} tplcomp
                    JOIN {' . competency::TABLE . '} comp
                      ON tplcomp.competencyid = comp.id
                    LEFT JOIN {' . course_competency::TABLE . '} crscomp
                      ON crscomp.competencyid = comp.id
                   WHERE tplcomp.templateid = ? AND crscomp.id IS NULL';
          $params = array($templateid);
  
          $results = $DB->count_records_sql($sql, $params);
  
          return $results;
      }
code: public static function count_competencies_with_no_courses($templateid) {
          global $DB;
  
          $sql = 'SELECT COUNT(comp.id)
                    FROM {' . self::TABLE . '} tplcomp
                    JOIN {' . competency::TABLE . '} comp
                      ON tplcomp.competencyid = comp.id
                    LEFT JOIN {' . course_competency::TABLE . '} crscomp
                      ON crscomp.competencyid = comp.id
                   WHERE tplcomp.templateid = ? AND crscomp.id IS NULL';
          $params = array($templateid);
  
          $results = $DB->count_records_sql($sql, $params);
  
          return $results;
      }
code_tokens: public static function count_competencies_with_no_courses ( $ templateid ) { global $ DB ; $ sql = 'SELECT COUNT(comp.id)
                    FROM {' . self :: TABLE . '} tplcomp
                    JOIN {' . competency :: TABLE . '} comp
                      ON tplcomp.competencyid = comp.id
                    LEFT JOIN {' . course_competency :: TABLE . '} crscomp
                      ON crscomp.competencyid = comp.id
                   WHERE tplcomp.templateid = ? AND crscomp.id IS NULL' ; $ params = array ( $ templateid ) ; $ results = $ DB -> count_records_sql ( $ sql , $ params ) ; return $ results ; }
docstring: Count the competencies in a template with no links to courses.
  
  @param int $templateid The template id
  @return int
docstring_tokens: Count the competencies in a template with no links to courses .