Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
Public Member Functions | |
__construct ($properties, lesson $lesson) | |
Constructor method. | |
__get ($key) | |
Magic get method. | |
__isset ($key) | |
Stupid PHP needs an isset magic method if you use the get magic method and still want empty calls to work.... | |
__set ($key, $value) | |
Magic property method. | |
add_page_link ($previd) | |
Can be set to true if the page requires a static link to create a new instance instead of simply being included in the dropdown. | |
callback_on_view ($canmanage, $redirect=true) | |
This is a callback method that can be override and gets called when ever a page is viewed. | |
check_answer () | |
This method MUST be overridden by all question page types, or page types that wish to score a page. | |
create_answers ($properties) | |
Creates answers within the database for this lesson_page. | |
delete () | |
Deletes a lesson_page from the database as well as any associated records. | |
display ($renderer, $attempt) | |
This method gets called to display the page to the user taking the lesson @abstract. | |
display_answers (html_table $table) | |
Updates a table with the answers for this page. | |
earned_score ($answers, $attempt) | |
Returns the score for the attempt This may be overridden by page types that require manual grading. | |
format_answer ($answer, $context, $answerformat, $options=[]) | |
Formats the answer. | |
get_answers () | |
Returns the answers that are associated with this page in the database. | |
get_contents () | |
Returns the contents field for the page properly formatted and with plugin file url's converted. | |
get_files ($includedirs=true, $updatedsince=0) | |
Get files from the page area file. | |
get_jumps () | |
Gets an array of the jumps used by the answers of this page. | |
has_option () | |
True if the page uses a custom option. | |
is_unanswered ($nretakes) | |
Checks to see if a page has been answered previously. | |
is_unseen ($param) | |
Returns true if a page has been viewed before. | |
max_answers ($default) | |
Returns the maximum number of answers for this page given the maximum number of answers permitted by the lesson. | |
move ($nextpageid=null, $prevpageid=null) | |
Moves a page by updating its nextpageid and prevpageid values within the database. | |
on_after_write_attempt ($attempt, $result) | |
Do any post persistence processing logic of an attempt. | |
option_description_string () | |
Get the string that describes the options of this page type. | |
override_next_page () | |
A callback method that allows a page to override the next page a user will see during when this page is being completed. | |
properties () | |
Returns the properties of this lesson page as an object. | |
moodle_database | record_attempt ($context) |
Records an attempt at this page. | |
report_answers ($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) | |
Formats the answers of this page for a report. | |
requires_manual_grading () | |
Informs whether this page type require manual grading or not. | |
save_answers_files ($context, $maxbytes, &$answer, $answereditor='', $responseeditor='') | |
save editor answers files and update answer record | |
stats (array &$pagestats, $tries) | |
Adds stats for this page to the &pagestats object. | |
update ($properties, $context=null, $maxbytes=null) | |
Updates a lesson page and its answers within the database. | |
update_form_data (stdClass $data) | |
Make updates to the form data if required. | |
valid_page_and_view (&$validpages, &$pageviews) | |
This method is used to determine if this page is a valid page. | |
Static Public Member Functions | |
static | create ($properties, lesson $lesson, $context, $maxbytes) |
Creates a new lesson_page within the database and returns the correct pagetype object to use to interact with the new lesson. | |
static | get_jumptooptions ($pageid, lesson $lesson) |
Returns an array of options to display when choosing the jumpto for a page/answer. | |
static | load ($id, lesson $lesson) |
This method loads a page object from the database and returns it as a specialised object that extends lesson_page. | |
static | rewrite_answers_urls ($answer, $rewriteanswer=true) |
Rewrite urls in response and optionality answer of a question answer. | |
Protected Member Functions | |
get_displayinmenublock () | |
Set to true if this page should display in the menu block. | |
get_grayout () | |
Determines if this page should be grayed out on the management/report screens. | |
get_jump_name ($jumpto) | |
Returns the string for a jump name. | |
get_lesson () | |
Returns the lesson this page is associated with @final. | |
get_type () | |
Returns the type of page this is. | |
get_typeid () | |
This method should return the integer used to identify the page type within the database and throughout code. | |
get_typestring () | |
This method should return the string that describes the pagetype @abstract. | |
Protected Attributes | |
null array | $answers = null |
Contains the answers to this lesson_page once loaded. | |
lesson | $lesson = null |
A reference to the lesson this page belongs to. | |
stdClass | $properties |
An object containing properties. | |
int | $type = 0 |
This sets the type of the page, can be one of the constants defined below. | |
lesson_page::__construct | ( | $properties, | |
lesson | $lesson ) |
Constructor method.
object | $properties | |
lesson | $lesson |
|
inherited |
Magic get method.
Attempts to call a get_$key method to return the property and ralls over to return the raw property
str | $key |
mixed |
|
inherited |
Stupid PHP needs an isset magic method if you use the get magic method and still want empty calls to work....
blah ~!
string | $key |
bool |
|
inherited |
Magic property method.
Attempts to call a set_$key method if one exists otherwise falls back to simply set the property
string | $key | |
mixed | $value |
lesson_page::add_page_link | ( | $previd | ) |
Can be set to true if the page requires a static link to create a new instance instead of simply being included in the dropdown.
int | $previd |
bool |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_cluster, lesson_page_type_endofbranch, and lesson_page_type_endofcluster.
lesson_page::callback_on_view | ( | $canmanage, | |
$redirect = true ) |
This is a callback method that can be override and gets called when ever a page is viewed.
bool | $canmanage | True if the user has the manage cap |
bool | $redirect | Optional, default to true. Set to false to avoid redirection and return the page to redirect. |
mixed |
Reimplemented in lesson_page_type_cluster, lesson_page_type_endofbranch, and lesson_page_type_endofcluster.
lesson_page::check_answer | ( | ) |
This method MUST be overridden by all question page types, or page types that wish to score a page.
The structure of result should always be the same so it is a good idea when overriding this method on a page type to call $result = parent\check_answer();
before modifying it as required.
stdClass |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_multichoice, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
|
staticfinal |
Creates a new lesson_page within the database and returns the correct pagetype object to use to interact with the new lesson.
@final
object | $properties | |
lesson | $lesson |
lesson_page | Specialised object that extends lesson_page |
lesson_page::create_answers | ( | $properties | ) |
Creates answers within the database for this lesson_page.
Usually only ever called when creating a new page instance
object | $properties |
array |
Reimplemented in lesson_page_type_cluster, lesson_page_type_endofbranch, lesson_page_type_endofcluster, lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_numerical, and lesson_page_type_shortanswer.
|
final |
Deletes a lesson_page from the database as well as any associated records.
@final
bool |
|
abstract |
This method gets called to display the page to the user taking the lesson @abstract.
object | $renderer | |
object | $attempt |
string |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_cluster, lesson_page_type_endofbranch, lesson_page_type_endofcluster, lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_multichoice, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
lesson_page::display_answers | ( | html_table | $table | ) |
Updates a table with the answers for this page.
html_table | $table |
html_table |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_matching, lesson_page_type_multichoice, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
lesson_page::earned_score | ( | $answers, | |
$attempt ) |
Returns the score for the attempt This may be overridden by page types that require manual grading.
array | $answers | |
object | $attempt |
int |
lesson_page::format_answer | ( | $answer, | |
$context, | |||
$answerformat, | |||
$options = [] ) |
Formats the answer.
Override for custom formatting.
string | $answer | |
context | $context | |
int | $answerformat |
string | Returns formatted string |
Reimplemented in lesson_page_type_essay, and lesson_page_type_numerical.
|
final |
Returns the answers that are associated with this page in the database.
@final
array |
lesson_page::get_contents | ( | ) |
Returns the contents field for the page properly formatted and with plugin file url's converted.
string |
|
protected |
Set to true if this page should display in the menu block.
bool |
Reimplemented in lesson_page_type_branchtable.
lesson_page::get_files | ( | $includedirs = true, | |
$updatedsince = 0 ) |
Get files from the page area file.
bool | $includedirs | whether or not include directories |
int | $updatedsince | return files updated since this time |
array | list of stored_file objects |
|
protected |
Determines if this page should be grayed out on the management/report screens.
int | 0 or 1 |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_cluster, lesson_page_type_endofbranch, and lesson_page_type_endofcluster.
|
finalprotected |
Returns the string for a jump name.
@final
int | $jumpto | Jump code or page ID |
string |
lesson_page::get_jumps | ( | ) |
Gets an array of the jumps used by the answers of this page.
array |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_matching, and lesson_page_type_multichoice.
|
static |
Returns an array of options to display when choosing the jumpto for a page/answer.
int | $pageid | |
lesson | $lesson |
array |
Reimplemented in lesson_page_type_branchtable.
|
finalprotected |
Returns the lesson this page is associated with @final.
lesson |
|
finalprotected |
Returns the type of page this is.
Not to be confused with page type @final
int |
|
abstractprotected |
This method should return the integer used to identify the page type within the database and throughout code.
This maps back to the defines used in 1.x @abstract
int |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_cluster, lesson_page_type_endofbranch, lesson_page_type_endofcluster, lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_multichoice, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
|
abstractprotected |
This method should return the string that describes the pagetype @abstract.
string |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_cluster, lesson_page_type_endofbranch, lesson_page_type_endofcluster, lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_multichoice, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
lesson_page::has_option | ( | ) |
True if the page uses a custom option.
Should be override and set to true if the page uses a custom option.
bool |
lesson_page::is_unanswered | ( | $nretakes | ) |
Checks to see if a page has been answered previously.
int | $nretakes |
bool |
Reimplemented in lesson_page_type_essay.
lesson_page::is_unseen | ( | $param | ) |
Returns true if a page has been viewed before.
array | int | $param | Either an array of pages that have been seen or the number of retakes a user has had |
bool |
Reimplemented in lesson_page_type_branchtable.
|
staticfinal |
This method loads a page object from the database and returns it as a specialised object that extends lesson_page.
@final
int | $id | |
lesson | $lesson |
lesson_page | Specialised lesson_page object |
lesson_page::max_answers | ( | $default | ) |
Returns the maximum number of answers for this page given the maximum number of answers permitted by the lesson.
int | $default |
int |
|
final |
Moves a page by updating its nextpageid and prevpageid values within the database.
@final
int | $nextpageid | |
int | $prevpageid |
lesson_page::on_after_write_attempt | ( | $attempt, | |
$result ) |
Do any post persistence processing logic of an attempt.
E.g. in cases where we need update file urls in an editor and we need to have the id of the stored attempt. Should be overridden in each individual child pagetype on a as required basis
object | $attempt | The attempt corresponding to the db record |
object | $result | The result from the 'check_answer' method |
array | False if nothing to be modified, updated $attempt and $result if update required. |
Reimplemented in lesson_page_type_essay.
lesson_page::option_description_string | ( | ) |
Get the string that describes the options of this page type.
string |
Reimplemented in lesson_page_type_matching, lesson_page_type_multichoice, and lesson_page_type_shortanswer.
lesson_page::override_next_page | ( | ) |
A callback method that allows a page to override the next page a user will see during when this page is being completed.
false|int |
Reimplemented in lesson_page_type_cluster, and lesson_page_type_endofcluster.
lesson_page::properties | ( | ) |
Returns the properties of this lesson page as an object.
stdClass; |
Reimplemented from lesson_base.
|
final |
Records an attempt at this page.
@final $DB
stdClass | $context |
stdClass | Returns the result of the attempt |
lesson_page::report_answers | ( | $answerpage, | |
$answerdata, | |||
$useranswer, | |||
$pagestats, | |||
& | $i, | ||
& | $n ) |
Formats the answers of this page for a report.
object | $answerpage | |
object | $answerdata | |
object | $useranswer | |
array | $pagestats | |
int | $i | Count of first level answers |
int | $n | Count of second level answers |
object | The answer page for this |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_multichoice, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
lesson_page::requires_manual_grading | ( | ) |
Informs whether this page type require manual grading or not.
bool |
Reimplemented in lesson_page_type_essay.
|
static |
Rewrite urls in response and optionality answer of a question answer.
object | $answer | |
bool | $rewriteanswer | must rewrite answer |
object | answer with rewritten urls |
lesson_page::save_answers_files | ( | $context, | |
$maxbytes, | |||
& | $answer, | ||
$answereditor = '', | |||
$responseeditor = '' ) |
save editor answers files and update answer record
object | $context | |
int | $maxbytes | |
object | $answer | |
object | $answereditor | |
object | $responseeditor |
lesson_page::stats | ( | array & | $pagestats, |
$tries ) |
Adds stats for this page to the &pagestats object.
This should be defined for all page types that grade
array | $pagestats | |
int | $tries |
bool |
Reimplemented in lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_multichoice, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
lesson_page::update | ( | $properties, | |
$context = null, | |||
$maxbytes = null ) |
Updates a lesson page and its answers within the database.
object | $properties |
bool |
Reimplemented in lesson_page_type_branchtable, lesson_page_type_essay, lesson_page_type_matching, lesson_page_type_numerical, lesson_page_type_shortanswer, and lesson_page_type_truefalse.
lesson_page::update_form_data | ( | stdClass | $data | ) |
Make updates to the form data if required.
stdClass | $data | The form data to update. |
stdClass | The updated fom data. |
Reimplemented in lesson_page_type_numerical, and lesson_page_type_shortanswer.
lesson_page::valid_page_and_view | ( | & | $validpages, |
& | $pageviews ) |
This method is used to determine if this page is a valid page.
array | $validpages | |
array | $pageviews |
int | The next page id to check |
Reimplemented in lesson_page_type_cluster, lesson_page_type_endofbranch, and lesson_page_type_endofcluster.