original_string: public static function add_competency_to_course($courseid, $competencyid) {
          static::require_enabled();
          // Check the user have access to the course.
          self::validate_course($courseid);
  
          // First we do a permissions check.
          $context = context_course::instance($courseid);
  
          require_capability('moodle/competency:coursecompetencymanage', $context);
  
          $record = new stdClass();
          $record->courseid = $courseid;
          $record->competencyid = $competencyid;
  
          $competency = new competency($competencyid);
  
          // Can not add a competency that belong to a hidden framework.
          if ($competency->get_framework()->get('visible') == false) {
              throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
          }
  
          $coursecompetency = new course_competency();
          $exists = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyid));
          if (!$exists) {
              $coursecompetency->from_record($record);
              if ($coursecompetency->create()) {
                  return true;
              }
          }
          return false;
      }
code: public static function add_competency_to_course($courseid, $competencyid) {
          static::require_enabled();
          // Check the user have access to the course.
          self::validate_course($courseid);
  
          // First we do a permissions check.
          $context = context_course::instance($courseid);
  
          require_capability('moodle/competency:coursecompetencymanage', $context);
  
          $record = new stdClass();
          $record->courseid = $courseid;
          $record->competencyid = $competencyid;
  
          $competency = new competency($competencyid);
  
          // Can not add a competency that belong to a hidden framework.
          if ($competency->get_framework()->get('visible') == false) {
              throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
          }
  
          $coursecompetency = new course_competency();
          $exists = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyid));
          if (!$exists) {
              $coursecompetency->from_record($record);
              if ($coursecompetency->create()) {
                  return true;
              }
          }
          return false;
      }
code_tokens: public static function add_competency_to_course ( $ courseid , $ competencyid ) { static :: require_enabled ( ) ; // Check the user have access to the course. self :: validate_course ( $ courseid ) ; // First we do a permissions check. $ context = context_course :: instance ( $ courseid ) ; require_capability ( 'moodle/competency:coursecompetencymanage' , $ context ) ; $ record = new stdClass ( ) ; $ record -> courseid = $ courseid ; $ record -> competencyid = $ competencyid ; $ competency = new competency ( $ competencyid ) ; // Can not add a competency that belong to a hidden framework. if ( $ competency -> get_framework ( ) -> get ( 'visible' ) == false ) { throw new coding_exception ( 'A competency belonging to hidden framework can not be linked to course' ) ; } $ coursecompetency = new course_competency ( ) ; $ exists = $ coursecompetency -> get_records ( array ( 'courseid' => $ courseid , 'competencyid' => $ competencyid ) ) ; if ( ! $ exists ) { $ coursecompetency -> from_record ( $ record ) ; if ( $ coursecompetency -> create ( ) ) { return true ; } } return false ; }
docstring: Add a competency to this course.
  
  @param int $courseid The id of the course
  @param int $competencyid The id of the competency
  @return bool
docstring_tokens: Add a competency to this course .