Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Static Public Member Functions | |
static | call_external_function ($function, $args, $ajaxonly=false) |
Call an external function validating all params/returns correctly. More... | |
static | clean_returnvalue (external_description $description, $response) |
Clean response If a response attribute is unknown from the description, we just ignore the attribute. More... | |
static | external_function_info ($function, $strictness=MUST_EXIST) |
Returns detailed function information. More... | |
static | finish_attempt ($lessonid, $password='', $outoftime=false, $review=false) |
Finishes the current attempt. More... | |
static | finish_attempt_parameters () |
Describes the parameters for finish_attempt. More... | |
static | finish_attempt_returns () |
Describes the finish_attempt return value. More... | |
static | get_attempts_overview ($lessonid, $groupid=0) |
Get a list of all the attempts made by users in a lesson. More... | |
static | get_attempts_overview_parameters () |
Describes the parameters for get_attempts_overview. More... | |
static | get_attempts_overview_returns () |
Describes the get_attempts_overview return value. More... | |
static | get_content_pages_viewed ($lessonid, $lessonattempt, $userid=null) |
Return the list of content pages viewed by a user during a lesson attempt. More... | |
static | get_content_pages_viewed_parameters () |
Describes the parameters for get_content_pages_viewed. More... | |
static | get_content_pages_viewed_returns () |
Describes the get_content_pages_viewed return value. More... | |
static | get_lesson ($lessonid, $password='') |
Return information of a given lesson. More... | |
static | get_lesson_access_information ($lessonid) |
Return access information for a given lesson. More... | |
static | get_lesson_access_information_parameters () |
Describes the parameters for get_lesson_access_information. More... | |
static | get_lesson_access_information_returns () |
Describes the get_lesson_access_information return value. More... | |
static | get_lesson_parameters () |
Describes the parameters for get_lesson. More... | |
static | get_lesson_returns () |
Describes the get_lesson return value. More... | |
static | get_lessons_by_courses ($courseids=array()) |
Returns a list of lessons in a provided list of courses, if no list is provided all lessons that the user can view will be returned. More... | |
static | get_lessons_by_courses_parameters () |
Describes the parameters for get_lessons_by_courses. More... | |
static | get_lessons_by_courses_returns () |
Describes the get_lessons_by_courses return value. More... | |
static | get_page_data ($lessonid, $pageid, $password='', $review=false, $returncontents=false) |
Return information of a given page, including its contents. More... | |
static | get_page_data_parameters () |
Describes the parameters for get_page_data. More... | |
static | get_page_data_returns () |
Describes the get_page_data return value. More... | |
static | get_pages ($lessonid, $password='') |
Return the list of pages in a lesson (based on the user permissions). More... | |
static | get_pages_parameters () |
Describes the parameters for get_pages. More... | |
static | get_pages_possible_jumps ($lessonid) |
Return all the possible jumps for the pages in a given lesson. More... | |
static | get_pages_possible_jumps_parameters () |
Describes the parameters for get_pages_possible_jumps. More... | |
static | get_pages_possible_jumps_returns () |
Describes the get_pages_possible_jumps return value. More... | |
static | get_pages_returns () |
Describes the get_pages return value. More... | |
static | get_questions_attempts ($lessonid, $attempt, $correct=false, $pageid=null, $userid=null) |
Return the list of page question attempts in a given lesson. More... | |
static | get_questions_attempts_parameters () |
Describes the parameters for get_questions_attempts. More... | |
static | get_questions_attempts_returns () |
Describes the get_questions_attempts return value. More... | |
static | get_user_attempt ($lessonid, $userid, $lessonattempt) |
Return information about the given user attempt (including answers). More... | |
static | get_user_attempt_grade ($lessonid, $lessonattempt, $userid=null) |
Return grade information in the attempt for a given user. More... | |
static | get_user_attempt_grade_parameters () |
Describes the parameters for get_user_attempt_grade. More... | |
static | get_user_attempt_grade_returns () |
Describes the get_user_attempt_grade return value. More... | |
static | get_user_attempt_parameters () |
Describes the parameters for get_user_attempt. More... | |
static | get_user_attempt_returns () |
Describes the get_user_attempt return value. More... | |
static | get_user_grade ($lessonid, $userid=null) |
Return the final grade in the lesson for the given user. More... | |
static | get_user_grade_parameters () |
Describes the parameters for get_user_grade. More... | |
static | get_user_grade_returns () |
Describes the get_user_grade return value. More... | |
static | get_user_timers ($lessonid, $userid=null) |
Return the timers in the current lesson for the given user. More... | |
static | get_user_timers_parameters () |
Describes the parameters for get_user_timers. More... | |
static | get_user_timers_returns () |
Describes the get_user_timers return value. More... | |
static | launch_attempt ($lessonid, $password='', $pageid=0, $review=false) |
Starts a new attempt or continues an existing one. More... | |
static | launch_attempt_parameters () |
Describes the parameters for launch_attempt. More... | |
static | launch_attempt_returns () |
Describes the launch_attempt return value. More... | |
static | process_page ($lessonid, $pageid, $data, $password='', $review=false) |
Processes page responses. More... | |
static | process_page_parameters () |
Describes the parameters for process_page. More... | |
static | process_page_returns () |
Describes the process_page return value. More... | |
static | set_context_restriction ($context) |
Set context restriction for all following subsequent function calls. More... | |
static | set_timeout ($seconds=360) |
This method has to be called before every operation that takes a longer time to finish! More... | |
static | validate_context ($context) |
Makes sure user may execute functions in this context. More... | |
static | validate_parameters (external_description $description, $params) |
Validates submitted function parameters, if anything is incorrect invalid_parameter_exception is thrown. More... | |
static | view_lesson ($lessonid, $password='') |
Trigger the course module viewed event and update the module completion status. More... | |
static | view_lesson_parameters () |
Describes the parameters for view_lesson. More... | |
static | view_lesson_returns () |
Describes the view_lesson return value. More... | |
Static Protected Member Functions | |
static | check_can_view_user_data ($userid, $course, $cm, $context) |
Check if the current user can retrieve lesson information (grades, attempts) about the given user. More... | |
static | external_messages () |
Return a external structure representing messages. More... | |
static | format_lesson_messages ($lesson) |
Return lesson messages formatted according the external_messages structure. More... | |
static | get_context_from_params ($param) |
Get context from passed parameters. More... | |
static | get_context_parameters () |
Returns a prepared structure to use a context parameters. More... | |
static | get_lesson_summary_for_exporter ($lessonrecord, $password='') |
Return a lesson record ready for being exported. More... | |
static | get_page_fields (lesson_page $page, $returncontents=false) |
Returns the fields of a page object. More... | |
static | get_page_structure ($required=VALUE_REQUIRED) |
Describes the external structure for a lesson page. More... | |
static | get_user_attempt_grade_structure ($required=VALUE_REQUIRED) |
Describes an attempt grade structure. More... | |
static | validate_attempt (lesson $lesson, $params, $return=false) |
Validates a new attempt. More... | |
static | validate_lesson ($lessonid) |
Utility function for validating a lesson. More... | |
|
staticinherited |
Call an external function validating all params/returns correctly.
Note that an external function may modify the state of the current page, so this wrapper saves and restores tha PAGE and COURSE global variables before/after calling the external function.
string | $function | A webservice function name. |
array | $args | Params array (named params) |
boolean | $ajaxonly | If true, an extra check will be peformed to see if ajax is required. |
array | containing keys for error (bool), exception and data. |
|
staticprotected |
Check if the current user can retrieve lesson information (grades, attempts) about the given user.
int | $userid | the user to check |
stdClass | $course | course object |
stdClass | $cm | cm object |
stdClass | $context | context object |
moodle_exception |
|
staticinherited |
Clean response If a response attribute is unknown from the description, we just ignore the attribute.
If a response attribute is incorrect, invalid_response_exception is thrown. Note: this function is similar to validate parameters, however it is distinct because parameters validation must be distinct from cleaning return values.
external_description | $description | description of the return values |
mixed | $response | the actual response |
mixed | response with added defaults for optional items, invalid_response_exception thrown if any problem found |
|
staticinherited |
Returns detailed function information.
string | object | $function | name of external function or record from external_function |
int | $strictness | IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; MUST_EXIST means throw exception if no record or multiple records found |
stdClass | description or false if not found or exception thrown |
|
staticprotected |
Return a external structure representing messages.
external_multiple_structure | messages structure |
|
static |
Finishes the current attempt.
int | $lessonid | lesson instance id |
string | $password | optional password (the lesson may be protected) |
bool | $outoftime | optional if the user run out of time |
bool | $review | if we want to review just after finishing (1 hour margin) |
array | of warnings and information about the finished attempt |
moodle_exception |
|
static |
Describes the parameters for finish_attempt.
external_function_parameters |
|
static |
|
staticprotected |
Return lesson messages formatted according the external_messages structure.
lesson | $lesson | lesson instance |
array | messages formatted |
|
static |
Get a list of all the attempts made by users in a lesson.
int | $lessonid | lesson instance id |
int | $groupid | group id, 0 means that the function will determine the user group |
array | of warnings and status result |
moodle_exception |
|
static |
Describes the parameters for get_attempts_overview.
external_function_parameters |
|
static |
Describes the get_attempts_overview return value.
external_single_structure |
|
static |
Return the list of content pages viewed by a user during a lesson attempt.
int | $lessonid | lesson instance id |
int | $lessonattempt | lesson attempt number |
int | $userid | only fetch attempts of the given user |
array | of warnings and page attempts |
moodle_exception |
|
static |
Describes the parameters for get_content_pages_viewed.
external_function_parameters |
|
static |
Describes the get_content_pages_viewed return value.
external_single_structure |
|
staticprotectedinherited |
Get context from passed parameters.
The passed array must either contain a contextid or a combination of context level and instance id to fetch the context. For example, the context level can be "course" and instanceid can be courseid.
See context_helper::get_all_levels() for a list of valid context levels.
array | $param |
invalid_parameter_exception |
context |
|
staticprotectedinherited |
Returns a prepared structure to use a context parameters.
external_single_structure |
Reimplemented in tool_lp\external, and core_competency\external.
|
static |
Return information of a given lesson.
int | $lessonid | lesson instance id |
string | $password | optional password (the lesson may be protected) |
array | of warnings and status result |
moodle_exception |
|
static |
Return access information for a given lesson.
int | $lessonid | lesson instance id |
array | of warnings and the access information |
moodle_exception |
|
static |
Describes the parameters for get_lesson_access_information.
external_function_parameters |
|
static |
Describes the get_lesson_access_information return value.
external_single_structure |
|
static |
|
static |
|
staticprotected |
Return a lesson record ready for being exported.
stdClass | $lessonrecord | lesson record |
string | $password | lesson password |
stdClass | the lesson record ready for exporting. |
|
static |
Returns a list of lessons in a provided list of courses, if no list is provided all lessons that the user can view will be returned.
array | $courseids | Array of course ids |
array | of lessons details |
|
static |
Describes the parameters for get_lessons_by_courses.
external_function_parameters |
|
static |
Describes the get_lessons_by_courses return value.
external_single_structure |
|
static |
Return information of a given page, including its contents.
int | $lessonid | lesson instance id |
int | $pageid | page id |
string | $password | optional password (the lesson may be protected) |
bool | $review | if we want to review just after finishing (1 hour margin) |
bool | $returncontents | if we must return the complete page contents once rendered |
array | of warnings and status result |
moodle_exception |
|
static |
Describes the parameters for get_page_data.
external_function_parameters |
|
static |
|
staticprotected |
Returns the fields of a page object.
lesson_page | $page | the lesson page |
bool | $returncontents | whether to return the page title and contents |
stdClass | the fields matching the external page structure |
|
staticprotected |
Describes the external structure for a lesson page.
external_single_structure |
|
static |
Return the list of pages in a lesson (based on the user permissions).
int | $lessonid | lesson instance id |
string | $password | optional password (the lesson may be protected) |
array | of warnings and status result |
moodle_exception |
|
static |
|
static |
Return all the possible jumps for the pages in a given lesson.
You may expect different results on consecutive executions due to the random nature of the lesson module.
int | $lessonid | lesson instance id |
array | of warnings and possible jumps |
moodle_exception |
|
static |
Describes the parameters for get_pages_possible_jumps.
external_function_parameters |
|
static |
Describes the get_pages_possible_jumps return value.
external_single_structure |
|
static |
|
static |
Return the list of page question attempts in a given lesson.
int | $lessonid | lesson instance id |
int | $attempt | the lesson attempt number |
bool | $correct | only fetch correct attempts |
int | $pageid | only fetch attempts at the given page |
int | $userid | only fetch attempts of the given user |
array | of warnings and page attempts |
moodle_exception |
|
static |
Describes the parameters for get_questions_attempts.
external_function_parameters |
|
static |
Describes the get_questions_attempts return value.
external_single_structure |
|
static |
Return information about the given user attempt (including answers).
int | $lessonid | lesson instance id |
int | $userid | the user id |
int | $lessonattempt | the attempt number |
array | of warnings and page attempts |
moodle_exception |
|
static |
Return grade information in the attempt for a given user.
int | $lessonid | lesson instance id |
int | $lessonattempt | lesson attempt number |
int | $userid | only fetch attempts of the given user |
array | of warnings and page attempts |
moodle_exception |
|
static |
Describes the parameters for get_user_attempt_grade.
external_function_parameters |
|
static |
Describes the get_user_attempt_grade return value.
external_single_structure |
|
staticprotected |
Describes an attempt grade structure.
int | $required | if the structure is required or optional |
external_single_structure | the structure |
|
static |
Describes the parameters for get_user_attempt.
external_function_parameters |
|
static |
Describes the get_user_attempt return value.
external_single_structure |
|
static |
Return the final grade in the lesson for the given user.
int | $lessonid | lesson instance id |
int | $userid | only fetch grades of this user |
array | of warnings and page attempts |
moodle_exception |
|
static |
Describes the parameters for get_user_grade.
external_function_parameters |
|
static |
|
static |
Return the timers in the current lesson for the given user.
int | $lessonid | lesson instance id |
int | $userid | only fetch timers of the given user |
array | of warnings and timers |
moodle_exception |
|
static |
Describes the parameters for get_user_timers.
external_function_parameters |
|
static |
|
static |
Starts a new attempt or continues an existing one.
int | $lessonid | lesson instance id |
string | $password | optional password (the lesson may be protected) |
int | $pageid | page id to continue from (only when continuing an attempt) |
bool | $review | if we want to review just after finishing |
array | of warnings and status result |
moodle_exception |
|
static |
Describes the parameters for launch_attempt.
external_function_parameters |
|
static |
|
static |
Processes page responses.
int | $lessonid | lesson instance id |
int | $pageid | page id |
array | $data | the data to be saved |
string | $password | optional password (the lesson may be protected) |
bool | $review | if we want to review just after finishing (1 hour margin) |
array | of warnings and status result |
moodle_exception |
|
static |
Describes the parameters for process_page.
external_function_parameters |
|
static |
|
staticinherited |
Set context restriction for all following subsequent function calls.
stdClass | $context | the context restriction |
|
staticinherited |
This method has to be called before every operation that takes a longer time to finish!
int | $seconds | max expected time the next operation needs |
|
staticprotected |
Validates a new attempt.
lesson | $lesson | lesson instance |
array | $params | request parameters |
boolean | $return | whether to return the errors or throw exceptions |
array | the errors (if return set to true) |
|
staticinherited |
Makes sure user may execute functions in this context.
stdClass | $context |
|
staticprotected |
Utility function for validating a lesson.
int | $lessonid | lesson instance id |
array | array containing the lesson, course, context and course module objects |
|
staticinherited |
Validates submitted function parameters, if anything is incorrect invalid_parameter_exception is thrown.
This is a simple recursive method which is intended to be called from each implementation method of external API.
external_description | $description | description of parameters |
mixed | $params | the actual parameters |
mixed | params with added defaults for optional items, invalid_parameters_exception thrown if any problem found |
|
static |
Trigger the course module viewed event and update the module completion status.
int | $lessonid | lesson instance id |
string | $password | optional password (the lesson may be protected) |
array | of warnings and status result |
moodle_exception |
|
static |
Describes the parameters for view_lesson.
external_function_parameters |
|
static |