original_string: public static function list_user_competencies_in_course($courseid, $userid) {
          static::require_enabled();
          // First we do a permissions check.
          $context = context_course::instance($courseid);
          $onlyvisible = 1;
  
          $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
          if (!has_any_capability($capabilities, $context)) {
              throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
          } else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
              throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
          }
  
          // OK - all set.
          $competencylist = course_competency::list_competencies($courseid, false);
  
          $existing = user_competency_course::get_multiple($userid, $courseid, $competencylist);
          // Create missing.
          $orderedusercompetencycourses = array();
  
          $somemissing = false;
          foreach ($competencylist as $coursecompetency) {
              $found = false;
              foreach ($existing as $usercompetencycourse) {
                  if ($usercompetencycourse->get('competencyid') == $coursecompetency->get('id')) {
                      $found = true;
                      $orderedusercompetencycourses[$usercompetencycourse->get('id')] = $usercompetencycourse;
                      break;
                  }
              }
              if (!$found) {
                  $ucc = user_competency_course::create_relation($userid, $coursecompetency->get('id'), $courseid);
                  $ucc->create();
                  $orderedusercompetencycourses[$ucc->get('id')] = $ucc;
              }
          }
  
          return $orderedusercompetencycourses;
      }
code: public static function list_user_competencies_in_course($courseid, $userid) {
          static::require_enabled();
          // First we do a permissions check.
          $context = context_course::instance($courseid);
          $onlyvisible = 1;
  
          $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
          if (!has_any_capability($capabilities, $context)) {
              throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
          } else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
              throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
          }
  
          // OK - all set.
          $competencylist = course_competency::list_competencies($courseid, false);
  
          $existing = user_competency_course::get_multiple($userid, $courseid, $competencylist);
          // Create missing.
          $orderedusercompetencycourses = array();
  
          $somemissing = false;
          foreach ($competencylist as $coursecompetency) {
              $found = false;
              foreach ($existing as $usercompetencycourse) {
                  if ($usercompetencycourse->get('competencyid') == $coursecompetency->get('id')) {
                      $found = true;
                      $orderedusercompetencycourses[$usercompetencycourse->get('id')] = $usercompetencycourse;
                      break;
                  }
              }
              if (!$found) {
                  $ucc = user_competency_course::create_relation($userid, $coursecompetency->get('id'), $courseid);
                  $ucc->create();
                  $orderedusercompetencycourses[$ucc->get('id')] = $ucc;
              }
          }
  
          return $orderedusercompetencycourses;
      }
code_tokens: public static function list_user_competencies_in_course ( $ courseid , $ userid ) { static :: require_enabled ( ) ; // First we do a permissions check. $ context = context_course :: instance ( $ courseid ) ; $ onlyvisible = 1 ; $ capabilities = array ( 'moodle/competency:coursecompetencyview' , 'moodle/competency:coursecompetencymanage' ) ; if ( ! has_any_capability ( $ capabilities , $ context ) ) { throw new required_capability_exception ( $ context , 'moodle/competency:coursecompetencyview' , 'nopermissions' , '' ) ; } else if ( ! user_competency :: can_read_user_in_course ( $ userid , $ courseid ) ) { throw new required_capability_exception ( $ context , 'moodle/competency:usercompetencyview' , 'nopermissions' , '' ) ; } // OK - all set. $ competencylist = course_competency :: list_competencies ( $ courseid , false ) ; $ existing = user_competency_course :: get_multiple ( $ userid , $ courseid , $ competencylist ) ; // Create missing. $ orderedusercompetencycourses = array ( ) ; $ somemissing = false ; foreach ( $ competencylist as $ coursecompetency ) { $ found = false ; foreach ( $ existing as $ usercompetencycourse ) { if ( $ usercompetencycourse -> get ( 'competencyid' ) == $ coursecompetency -> get ( 'id' ) ) { $ found = true ; $ orderedusercompetencycourses [ $ usercompetencycourse -> get ( 'id' ) ] = $ usercompetencycourse ; break ; } } if ( ! $ found ) { $ ucc = user_competency_course :: create_relation ( $ userid , $ coursecompetency -> get ( 'id' ) , $ courseid ) ; $ ucc -> create ( ) ; $ orderedusercompetencycourses [ $ ucc -> get ( 'id' ) ] = $ ucc ; } } return $ orderedusercompetencycourses ; }
docstring: List all the user competencies in a course.
  
  @param int $courseid The id of the course to check.
  @param int $userid The id of the course to check.
  @return array of user_competency_course objects
docstring_tokens: List all the user competencies in a course .