original_string: public static function count_courses_using_competency($competencyid) {
          static::require_enabled();
  
          // OK - all set.
          $courses = course_competency::list_courses_min($competencyid);
          $count = 0;
  
          // Now check permissions on each course.
          foreach ($courses as $course) {
              if (!self::validate_course($course, false)) {
                  continue;
              }
  
              $context = context_course::instance($course->id);
              $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
              if (!has_any_capability($capabilities, $context)) {
                  continue;
              }
  
              $count++;
          }
  
          return $count;
      }
code: public static function count_courses_using_competency($competencyid) {
          static::require_enabled();
  
          // OK - all set.
          $courses = course_competency::list_courses_min($competencyid);
          $count = 0;
  
          // Now check permissions on each course.
          foreach ($courses as $course) {
              if (!self::validate_course($course, false)) {
                  continue;
              }
  
              $context = context_course::instance($course->id);
              $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
              if (!has_any_capability($capabilities, $context)) {
                  continue;
              }
  
              $count++;
          }
  
          return $count;
      }
code_tokens: public static function count_courses_using_competency ( $ competencyid ) { static :: require_enabled ( ) ; // OK - all set. $ courses = course_competency :: list_courses_min ( $ competencyid ) ; $ count = 0 ; // Now check permissions on each course. foreach ( $ courses as $ course ) { if ( ! self :: validate_course ( $ course , false ) ) { continue ; } $ context = context_course :: instance ( $ course -> id ) ; $ capabilities = array ( 'moodle/competency:coursecompetencyview' , 'moodle/competency:coursecompetencymanage' ) ; if ( ! has_any_capability ( $ capabilities , $ context ) ) { continue ; } $ count ++ ; } return $ count ; }
docstring: Count all the courses using a competency.
  
  @param int $competencyid The id of the competency to check.
  @return int
docstring_tokens: Count all the courses using a competency .