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;
    }