|
Moodle PHP Documentation 4.5
Moodle 4.5.5+ (Build: 20250711) (ce34e8ff087)
|
Public Member Functions | |
| __construct ($properties, $cm=null, $course=null) | |
| 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_message ($message, $class="notifyproblem", $align='center') | |
| Sets a message against the session for this lesson that will displayed next time the lesson processes messages. | |
| add_messages_on_page_process (lesson_page $page, $result, $reviewmode) | |
| Add different informative messages to the given page. | |
| add_messages_on_page_view (lesson_page $page, $reviewmode) | |
| Add different informative messages to the given page. | |
| calculate_new_page_on_jump (lesson_page $page, $newpageid) | |
| This returns a real page id to jump to (or LESSON_EOL) after processing page responses. | |
| calculate_progress () | |
| Calculate the progress of the current user in the lesson. | |
| can_manage () | |
| Check if the user can manage the lesson activity. | |
| check_time ($timer) | |
| Check if the user is out of time in a timed lesson. | |
| cluster_jump ($pageid, $userid=null) | |
| Interprets LESSON_CLUSTERJUMP jumpto value. | |
| count_user_retries ($userid) | |
| Return the number of retries in a lesson for a given user. | |
| delete () | |
| Deletes this lesson from the database. | |
| delete_all_overrides () | |
| Deletes all lesson overrides from the database and clears any corresponding calendar events. | |
| delete_override ($overrideid) | |
| Deletes a lesson override from the database and clears any corresponding calendar events. | |
| duplicate_page ($pageid) | |
| Duplicate the lesson page. | |
| get_attempts ($retries, $correct=false, $pageid=null, $userid=null) | |
| Get all of the attempts for the current user. | |
| get_cm () | |
| Return the lesson course module object. | |
| get_content_pages_viewed ($lessonattempt, $userid=null, $sort='', $fields=' *') | |
| Get a list of content pages (formerly known as branch tables) viewed in the lesson for the given user during an attempt. | |
| get_context () | |
| Return the lesson context object. | |
| get_courserecord () | |
| Return the lesson course object. | |
| get_dependencies_restriction_status () | |
| Check if dependencies restrictions are applied. | |
| get_last_attempt (array $attempts) | |
| Returns the last "legal" attempt from the list of student attempts. | |
| get_last_page_seen ($retriescount) | |
| Return the last page the current user saw. | |
| get_lastpageid () | |
| Returns the id of the last page of this lesson. | |
| get_next_page ($nextpageid) | |
| Gets the next page id to display after the one that is provided. | |
| get_ongoing_score_message () | |
| Get the ongoing score message for the user (depending on the user permission and lesson settings). | |
| get_password_restriction_status ($userpassword) | |
| Check if password restriction is applied. | |
| get_sub_pages_of ($pageid, array $ends) | |
| Finds all pages that appear to be a subtype of the provided pageid until an end point specified within $ends is encountered or no more pages exist. | |
| get_time_restriction_status () | |
| Check if time restriction is applied. | |
| get_user_timers ($userid=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0) | |
| Return the timers in the current lesson for the given user. | |
| has_pages () | |
| Checks to see if the lesson has pages. | |
| is_accessible () | |
| Check if the lesson is accessible at the present time. | |
| is_in_review_mode () | |
| Check if the lesson is in review mode. | |
| is_participant ($userid) | |
| Checks user enrollment in the current course. | |
| is_sub_page_of_type ($pageid, array $types, array $ends) | |
| Checks to see if the specified page[id] is a subpage of a type specified in the $types array, until either there are no more pages of we find a type corresponding to that of a type specified in $ends. | |
| jumpto_is_correct ($pageid, $jumpto) | |
| Determines if a jumpto value is correct or not. | |
| left_during_timed_session ($retriescount) | |
| Check if a user left a timed session. | |
| link_for_activitylink () | |
| Returns the link for the related activity. | |
| load_all_pages () | |
| Loads ALL of the pages for this lesson. | |
| load_page ($pageid) | |
| Loads the requested page. | |
| prepare_page_and_contents ($pageid, $lessonoutput, $reviewmode, $redirect=true) | |
| Calculate the correct page and prepare contents for a given page id (could be a page jump id). | |
| process_eol_page ($outoftime) | |
| Process and return all the information for the end of lesson page. | |
| process_page_responses (lesson_page $page) | |
| Process page responses. | |
| properties () | |
| If implemented should create a new instance, save it in the DB and return it. | |
| resort_pages ($pageid, $after) | |
| Move a page resorting all other pages. | |
| set_module_viewed () | |
| Trigger module viewed event and set the module viewed for completion. | |
| show_only_active_users () | |
| Check is only active users in course should be shown. | |
| start_timer () | |
| Starts the lesson time for the current user. | |
| stop_timer () | |
| Updates the timer to the current time then stops it by unsetting the user var. | |
| time_remaining ($starttime) | |
| Returns the time a user has remaining on this lesson. | |
| update_effective_access ($userid) | |
| Updates the lesson properties with override information for a user. | |
| update_timer ($restart=false, $continue=false, $endreached=false) | |
| Updates the timer to the current time and returns the new timer object. | |
Static Public Member Functions | |
| static | create ($properties) |
| Simply generates a lesson object given an array/object of properties Overrides {. | |
| static | load ($lessonid) |
| Generates a lesson object from the database given its id. | |
Protected Member Functions | |
| copy_page_files ($filearea, $itemid, $newitemid, $contextid) | |
| Copy the files from one page to another. | |
| get_firstpage () | |
| Returns the first page for the lesson or false if there isn't one. | |
| get_firstpageid () | |
| Returns the id of the first page of this lesson. | |
| get_lastpage () | |
| Returns the last page for the lesson or false if there isn't one. | |
| get_messages () | |
| Fetches messages from the session that may have been set in previous page actions. | |
Protected Attributes | |
| stdClass | $cm = null |
Course module object gets set and retrieved by directly calling $lesson->cm; | |
| stdClass | $context = null |
Context object gets set and retrieved by directly calling $lesson->context; | |
| stdClass | $courserecord = null |
Course object gets set and retrieved by directly calling $lesson->courserecord; | |
| int | $firstpageid = null |
| The id of the first page (where prevpageid = 0) gets set and retrieved by {. | |
| int | $lastpageid = null |
| The id of the last page (where nextpageid = 0) gets set and retrieved by {. | |
| bool | $loadedallpages = false |
| Flag that gets set to true once all of the pages associated with the lesson have been loaded. | |
| array | $pages = array() |
| An array used to cache the pages associated with this lesson after the first time they have been loaded. | |
| stdClass | $properties |
| An object containing properties. | |
| lesson::__construct | ( | $properties, | |
| $cm = null, | |||
| $course = null ) |
Constructor method.
| object | $properties | |
| stdClass | $cm | course module object |
| stdClass | $course | course object |
|
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::add_message | ( | $message, | |
| $class = "notifyproblem", | |||
| $align = 'center' ) |
Sets a message against the session for this lesson that will displayed next time the lesson processes messages.
| string | $message | |
| string | $class | |
| string | $align |
| bool |
| lesson::add_messages_on_page_process | ( | lesson_page | $page, |
| $result, | |||
| $reviewmode ) |
Add different informative messages to the given page.
| lesson_page | $page | page object |
| stdClass | $result | the page processing result object |
| bool | $reviewmode | whether we are in review mode or not |
| lesson::add_messages_on_page_view | ( | lesson_page | $page, |
| $reviewmode ) |
Add different informative messages to the given page.
| lesson_page | $page | page object |
| reviewmode | $bool | whether we are in review mode or not |
| lesson::calculate_new_page_on_jump | ( | lesson_page | $page, |
| $newpageid ) |
This returns a real page id to jump to (or LESSON_EOL) after processing page responses.
| lesson_page | $page | lesson page |
| int | $newpageid | the new page id |
| int | the real page to jump to (or end of lesson) |
| lesson::calculate_progress | ( | ) |
Calculate the progress of the current user in the lesson.
| int | the progress (scale 0-100) |
| lesson::can_manage | ( | ) |
Check if the user can manage the lesson activity.
| bool | true if the user can manage the lesson |
| lesson::check_time | ( | $timer | ) |
Check if the user is out of time in a timed lesson.
| stdClass | $timer | timer object |
| bool | True if the user is on time, false is the user ran out of time |
| lesson::cluster_jump | ( | $pageid, | |
| $userid = null ) |
Interprets LESSON_CLUSTERJUMP jumpto value.
This will select a page randomly and the page selected will be inbetween a cluster page and end of clutter or end of lesson and the page selected will be a page that has not been viewed already and if any pages are within a branch table or end of branch then only 1 page within the branch table or end of branch will be randomly selected (sub clustering).
| int | $pageid | Id of the current page from which we are jumping from. |
| int | $userid | Id of the user. |
| int | The id of the next page. |
|
protected |
Copy the files from one page to another.
| string | $filearea | Area that the files are stored. |
| int | $itemid | Item ID. |
| int | $newitemid | The item ID for the new page. |
| int | $contextid | Context ID for this page. |
| void. |
| lesson::count_user_retries | ( | $userid | ) |
Return the number of retries in a lesson for a given user.
| int | $userid | the user id |
| int | the retries count |
|
static |
Simply generates a lesson object given an array/object of properties Overrides {.
| object | array | $properties |
| lesson |
| lesson::delete_override | ( | $overrideid | ) |
Deletes a lesson override from the database and clears any corresponding calendar events.
| int | $overrideid | The id of the override being deleted |
| bool | true on success |
| lesson::duplicate_page | ( | $pageid | ) |
Duplicate the lesson page.
| int | $pageid | Page ID of the page to duplicate. |
| void. |
| lesson::get_attempts | ( | $retries, | |
| $correct = false, | |||
| $pageid = null, | |||
| $userid = null ) |
Get all of the attempts for the current user.
| int | $retries | |
| bool | $correct | Optional: only fetch correct attempts |
| int | $pageid | Optional: only fetch attempts at the given page |
| int | $userid | Optional: defaults to the current user if not set |
| array|false |
| lesson::get_cm | ( | ) |
| lesson::get_content_pages_viewed | ( | $lessonattempt, | |
| $userid = null, | |||
| $sort = '', | |||
| $fields = '*' ) |
Get a list of content pages (formerly known as branch tables) viewed in the lesson for the given user during an attempt.
| int | $lessonattempt | the lesson attempt number (also known as retries) |
| int | $userid | the user id to retrieve the data from |
| string | $sort | an order to sort the results in (a valid SQL ORDER BY parameter) |
| string | $fields | a comma separated list of fields to return |
| array | of pages |
| lesson::get_context | ( | ) |
| lesson::get_courserecord | ( | ) |
| lesson::get_dependencies_restriction_status | ( | ) |
Check if dependencies restrictions are applied.
| mixed | false if there aren't restrictions or an object with the restriction information |
|
protected |
Returns the first page for the lesson or false if there isn't one.
This method should be called via the magic method __get(); $firstpage = $lesson->firstpage;
| lesson_page|bool | Returns the lesson_page specialised object or false |
|
protected |
Returns the id of the first page of this lesson.
(prevpageid = 0)
| int |
| lesson::get_last_attempt | ( | array | $attempts | ) |
Returns the last "legal" attempt from the list of student attempts.
| array | $attempts | The list of student attempts. |
| stdClass | The updated fom data. |
| lesson::get_last_page_seen | ( | $retriescount | ) |
Return the last page the current user saw.
| int | $retriescount | the number of retries for the lesson (the last retry number). |
| mixed | false if the user didn't see the lesson or the last page id |
|
protected |
Returns the last page for the lesson or false if there isn't one.
This method should be called via the magic method __get(); $lastpage = $lesson->lastpage;
| lesson_page|bool | Returns the lesson_page specialised object or false |
| lesson::get_lastpageid | ( | ) |
Returns the id of the last page of this lesson.
(nextpageid = 0)
| int |
|
protected |
Fetches messages from the session that may have been set in previous page actions.
// Do not call this method directly instead use $lesson->messages;
| array |
| lesson::get_next_page | ( | $nextpageid | ) |
Gets the next page id to display after the one that is provided.
| int | $nextpageid |
| bool |
| lesson::get_ongoing_score_message | ( | ) |
Get the ongoing score message for the user (depending on the user permission and lesson settings).
| str | the ongoing score message |
| lesson::get_password_restriction_status | ( | $userpassword | ) |
Check if password restriction is applied.
| string | $userpassword | the user password to check (if the restriction is set) |
| mixed | false if there aren't restrictions or an object with the restriction information |
| lesson::get_sub_pages_of | ( | $pageid, | |
| array | $ends ) |
Finds all pages that appear to be a subtype of the provided pageid until an end point specified within $ends is encountered or no more pages exist.
| int | $pageid | |
| array | $ends | An array of LESSON_PAGE_* types that signify an end of the subtype |
| array | An array of specialised lesson_page objects |
| lesson::get_time_restriction_status | ( | ) |
Check if time restriction is applied.
| mixed | false if there aren't restrictions or an object with the restriction information |
| lesson::get_user_timers | ( | $userid = null, | |
| $sort = '', | |||
| $fields = '*', | |||
| $limitfrom = 0, | |||
| $limitnum = 0 ) |
Return the timers in the current lesson for the given user.
| int | $userid | the user id |
| string | $sort | an order to sort the results in (optional, a valid SQL ORDER BY parameter). |
| string | $fields | a comma separated list of fields to return |
| int | $limitfrom | return a subset of records, starting at this point (optional). |
| int | $limitnum | return a subset comprising this many records in total (optional, required if $limitfrom is set). |
| array | list of timers for the given user in the lesson |
| lesson::is_accessible | ( | ) |
Check if the lesson is accessible at the present time.
| bool | True if the lesson is accessible, false otherwise |
| lesson::is_in_review_mode | ( | ) |
Check if the lesson is in review mode.
(The user already finished it and retakes are not allowed).
| bool | true if is in review mode |
| lesson::is_participant | ( | $userid | ) |
Checks user enrollment in the current course.
| int | $userid |
| null|stdClass | user record |
| lesson::is_sub_page_of_type | ( | $pageid, | |
| array | $types, | ||
| array | $ends ) |
Checks to see if the specified page[id] is a subpage of a type specified in the $types array, until either there are no more pages of we find a type corresponding to that of a type specified in $ends.
| int | $pageid | The id of the page to check |
| array | $types | An array of types that would signify this page was a subpage |
| array | $ends | An array of types that mean this is not a subpage |
| bool |
| lesson::jumpto_is_correct | ( | $pageid, | |
| $jumpto ) |
Determines if a jumpto value is correct or not.
returns true if jumpto page is (logically) after the pageid page or if the jumpto value is a special value. Returns false in all other cases.
| int | $pageid | Id of the page from which you are jumping from. |
| int | $jumpto | The jumpto number. |
| boolean | True or false after a series of tests. |
| lesson::left_during_timed_session | ( | $retriescount | ) |
Check if a user left a timed session.
| int | $retriescount | the number of retries for the lesson (the last retry number). |
| true | if the user left the timed session |
| lesson::link_for_activitylink | ( | ) |
Returns the link for the related activity.
| string |
|
static |
Generates a lesson object from the database given its id.
| int | $lessonid |
| lesson |
| lesson::load_all_pages | ( | ) |
Loads ALL of the pages for this lesson.
| array | An array containing all pages from this lesson |
| lesson::load_page | ( | $pageid | ) |
Loads the requested page.
This function will return the requested page id as either a specialised lesson_page object OR as a generic lesson_page. If the page has been loaded previously it will be returned from the pages array, otherwise it will be loaded from the database first
| int | $pageid |
| lesson_page | A lesson_page object or an object that extends it |
| lesson::prepare_page_and_contents | ( | $pageid, | |
| $lessonoutput, | |||
| $reviewmode, | |||
| $redirect = true ) |
Calculate the correct page and prepare contents for a given page id (could be a page jump id).
| int | $pageid | the given page id |
| mod_lesson_renderer | $lessonoutput | the lesson output rendered |
| bool | $reviewmode | whether we are in review mode or not |
| bool | $redirect | Optional, default to true. Set to false to avoid redirection and return the page to redirect. |
| array | the page object and contents |
| moodle_exception |
| lesson::process_eol_page | ( | $outoftime | ) |
Process and return all the information for the end of lesson page.
| string | $outoftime | used to check to see if the student ran out of time |
| stdclass | an object with all the page data ready for rendering |
| lesson::process_page_responses | ( | lesson_page | $page | ) |
|
inherited |
If implemented should create a new instance, save it in the DB and return it.
If implemented should load an instance from the DB and return it Fetches all of the properties of the object
| stdClass |
Reimplemented in lesson_page.
| lesson::resort_pages | ( | $pageid, | |
| $after ) |
Move a page resorting all other pages.
| int | $pageid | |
| int | $after |
| void |
| lesson::set_module_viewed | ( | ) |
Trigger module viewed event and set the module viewed for completion.
| lesson::show_only_active_users | ( | ) |
Check is only active users in course should be shown.
| bool | true if only active users should be shown. |
| lesson::start_timer | ( | ) |
Starts the lesson time for the current user.
| bool | Returns true |
| lesson::stop_timer | ( | ) |
Updates the timer to the current time then stops it by unsetting the user var.
| bool | Returns true |
| lesson::time_remaining | ( | $starttime | ) |
Returns the time a user has remaining on this lesson.
| int | $starttime | Starttime timestamp |
| string |
| lesson::update_effective_access | ( | $userid | ) |
Updates the lesson properties with override information for a user.
Algorithm: For each lesson setting, if there is a matching user-specific override, then use that otherwise, if there are group-specific overrides, return the most lenient combination of them. If neither applies, leave the quiz setting unchanged.
Special case: if there is more than one password that applies to the user, then lesson->extrapasswords will contain an array of strings giving the remaining passwords.
| int | $userid | The userid. |
| lesson::update_timer | ( | $restart = false, | |
| $continue = false, | |||
| $endreached = false ) |
Updates the timer to the current time and returns the new timer object.
| bool | $restart | If set to true the timer is restarted |
| bool | $continue | If set to true AND $restart=true then the timer will continue from a previous attempt |
| stdClass | The new timer |
|
protected |
Course module object gets set and retrieved by directly calling $lesson->cm;
|
protected |
Context object gets set and retrieved by directly calling $lesson->context;
|
protected |
Course object gets set and retrieved by directly calling $lesson->courserecord;
|
protected |
The id of the first page (where prevpageid = 0) gets set and retrieved by {.
$lesson->firstpageid;
|
protected |
The id of the last page (where nextpageid = 0) gets set and retrieved by {.
$lesson->lastpageid;
|
protected |
An array used to cache the pages associated with this lesson after the first time they have been loaded.
A note to developers: If you are going to be working with MORE than one or two pages from a lesson you should probably call {