original_string: public static function get_user_attempts($quizid, $userid = 0, $status = 'finished', $includepreviews = false) {
          global $DB, $USER;
  
          $warnings = array();
  
          $params = array(
              'quizid' => $quizid,
              'userid' => $userid,
              'status' => $status,
              'includepreviews' => $includepreviews,
          );
          $params = self::validate_parameters(self::get_user_attempts_parameters(), $params);
  
          list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']);
  
          if (!in_array($params['status'], array('all', 'finished', 'unfinished'))) {
              throw new invalid_parameter_exception('Invalid status value');
          }
  
          // Default value for userid.
          if (empty($params['userid'])) {
              $params['userid'] = $USER->id;
          }
  
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
          // Extra checks so only users with permissions can view other users attempts.
          if ($USER->id != $user->id) {
              require_capability('mod/quiz:viewreports', $context);
          }
  
          $attempts = quiz_get_user_attempts($quiz->id, $user->id, $params['status'], $params['includepreviews']);
  
          $result = array();
          $result['attempts'] = $attempts;
          $result['warnings'] = $warnings;
          return $result;
      }
code: public static function get_user_attempts($quizid, $userid = 0, $status = 'finished', $includepreviews = false) {
          global $DB, $USER;
  
          $warnings = array();
  
          $params = array(
              'quizid' => $quizid,
              'userid' => $userid,
              'status' => $status,
              'includepreviews' => $includepreviews,
          );
          $params = self::validate_parameters(self::get_user_attempts_parameters(), $params);
  
          list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']);
  
          if (!in_array($params['status'], array('all', 'finished', 'unfinished'))) {
              throw new invalid_parameter_exception('Invalid status value');
          }
  
          // Default value for userid.
          if (empty($params['userid'])) {
              $params['userid'] = $USER->id;
          }
  
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
          // Extra checks so only users with permissions can view other users attempts.
          if ($USER->id != $user->id) {
              require_capability('mod/quiz:viewreports', $context);
          }
  
          $attempts = quiz_get_user_attempts($quiz->id, $user->id, $params['status'], $params['includepreviews']);
  
          $result = array();
          $result['attempts'] = $attempts;
          $result['warnings'] = $warnings;
          return $result;
      }
code_tokens: public static function get_user_attempts ( $ quizid , $ userid = 0 , $ status = 'finished' , $ includepreviews = false ) { global $ DB , $ USER ; $ warnings = array ( ) ; $ params = array ( 'quizid' => $ quizid , 'userid' => $ userid , 'status' => $ status , 'includepreviews' => $ includepreviews , ) ; $ params = self :: validate_parameters ( self :: get_user_attempts_parameters ( ) , $ params ) ; list ( $ quiz , $ course , $ cm , $ context ) = self :: validate_quiz ( $ params [ 'quizid' ] ) ; if ( ! in_array ( $ params [ 'status' ] , array ( 'all' , 'finished' , 'unfinished' ) ) ) { throw new invalid_parameter_exception ( 'Invalid status value' ) ; } // Default value for userid. if ( empty ( $ params [ 'userid' ] ) ) { $ params [ 'userid' ] = $ USER -> id ; } $ user = core_user :: get_user ( $ params [ 'userid' ] , '*' , MUST_EXIST ) ; core_user :: require_active_user ( $ user ) ; // Extra checks so only users with permissions can view other users attempts. if ( $ USER -> id != $ user -> id ) { require_capability ( 'mod/quiz:viewreports' , $ context ) ; } $ attempts = quiz_get_user_attempts ( $ quiz -> id , $ user -> id , $ params [ 'status' ] , $ params [ 'includepreviews' ] ) ; $ result = array ( ) ; $ result [ 'attempts' ] = $ attempts ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
docstring: Return a list of attempts for the given quiz and user.
  
  @param int $quizid quiz instance id
  @param int $userid user id
  @param string $status quiz status: all, finished or unfinished
  @param bool $includepreviews whether to include previews or not
  @return array of warnings and the list of attempts
  @since Moodle 3.1
  @throws invalid_parameter_exception
docstring_tokens: Return a list of attempts for the given quiz and user .