Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

Quiz external API

Copyright: 2016 Juan Leyva <juan@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 2018 lines (88 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

mod_quiz_external:: (60 methods):
  get_quizzes_by_courses_parameters()
  get_quizzes_by_courses()
  get_quizzes_by_courses_returns()
  validate_quiz()
  view_quiz_parameters()
  view_quiz()
  view_quiz_returns()
  get_user_attempts_parameters()
  get_user_attempts()
  attempt_structure()
  get_user_attempts_returns()
  get_user_best_grade_parameters()
  get_user_best_grade()
  get_user_best_grade_returns()
  get_combined_review_options_parameters()
  get_combined_review_options()
  get_combined_review_options_returns()
  start_attempt_parameters()
  start_attempt()
  start_attempt_returns()
  validate_attempt()
  question_structure()
  get_attempt_questions_data()
  get_attempt_data_parameters()
  get_attempt_data()
  get_attempt_data_returns()
  get_attempt_summary_parameters()
  get_attempt_summary()
  get_attempt_summary_returns()
  save_attempt_parameters()
  save_attempt()
  save_attempt_returns()
  process_attempt_parameters()
  process_attempt()
  process_attempt_returns()
  validate_attempt_review()
  get_attempt_review_parameters()
  get_attempt_review()
  get_attempt_review_returns()
  view_attempt_parameters()
  view_attempt()
  view_attempt_returns()
  view_attempt_summary_parameters()
  view_attempt_summary()
  view_attempt_summary_returns()
  view_attempt_review_parameters()
  view_attempt_review()
  view_attempt_review_returns()
  get_quiz_feedback_for_grade_parameters()
  get_quiz_feedback_for_grade()
  get_quiz_feedback_for_grade_returns()
  get_quiz_access_information_parameters()
  get_quiz_access_information()
  get_quiz_access_information_returns()
  get_attempt_access_information_parameters()
  get_attempt_access_information()
  get_attempt_access_information_returns()
  get_quiz_required_qtypes_parameters()
  get_quiz_required_qtypes()
  get_quiz_required_qtypes_returns()


Class: mod_quiz_external  - X-Ref

Quiz external functions

get_quizzes_by_courses_parameters()   X-Ref
Describes the parameters for get_quizzes_by_courses.

return: external_function_parameters

get_quizzes_by_courses($courseids = array()   X-Ref
Returns a list of quizzes in a provided list of courses,
if no list is provided all quizzes that the user can view will be returned.

param: array $courseids Array of course ids
return: array of quizzes details

get_quizzes_by_courses_returns()   X-Ref
Describes the get_quizzes_by_courses return value.

return: external_single_structure

validate_quiz($quizid)   X-Ref
No description

view_quiz_parameters()   X-Ref
Describes the parameters for view_quiz.

return: external_function_parameters

view_quiz($quizid)   X-Ref
Trigger the course module viewed event and update the module completion status.

param: int $quizid quiz instance id
return: array of warnings and status result

view_quiz_returns()   X-Ref
Describes the view_quiz return value.

return: external_single_structure

get_user_attempts_parameters()   X-Ref
Describes the parameters for get_user_attempts.

return: external_function_parameters

get_user_attempts($quizid, $userid = 0, $status = 'finished', $includepreviews = false)   X-Ref
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

attempt_structure()   X-Ref
Describes a single attempt structure.

return: external_single_structure the attempt structure

get_user_attempts_returns()   X-Ref
Describes the get_user_attempts return value.

return: external_single_structure

get_user_best_grade_parameters()   X-Ref
Describes the parameters for get_user_best_grade.

return: external_function_parameters

get_user_best_grade($quizid, $userid = 0)   X-Ref
Get the best current grade for the given user on a quiz.

param: int $quizid quiz instance id
param: int $userid user id
return: array of warnings and the grade information

get_user_best_grade_returns()   X-Ref
Describes the get_user_best_grade return value.

return: external_single_structure

get_combined_review_options_parameters()   X-Ref
Describes the parameters for get_combined_review_options.

return: external_function_parameters

get_combined_review_options($quizid, $userid = 0)   X-Ref
Combines the review options from a number of different quiz attempts.

param: int $quizid quiz instance id
param: int $userid user id (empty for current user)
return: array of warnings and the review options

get_combined_review_options_returns()   X-Ref
Describes the get_combined_review_options return value.

return: external_single_structure

start_attempt_parameters()   X-Ref
Describes the parameters for start_attempt.

return: external_function_parameters

start_attempt($quizid, $preflightdata = array()   X-Ref
Starts a new attempt at a quiz.

param: int $quizid quiz instance id
param: array $preflightdata preflight required data (like passwords)
param: bool $forcenew Whether to force a new attempt or not.
return: array of warnings and the attempt basic data

start_attempt_returns()   X-Ref
Describes the start_attempt return value.

return: external_single_structure

validate_attempt($params, $checkaccessrules = true, $failifoverdue = true)   X-Ref
Utility function for validating a given attempt

param: array $params array of parameters including the attemptid and preflight data
param: bool $checkaccessrules whether to check the quiz access rules or not
param: bool $failifoverdue whether to return error if the attempt is overdue
return: array containing the attempt object and access messages

question_structure()   X-Ref
Describes a single question structure.

return: external_single_structure the question data. Some fields may not be returned depending on the quiz display settings.

get_attempt_questions_data(quiz_attempt $attemptobj, $review, $page = 'all')   X-Ref
Return questions information for a given attempt.

param: quiz_attempt  $attemptobj  the quiz attempt object
param: bool  $review  whether if we are in review mode or not
param: mixed  $page  string 'all' or integer page number
return: array array of questions including data

get_attempt_data_parameters()   X-Ref
Describes the parameters for get_attempt_data.

return: external_function_parameters

get_attempt_data($attemptid, $page, $preflightdata = array()   X-Ref
Returns information for the given attempt page for a quiz attempt in progress.

param: int $attemptid attempt id
param: int $page page number
param: array $preflightdata preflight required data (like passwords)
return: array of warnings and the attempt data, next page, message and questions

get_attempt_data_returns()   X-Ref
Describes the get_attempt_data return value.

return: external_single_structure

get_attempt_summary_parameters()   X-Ref
Describes the parameters for get_attempt_summary.

return: external_function_parameters

get_attempt_summary($attemptid, $preflightdata = array()   X-Ref
Returns a summary of a quiz attempt before it is submitted.

param: int $attemptid attempt id
param: int $preflightdata preflight required data (like passwords)
return: array of warnings and the attempt summary data for each question

get_attempt_summary_returns()   X-Ref
Describes the get_attempt_summary return value.

return: external_single_structure

save_attempt_parameters()   X-Ref
Describes the parameters for save_attempt.

return: external_function_parameters

save_attempt($attemptid, $data, $preflightdata = array()   X-Ref
Processes save requests during the quiz. This function is intended for the quiz auto-save feature.

param: int $attemptid attempt id
param: array $data the data to be saved
param: array $preflightdata preflight required data (like passwords)
return: array of warnings and execution result

save_attempt_returns()   X-Ref
Describes the save_attempt return value.

return: external_single_structure

process_attempt_parameters()   X-Ref
Describes the parameters for process_attempt.

return: external_function_parameters

process_attempt($attemptid, $data, $finishattempt = false, $timeup = false, $preflightdata = array()   X-Ref
Process responses during an attempt at a quiz and also deals with attempts finishing.

param: int $attemptid attempt id
param: array $data the data to be saved
param: bool $finishattempt whether to finish or not the attempt
param: bool $timeup whether the WS was called by a timer when the time is up
param: array $preflightdata preflight required data (like passwords)
return: array of warnings and the attempt state after the processing

process_attempt_returns()   X-Ref
Describes the process_attempt return value.

return: external_single_structure

validate_attempt_review($params)   X-Ref
Validate an attempt finished for review. The attempt would be reviewed by a user or a teacher.

param: array $params Array of parameters including the attemptid
return: array containing the attempt object and display options

get_attempt_review_parameters()   X-Ref
Describes the parameters for get_attempt_review.

return: external_function_parameters

get_attempt_review($attemptid, $page = -1)   X-Ref
Returns review information for the given finished attempt, can be used by users or teachers.

param: int $attemptid attempt id
param: int $page page number, empty for all the questions in all the pages
return: array of warnings and the attempt data, feedback and questions

get_attempt_review_returns()   X-Ref
Describes the get_attempt_review return value.

return: external_single_structure

view_attempt_parameters()   X-Ref
Describes the parameters for view_attempt.

return: external_function_parameters

view_attempt($attemptid, $page, $preflightdata = array()   X-Ref
Trigger the attempt viewed event.

param: int $attemptid attempt id
param: int $page page number
param: array $preflightdata preflight required data (like passwords)
return: array of warnings and status result

view_attempt_returns()   X-Ref
Describes the view_attempt return value.

return: external_single_structure

view_attempt_summary_parameters()   X-Ref
Describes the parameters for view_attempt_summary.

return: external_function_parameters

view_attempt_summary($attemptid, $preflightdata = array()   X-Ref
Trigger the attempt summary viewed event.

param: int $attemptid attempt id
param: array $preflightdata preflight required data (like passwords)
return: array of warnings and status result

view_attempt_summary_returns()   X-Ref
Describes the view_attempt_summary return value.

return: external_single_structure

view_attempt_review_parameters()   X-Ref
Describes the parameters for view_attempt_review.

return: external_function_parameters

view_attempt_review($attemptid)   X-Ref
Trigger the attempt reviewed event.

param: int $attemptid attempt id
return: array of warnings and status result

view_attempt_review_returns()   X-Ref
Describes the view_attempt_review return value.

return: external_single_structure

get_quiz_feedback_for_grade_parameters()   X-Ref
Describes the parameters for view_quiz.

return: external_function_parameters

get_quiz_feedback_for_grade($quizid, $grade)   X-Ref
Get the feedback text that should be show to a student who got the given grade in the given quiz.

param: int $quizid quiz instance id
param: float $grade the grade to check
return: array of warnings and status result

get_quiz_feedback_for_grade_returns()   X-Ref
Describes the get_quiz_feedback_for_grade return value.

return: external_single_structure

get_quiz_access_information_parameters()   X-Ref
Describes the parameters for get_quiz_access_information.

return: external_function_parameters

get_quiz_access_information($quizid)   X-Ref
Return access information for a given quiz.

param: int $quizid quiz instance id
return: array of warnings and the access information

get_quiz_access_information_returns()   X-Ref
Describes the get_quiz_access_information return value.

return: external_single_structure

get_attempt_access_information_parameters()   X-Ref
Describes the parameters for get_attempt_access_information.

return: external_function_parameters

get_attempt_access_information($quizid, $attemptid = 0)   X-Ref
Return access information for a given attempt in a quiz.

param: int $quizid quiz instance id
param: int $attemptid attempt id, 0 for the user last attempt if exists
return: array of warnings and the access information

get_attempt_access_information_returns()   X-Ref
Describes the get_attempt_access_information return value.

return: external_single_structure

get_quiz_required_qtypes_parameters()   X-Ref
Describes the parameters for get_quiz_required_qtypes.

return: external_function_parameters

get_quiz_required_qtypes($quizid)   X-Ref
Return the potential question types that would be required for a given quiz.
Please note that for random question types we return the potential question types in the category choosen.

param: int $quizid quiz instance id
return: array of warnings and the access information

get_quiz_required_qtypes_returns()   X-Ref
Describes the get_quiz_required_qtypes return value.

return: external_single_structure