Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mod_lesson_generator Class Reference

mod_lesson data generator class. More...

Inheritance diagram for mod_lesson_generator:
testing_module_generator component_generator_base

Public Member Functions

 create_answer ($record=null, array $options=null)
 Creates an answer in a page for testing purposes.
 
 create_cluster (stdClass $lesson, array $record=[])
 Creates a cluster page for testing purposes.
 
 create_content ($lesson, $record=array())
 Creates a content page for testing purposes.
 
 create_endofbranch (stdClass $lesson, array $record=[])
 Creates a end of branch page for testing purposes.
 
 create_endofcluster (stdClass $lesson, array $record=[])
 Creates a end of cluster page for testing purposes.
 
 create_instance ($record=null, array $options=null)
 Creates a lesson instance for testing purposes.
 
 create_override (array $data)
 Create a lesson override (either user or group).
 
 create_page ($record=null, array $options=null)
 Creates a page for testing purposes.
 
 create_question_essay ($lesson, $record=array())
 Create essay question pages.
 
 create_question_matching ($lesson, $record=array())
 Create matching question pages.
 
 create_question_multichoice ($lesson, $record=array())
 Create multichoice question pages.
 
 create_question_numeric ($lesson, $record=array())
 Create shortanswer question pages.
 
 create_question_shortanswer ($lesson, $record=array())
 Create shortanswer question pages.
 
 create_question_truefalse ($lesson, $record=array())
 Create True/false question pages.
 
 finish_generate_answer ()
 All answers in a table have been generated, create the pages.
 
 get_modulename ()
 Returns module name.
 
 reset ()
 To be called from data reset code only, do not use in tests.
 

Protected Member Functions

 convert_page_jumpto (int $lessonid, ?array $jumptolist)
 Convert the jumpto using a string to an integer value.
 
 create_candidate_pages ()
 Create candidate pages.
 
 get_previouspage_id (int $lessonid, string $pagetitle)
 Calculate the previous page id.
 
 insert_files (stdClass $instance, stdClass $record, string $table, context $context, string $component, string $filearea, int $targetitemid)
 Update the instance record, inserting any files that are referenced.
 
 post_add_instance ($id, $cmid)
 Called after *_add_instance()
 
 precreate_course_module ($courseid, array $options)
 Create course module and link it to course.
 
 prepare_moduleinfo_record ($record, $options)
 Merges together arguments $record and $options and fills default module fields that are shared by all module types.
 
 set_user (?stdClass $user=null)
 Set the current user during data generation.
 

Protected Attributes

array $candidatepages = []
 list of candidate pages to be created when all answers have been added.
 
testing_data_generator $datagenerator
 
int $instancecount = 0
 number of created instances
 
array $jumptomap
 map of readable jumpto to integer value.
 
int $pagecount = 0
 keep track of how many pages have been created.
 

Detailed Description

mod_lesson data generator class.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ convert_page_jumpto()

mod_lesson_generator::convert_page_jumpto ( int $lessonid,
?array $jumptolist )
protected

Convert the jumpto using a string to an integer value.

The jumpto can contain a page name or one of our predefined values.

Parameters
int$lessonidthe lesson id.
array | null$jumptolistlist of jumpto to treat.
Return values
array|nulllist of jumpto already treated.
Exceptions
coding_exception

◆ create_answer()

mod_lesson_generator::create_answer ( $record = null,
array $options = null )

Creates an answer in a page for testing purposes.

Parameters
null | array | stdClass$recorddata for module being generated.
null | array$optionsgeneral options.
Exceptions
coding_exception

◆ create_candidate_pages()

mod_lesson_generator::create_candidate_pages ( )
protected

Create candidate pages.

Exceptions
coding_exception

◆ create_cluster()

mod_lesson_generator::create_cluster ( stdClass $lesson,
array $record = [] )

Creates a cluster page for testing purposes.

Parameters
stdClass$lessoninstance where to create the page.
array$recorddata for page being generated.
Return values
stdClasspage record.

◆ create_content()

mod_lesson_generator::create_content ( $lesson,
$record = array() )

Creates a content page for testing purposes.

Parameters
stdClass$lessoninstance where to create the page.
array | stdClass$recorddata for page being generated.
Return values
stdClasspage record.

Reimplemented from testing_module_generator.

◆ create_endofbranch()

mod_lesson_generator::create_endofbranch ( stdClass $lesson,
array $record = [] )

Creates a end of branch page for testing purposes.

Parameters
stdClass$lessoninstance where to create the page.
array$recorddata for page being generated.
Return values
stdClasspage record.

◆ create_endofcluster()

mod_lesson_generator::create_endofcluster ( stdClass $lesson,
array $record = [] )

Creates a end of cluster page for testing purposes.

Parameters
stdClass$lessoninstance where to create the page.
array$recorddata for page being generated.
Return values
stdClasspage record.

◆ create_instance()

mod_lesson_generator::create_instance ( $record = null,
array $options = null )

Creates a lesson instance for testing purposes.

Parameters
null | array | stdClass$recorddata for module being generated.
null | array$optionsgeneral options for course module.
Return values
stdClassrecord from module-defined table with additional field cmid (corresponding id in course_modules table)

Reimplemented from testing_module_generator.

◆ create_override()

mod_lesson_generator::create_override ( array $data)

Create a lesson override (either user or group).

Parameters
array$datamust specify lessonid, and one of userid or groupid.
Exceptions
coding_exception

◆ create_page()

mod_lesson_generator::create_page ( $record = null,
array $options = null )

Creates a page for testing purposes.

The page will be created when answers are added.

Parameters
null | array | stdClass$recorddata for page being generated.
null | array$optionsgeneral options.

◆ create_question_essay()

mod_lesson_generator::create_question_essay ( $lesson,
$record = array() )

Create essay question pages.

Parameters
object$lesson
array$record
Return values
stdClasspage record.

◆ create_question_matching()

mod_lesson_generator::create_question_matching ( $lesson,
$record = array() )

Create matching question pages.

Parameters
object$lesson
array$record
Return values
stdClasspage record.

◆ create_question_multichoice()

mod_lesson_generator::create_question_multichoice ( $lesson,
$record = array() )

Create multichoice question pages.

Parameters
object$lesson
array$record
Return values
stdClasspage record.

◆ create_question_numeric()

mod_lesson_generator::create_question_numeric ( $lesson,
$record = array() )

Create shortanswer question pages.

Parameters
object$lesson
array$record
Return values
stdClasspage record.

◆ create_question_shortanswer()

mod_lesson_generator::create_question_shortanswer ( $lesson,
$record = array() )

Create shortanswer question pages.

Parameters
object$lesson
array$record
Return values
stdClasspage record.

◆ create_question_truefalse()

mod_lesson_generator::create_question_truefalse ( $lesson,
$record = array() )

Create True/false question pages.

Parameters
object$lesson
array$record
Return values
stdClasspage record.

◆ get_modulename()

testing_module_generator::get_modulename ( )
inherited

Returns module name.

Return values
stringname of module that this class describes
Exceptions
coding_exceptionif class invalid

◆ get_previouspage_id()

mod_lesson_generator::get_previouspage_id ( int $lessonid,
string $pagetitle )
protected

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.

Parameters
int$lessonidthe lesson id.
string$pagetitlethe page title, for example 'Test page'. '0' if no previous page.
Return values
intcorresponding id. 0 if no previous page.
Exceptions
coding_exception

◆ insert_files()

component_generator_base::insert_files ( stdClass $instance,
stdClass $record,
string $table,
context $context,
string $component,
string $filearea,
int $targetitemid )
protectedinherited

Update the instance record, inserting any files that are referenced.

Parameters
stdClass$instanceThe instance record of the already-created record
stdClass$recordThe data passed in to create the instance
string$tableThe table that the data exists in
context$contextThe context of the instance
string$componentThe component of the owning plugin
string$fileareaThe name of the file area
int$targetitemidThe itemid to use when saving the files
Return values
stdClassThe updated instance record

◆ post_add_instance()

testing_module_generator::post_add_instance ( $id,
$cmid )
protectedinherited

Called after *_add_instance()

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

Deprecated
since 2.6
See also
testing_module_generator\create_instance()
Parameters
int$id
int$cmid
Return values
stdClassmodule instance

◆ precreate_course_module()

testing_module_generator::precreate_course_module ( $courseid,
array $options )
protectedinherited

Create course module and link it to course.

Since 2.6 it is recommended to use function add_moduleinfo() to create a module.

Deprecated
since 2.6
See also
testing_module_generator\create_instance()
Parameters
integer$courseid
array$optionssection, visible
Return values
integer\$cminstance id

◆ prepare_moduleinfo_record()

testing_module_generator::prepare_moduleinfo_record ( $record,
$options )
protectedinherited

Merges together arguments $record and $options and fills default module fields that are shared by all module types.

Parameters
object | array$recordfields (different from defaults) for this module
null | array$optionsfor backward-compatibility this may include fields from course_modules table. They are merged into $record
Exceptions
coding_exceptionif $record->course is not specified

◆ reset()

mod_lesson_generator::reset ( )

To be called from data reset code only, do not use in tests.

Return values
void

Reimplemented from testing_module_generator.

◆ set_user()

component_generator_base::set_user ( ?stdClass $user = null)
protectedinherited

Set the current user during data generation.

This should be avoided wherever possible, but in some situations underlying code will insert data as the current user.

Parameters
stdClass$user

Member Data Documentation

◆ $jumptomap

array mod_lesson_generator::$jumptomap
protected
Initial value:
= [
'This page' => LESSON_THISPAGE,
'Next page' => LESSON_NEXTPAGE,
'Previous page' => LESSON_PREVIOUSPAGE,
'End of lesson' => LESSON_EOL,
'Unseen question within a content page' => LESSON_UNSEENBRANCHPAGE,
'Random question within a content page' => LESSON_RANDOMPAGE,
'Random content page' => LESSON_RANDOMBRANCH,
'Unseen question within a cluster' => LESSON_CLUSTERJUMP,
]
const LESSON_RANDOMPAGE
Jump to a random page within a branch and end of branch or end of lesson.
Definition locallib.php:50
const LESSON_CLUSTERJUMP
Cluster Jump.
Definition locallib.php:54
const LESSON_THISPAGE
Include the files that are required by this module.
Definition locallib.php:36
const LESSON_EOL
End of Lesson.
Definition locallib.php:44
const LESSON_RANDOMBRANCH
Jump to a random Branch.
Definition locallib.php:52
const LESSON_NEXTPAGE
Jump to Next Page.
Definition locallib.php:42
const LESSON_PREVIOUSPAGE
Jump to Previous Page.
Definition locallib.php:48
const LESSON_UNSEENBRANCHPAGE
Jump to an unseen page within a branch and end of branch or end of lesson.
Definition locallib.php:46

map of readable jumpto to integer value.


The documentation for this class was generated from the following file: