original_string: public static function get_course_completion_status($courseid, $userid) {
          global $CFG, $USER;
          require_once($CFG->libdir . '/grouplib.php');
  
          $warnings = array();
          $arrayparams = array(
              'courseid' => $courseid,
              'userid'   => $userid,
          );
          $params = self::validate_parameters(self::get_course_completion_status_parameters(), $arrayparams);
  
          $course = get_course($params['courseid']);
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
          $context = context_course::instance($course->id);
          self::validate_context($context);
  
          // Can current user see user's course completion status?
          // This check verifies if completion is enabled because $course is mandatory.
          if (!completion_can_view_data($user->id, $course)) {
              throw new moodle_exception('cannotviewreport');
          }
  
          // The previous function doesn't check groups.
          if ($user->id != $USER->id) {
              if (!groups_user_groups_visible($course, $user->id)) {
                  // We are not in the same group!
                  throw new moodle_exception('accessdenied', 'admin');
              }
          }
  
          $info = new completion_info($course);
  
          // Check this user is enroled.
          if (!$info->is_tracked_user($user->id)) {
              if ($USER->id == $user->id) {
                  throw new moodle_exception('notenroled', 'completion');
              } else {
                  throw new moodle_exception('usernotenroled', 'completion');
              }
          }
  
          $completions = $info->get_completions($user->id);
          if (empty($completions)) {
              throw new moodle_exception('nocriteriaset', 'completion');
          }
  
          // Load course completion.
          $completionparams = array(
              'userid' => $user->id,
              'course' => $course->id,
          );
          $ccompletion = new completion_completion($completionparams);
  
          $completionrows = array();
          // Loop through course criteria.
          foreach ($completions as $completion) {
              $criteria = $completion->get_criteria();
  
              $completionrow = array();
              $completionrow['type'] = $criteria->criteriatype;
              $completionrow['title'] = $criteria->get_title();
              $completionrow['status'] = $completion->get_status();
              $completionrow['complete'] = $completion->is_complete();
              $completionrow['timecompleted'] = $completion->timecompleted;
              $completionrow['details'] = $criteria->get_details($completion);
              $completionrows[] = $completionrow;
          }
  
          $result = array(
                    'completed'   => $info->is_course_complete($user->id),
                    'aggregation' => $info->get_aggregation_method(),
                    'completions' => $completionrows
          );
  
          $results = array(
              'completionstatus' => $result,
              'warnings' => $warnings
          );
          return $results;
  
      }
code: public static function get_course_completion_status($courseid, $userid) {
          global $CFG, $USER;
          require_once($CFG->libdir . '/grouplib.php');
  
          $warnings = array();
          $arrayparams = array(
              'courseid' => $courseid,
              'userid'   => $userid,
          );
          $params = self::validate_parameters(self::get_course_completion_status_parameters(), $arrayparams);
  
          $course = get_course($params['courseid']);
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
          $context = context_course::instance($course->id);
          self::validate_context($context);
  
          // Can current user see user's course completion status?
          // This check verifies if completion is enabled because $course is mandatory.
          if (!completion_can_view_data($user->id, $course)) {
              throw new moodle_exception('cannotviewreport');
          }
  
          // The previous function doesn't check groups.
          if ($user->id != $USER->id) {
              if (!groups_user_groups_visible($course, $user->id)) {
                  // We are not in the same group!
                  throw new moodle_exception('accessdenied', 'admin');
              }
          }
  
          $info = new completion_info($course);
  
          // Check this user is enroled.
          if (!$info->is_tracked_user($user->id)) {
              if ($USER->id == $user->id) {
                  throw new moodle_exception('notenroled', 'completion');
              } else {
                  throw new moodle_exception('usernotenroled', 'completion');
              }
          }
  
          $completions = $info->get_completions($user->id);
          if (empty($completions)) {
              throw new moodle_exception('nocriteriaset', 'completion');
          }
  
          // Load course completion.
          $completionparams = array(
              'userid' => $user->id,
              'course' => $course->id,
          );
          $ccompletion = new completion_completion($completionparams);
  
          $completionrows = array();
          // Loop through course criteria.
          foreach ($completions as $completion) {
              $criteria = $completion->get_criteria();
  
              $completionrow = array();
              $completionrow['type'] = $criteria->criteriatype;
              $completionrow['title'] = $criteria->get_title();
              $completionrow['status'] = $completion->get_status();
              $completionrow['complete'] = $completion->is_complete();
              $completionrow['timecompleted'] = $completion->timecompleted;
              $completionrow['details'] = $criteria->get_details($completion);
              $completionrows[] = $completionrow;
          }
  
          $result = array(
                    'completed'   => $info->is_course_complete($user->id),
                    'aggregation' => $info->get_aggregation_method(),
                    'completions' => $completionrows
          );
  
          $results = array(
              'completionstatus' => $result,
              'warnings' => $warnings
          );
          return $results;
  
      }
code_tokens: public static function get_course_completion_status ( $ courseid , $ userid ) { global $ CFG , $ USER ; require_once ( $ CFG -> libdir . '/grouplib.php' ) ; $ warnings = array ( ) ; $ arrayparams = array ( 'courseid' => $ courseid , 'userid' => $ userid , ) ; $ params = self :: validate_parameters ( self :: get_course_completion_status_parameters ( ) , $ arrayparams ) ; $ course = get_course ( $ params [ 'courseid' ] ) ; $ user = core_user :: get_user ( $ params [ 'userid' ] , '*' , MUST_EXIST ) ; core_user :: require_active_user ( $ user ) ; $ context = context_course :: instance ( $ course -> id ) ; self :: validate_context ( $ context ) ; // Can current user see user's course completion status? // This check verifies if completion is enabled because $course is mandatory. if ( ! completion_can_view_data ( $ user -> id , $ course ) ) { throw new moodle_exception ( 'cannotviewreport' ) ; } // The previous function doesn't check groups. if ( $ user -> id != $ USER -> id ) { if ( ! groups_user_groups_visible ( $ course , $ user -> id ) ) { // We are not in the same group! throw new moodle_exception ( 'accessdenied' , 'admin' ) ; } } $ info = new completion_info ( $ course ) ; // Check this user is enroled. if ( ! $ info -> is_tracked_user ( $ user -> id ) ) { if ( $ USER -> id == $ user -> id ) { throw new moodle_exception ( 'notenroled' , 'completion' ) ; } else { throw new moodle_exception ( 'usernotenroled' , 'completion' ) ; } } $ completions = $ info -> get_completions ( $ user -> id ) ; if ( empty ( $ completions ) ) { throw new moodle_exception ( 'nocriteriaset' , 'completion' ) ; } // Load course completion. $ completionparams = array ( 'userid' => $ user -> id , 'course' => $ course -> id , ) ; $ ccompletion = new completion_completion ( $ completionparams ) ; $ completionrows = array ( ) ; // Loop through course criteria. foreach ( $ completions as $ completion ) { $ criteria = $ completion -> get_criteria ( ) ; $ completionrow = array ( ) ; $ completionrow [ 'type' ] = $ criteria -> criteriatype ; $ completionrow [ 'title' ] = $ criteria -> get_title ( ) ; $ completionrow [ 'status' ] = $ completion -> get_status ( ) ; $ completionrow [ 'complete' ] = $ completion -> is_complete ( ) ; $ completionrow [ 'timecompleted' ] = $ completion -> timecompleted ; $ completionrow [ 'details' ] = $ criteria -> get_details ( $ completion ) ; $ completionrows [ ] = $ completionrow ; } $ result = array ( 'completed' => $ info -> is_course_complete ( $ user -> id ) , 'aggregation' => $ info -> get_aggregation_method ( ) , 'completions' => $ completionrows ) ; $ results = array ( 'completionstatus' => $ result , 'warnings' => $ warnings ) ; return $ results ; }
docstring: Get Course completion status
  
  @param int $courseid ID of the Course
  @param int $userid ID of the User
  @return array of course completion status and warnings
  @since Moodle 2.9
  @throws moodle_exception
docstring_tokens: Get Course completion status