Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

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

mod_lesson data generator.

Copyright: 2013 Marina Glancy
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 805 lines (29 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: mod_lesson_generator  - X-Ref

mod_lesson data generator class.

reset()   X-Ref
To be called from data reset code only,
do not use in tests.

return: void

create_instance($record = null, array $options = null)   X-Ref
Creates a lesson instance for testing purposes.

param: null|array|stdClass $record data for module being generated.
param: null|array $options general options for course module.
return: stdClass record from module-defined table with additional field cmid (corresponding id in course_modules table)

create_page($record = null, array $options = null)   X-Ref
Creates a page for testing purposes. The page will be created when answers are added.

param: null|array|stdClass $record data for page being generated.
param: null|array $options general options.

perform_create_page(array $record)   X-Ref
Creates a page and its answers for testing purposes.

param: array $record data for page being generated.
return: stdClass created page, null if couldn't be created because it has a jump to a page that doesn't exist.

create_content($lesson, $record = array()   X-Ref
Creates a content page for testing purposes.

param: stdClass $lesson instance where to create the page.
param: array|stdClass $record data for page being generated.
return: stdClass page record.

create_question_truefalse($lesson, $record = array()   X-Ref
Create True/false question pages.

param: object $lesson
param: array $record
return: stdClass page record.

create_question_multichoice($lesson, $record = array()   X-Ref
Create multichoice question pages.

param: object $lesson
param: array $record
return: stdClass page record.

create_question_essay($lesson, $record = array()   X-Ref
Create essay question pages.

param: object $lesson
param: array $record
return: stdClass page record.

create_question_matching($lesson, $record = array()   X-Ref
Create matching question pages.

param: object $lesson
param: array $record
return: stdClass page record.

create_question_shortanswer($lesson, $record = array()   X-Ref
Create shortanswer question pages.

param: object $lesson
param: array $record
return: stdClass page record.

create_question_numeric($lesson, $record = array()   X-Ref
Create shortanswer question pages.

param: object $lesson
param: array $record
return: stdClass page record.

create_cluster(stdClass $lesson, array $record = [])   X-Ref
Creates a cluster page for testing purposes.

param: stdClass $lesson instance where to create the page.
param: array $record data for page being generated.
return: stdClass page record.

create_endofcluster(stdClass $lesson, array $record = [])   X-Ref
Creates a end of cluster page for testing purposes.

param: stdClass $lesson instance where to create the page.
param: array $record data for page being generated.
return: stdClass page record.

create_endofbranch(stdClass $lesson, array $record = [])   X-Ref
Creates a end of branch page for testing purposes.

param: stdClass $lesson instance where to create the page.
param: array $record data for page being generated.
return: stdClass page record.

create_override(array $data)   X-Ref
Create a lesson override (either user or group).

param: array $data must specify lessonid, and one of userid or groupid.

create_answer($record = null, array $options = null)   X-Ref
Creates an answer in a page for testing purposes.

param: null|array|stdClass $record data for module being generated.
param: null|array $options general options.

finish_generate_answer()   X-Ref
All answers in a table have been generated, create the pages.


create_candidate_pages()   X-Ref
Create candidate pages.


get_previouspage_id(int $lessonid, string $pagetitle)   X-Ref
Calculate the previous page id.
If no page title is supplied, use the last page created in the lesson (0 if no pages).
If page title is supplied, search it in DB and the list of candidate pages.

param: int $lessonid the lesson id.
param: string $pagetitle the page title, for example 'Test page'. '0' if no previous page.
return: int corresponding id. 0 if no previous page.

convert_page_jumpto(int $lessonid, ?array $jumptolist)   X-Ref
Convert the jumpto using a string to an integer value.
The jumpto can contain a page name or one of our predefined values.

param: int $lessonid the lesson id.
param: array|null $jumptolist list of jumpto to treat.
return: array|null list of jumpto already treated.