Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lesson Class Reference
Inheritance diagram for lesson:
lesson_base

Public Member Functions

 __construct ($properties, $cm=null, $course=null)
 Constructor method. More...
 
 __get ($key)
 Magic get method. More...
 
 __isset ($key)
 Stupid PHP needs an isset magic method if you use the get magic method and still want empty calls to work.... More...
 
 __set ($key, $value)
 Magic property method. More...
 
 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. More...
 
 add_messages_on_page_process (lesson_page $page, $result, $reviewmode)
 Add different informative messages to the given page. More...
 
 add_messages_on_page_view (lesson_page $page, $reviewmode)
 Add different informative messages to the given page. More...
 
 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. More...
 
 calculate_progress ()
 Calculate the progress of the current user in the lesson. More...
 
 can_manage ()
 Check if the user can manage the lesson activity. More...
 
 check_time ($timer)
 Check if the user is out of time in a timed lesson. More...
 
 cluster_jump ($pageid, $userid=null)
 Interprets LESSON_CLUSTERJUMP jumpto value. More...
 
 count_user_retries ($userid)
 Return the number of retries in a lesson for a given user. More...
 
 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. More...
 
 duplicate_page ($pageid)
 Duplicate the lesson page. More...
 
 get_attempts ($retries, $correct=false, $pageid=null, $userid=null)
 Get all of the attempts for the current user. More...
 
 get_cm ()
 Return the lesson course module object. More...
 
 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. More...
 
 get_context ()
 Return the lesson context object. More...
 
 get_courserecord ()
 Return the lesson course object. More...
 
 get_dependencies_restriction_status ()
 Check if dependencies restrictions are applied. More...
 
 get_last_page_seen ($retriescount)
 Return the last page the current user saw. More...
 
 get_lastpageid ()
 Returns the id of the last page of this lesson. More...
 
 get_next_page ($nextpageid)
 Gets the next page id to display after the one that is provided. More...
 
 get_ongoing_score_message ()
 Get the ongoing score message for the user (depending on the user permission and lesson settings). More...
 
 get_password_restriction_status ($userpassword)
 Check if password restriction is applied. More...
 
 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. More...
 
 get_time_restriction_status ()
 Check if time restriction is applied. More...
 
 get_user_timers ($userid=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0)
 Return the timers in the current lesson for the given user. More...
 
 has_pages ()
 Checks to see if the lesson has pages.
 
 is_accessible ()
 Check if the lesson is accessible at the present time. More...
 
 is_in_review_mode ()
 Check if the lesson is in review mode. More...
 
 is_participant ($userid)
 Checks user enrollment in the current course. More...
 
 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. More...
 
 jumpto_is_correct ($pageid, $jumpto)
 Determines if a jumpto value is correct or not. More...
 
 left_during_timed_session ($retriescount)
 Check if a user left a timed session. More...
 
 link_for_activitylink ()
 Returns the link for the related activity. More...
 
 load_all_pages ()
 Loads ALL of the pages for this lesson. More...
 
 load_page ($pageid)
 Loads the requested page. More...
 
 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). More...
 
 process_eol_page ($outoftime)
 Process and return all the information for the end of lesson page. More...
 
 process_page_responses (lesson_page $page)
 Process page responses. More...
 
 properties ()
 If implemented should create a new instance, save it in the DB and return it. More...
 
 resort_pages ($pageid, $after)
 Move a page resorting all other pages. More...
 
 set_module_viewed ()
 Trigger module viewed event and set the module viewed for completion. More...
 
 show_only_active_users ()
 Check is only active users in course should be shown. More...
 
 start_timer ()
 Starts the lesson time for the current user. More...
 
 stop_timer ()
 Updates the timer to the current time then stops it by unsetting the user var. More...
 
 time_remaining ($starttime)
 Returns the time a user has remaining on this lesson. More...
 
 update_effective_access ($userid)
 Updates the lesson properties with override information for a user. More...
 
 update_timer ($restart=false, $continue=false, $endreached=false)
 Updates the timer to the current time and returns the new timer object. More...
 

Static Public Member Functions

static create ($properties)
 Simply generates a lesson object given an array/object of properties Overrides {. More...
 
static load ($lessonid)
 Generates a lesson object from the database given its id. More...
 

Protected Member Functions

 copy_page_files ($filearea, $itemid, $newitemid, $contextid)
 Copy the files from one page to another. More...
 
 get_firstpage ()
 Returns the first page for the lesson or false if there isn't one. More...
 
 get_firstpageid ()
 Returns the id of the first page of this lesson. More...
 
 get_lastpage ()
 Returns the last page for the lesson or false if there isn't one. More...
 
 get_messages ()
 Fetches messages from the session that may have been set in previous page actions. More...
 

Protected Attributes

stdClass $cm = null
 Course module object gets set and retrieved by directly calling $lesson->cm; More...
 
stdClass $context = null
 Context object gets set and retrieved by directly calling $lesson->context; More...
 
stdClass $courserecord = null
 Course object gets set and retrieved by directly calling $lesson->courserecord; More...
 
int $firstpageid = null
 The id of the first page (where prevpageid = 0) gets set and retrieved by {. More...
 
int $lastpageid = null
 The id of the last page (where nextpageid = 0) gets set and retrieved by {. More...
 
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. More...
 
stdClass $properties
 An object containing properties.
 

Constructor & Destructor Documentation

◆ __construct()

lesson::__construct (   $properties,
  $cm = null,
  $course = null 
)

Constructor method.

Parameters
object$properties
stdClass$cmcourse module object
stdClass$coursecourse object
Since
Moodle 3.3

Member Function Documentation

◆ __get()

lesson_base::__get (   $key)
inherited

Magic get method.

Attempts to call a get_$key method to return the property and ralls over to return the raw property

Parameters
str$key
Return values
mixed

◆ __isset()

lesson_base::__isset (   $key)
inherited

Stupid PHP needs an isset magic method if you use the get magic method and still want empty calls to work....

blah ~!

Parameters
string$key
Return values
bool

◆ __set()

lesson_base::__set (   $key,
  $value 
)
inherited

Magic property method.

Attempts to call a set_$key method if one exists otherwise falls back to simply set the property

Parameters
string$key
mixed$value

◆ add_message()

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.

Parameters
string$message
string$class
string$align
Return values
bool

◆ add_messages_on_page_process()

lesson::add_messages_on_page_process ( lesson_page  $page,
  $result,
  $reviewmode 
)

Add different informative messages to the given page.

Parameters
lesson_page$pagepage object
stdClass$resultthe page processing result object
bool$reviewmodewhether we are in review mode or not
Since
Moodle 3.3

◆ add_messages_on_page_view()

lesson::add_messages_on_page_view ( lesson_page  $page,
  $reviewmode 
)

Add different informative messages to the given page.

Parameters
lesson_page$pagepage object
reviewmode$boolwhether we are in review mode or not
Since
Moodle 3.3

◆ calculate_new_page_on_jump()

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.

Parameters
lesson_page$pagelesson page
int$newpageidthe new page id
Return values
intthe real page to jump to (or end of lesson)
Since
Moodle 3.3

◆ calculate_progress()

lesson::calculate_progress ( )

Calculate the progress of the current user in the lesson.

Return values
intthe progress (scale 0-100)
Since
Moodle 3.3

◆ can_manage()

lesson::can_manage ( )

Check if the user can manage the lesson activity.

Return values
booltrue if the user can manage the lesson
Since
Moodle 3.3

◆ check_time()

lesson::check_time (   $timer)

Check if the user is out of time in a timed lesson.

Parameters
stdClass$timertimer object
Return values
boolTrue if the user is on time, false is the user ran out of time
Since
Moodle 3.3

◆ cluster_jump()

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).

Parameters
int$pageidId of the current page from which we are jumping from.
int$useridId of the user.
Return values
intThe id of the next page.

◆ copy_page_files()

lesson::copy_page_files (   $filearea,
  $itemid,
  $newitemid,
  $contextid 
)
protected

Copy the files from one page to another.

Parameters
string$fileareaArea that the files are stored.
int$itemidItem ID.
int$newitemidThe item ID for the new page.
int$contextidContext ID for this page.
Return values
void.

◆ count_user_retries()

lesson::count_user_retries (   $userid)

Return the number of retries in a lesson for a given user.

Parameters
int$useridthe user id
Return values
intthe retries count
Since
Moodle 3.3

◆ create()

static lesson::create (   $properties)
static

Simply generates a lesson object given an array/object of properties Overrides {.

See also
lesson_base->create()}
Parameters
object | array$properties
Return values
lesson

◆ delete_override()

lesson::delete_override (   $overrideid)

Deletes a lesson override from the database and clears any corresponding calendar events.

Parameters
int$overrideidThe id of the override being deleted
Return values
booltrue on success

◆ duplicate_page()

lesson::duplicate_page (   $pageid)

Duplicate the lesson page.

Parameters
int$pageidPage ID of the page to duplicate.
Return values
void.

◆ get_attempts()

lesson::get_attempts (   $retries,
  $correct = false,
  $pageid = null,
  $userid = null 
)

Get all of the attempts for the current user.

Parameters
int$retries
bool$correctOptional: only fetch correct attempts
int$pageidOptional: only fetch attempts at the given page
int$useridOptional: defaults to the current user if not set
Return values
array|false

◆ get_cm()

lesson::get_cm ( )

Return the lesson course module object.

Return values
stdClasscourse module
Since
Moodle 3.3

◆ get_content_pages_viewed()

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.

Parameters
int$lessonattemptthe lesson attempt number (also known as retries)
int$useridthe user id to retrieve the data from
string$sortan order to sort the results in (a valid SQL ORDER BY parameter)
string$fieldsa comma separated list of fields to return
Return values
arrayof pages
Since
Moodle 3.3

◆ get_context()

lesson::get_context ( )

Return the lesson context object.

Return values
stdClasscontext
Since
Moodle 3.3

◆ get_courserecord()

lesson::get_courserecord ( )

Return the lesson course object.

Return values
stdClasscourse
Since
Moodle 3.3

◆ get_dependencies_restriction_status()

lesson::get_dependencies_restriction_status ( )

Check if dependencies restrictions are applied.

Return values
mixedfalse if there aren't restrictions or an object with the restriction information
Since
Moodle 3.3

◆ get_firstpage()

lesson::get_firstpage ( )
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;

Return values
lesson_page|boolReturns the lesson_page specialised object or false

◆ get_firstpageid()

lesson::get_firstpageid ( )
protected

Returns the id of the first page of this lesson.

(prevpageid = 0)

Return values
int

◆ get_last_page_seen()

lesson::get_last_page_seen (   $retriescount)

Return the last page the current user saw.

Parameters
int$retriescountthe number of retries for the lesson (the last retry number).
Return values
mixedfalse if the user didn't see the lesson or the last page id

◆ get_lastpage()

lesson::get_lastpage ( )
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;

Return values
lesson_page|boolReturns the lesson_page specialised object or false

◆ get_lastpageid()

lesson::get_lastpageid ( )

Returns the id of the last page of this lesson.

(nextpageid = 0)

Return values
int

◆ get_messages()

lesson::get_messages ( )
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;

Return values
array

◆ get_next_page()

lesson::get_next_page (   $nextpageid)

Gets the next page id to display after the one that is provided.

Parameters
int$nextpageid
Return values
bool

◆ get_ongoing_score_message()

lesson::get_ongoing_score_message ( )

Get the ongoing score message for the user (depending on the user permission and lesson settings).

Return values
strthe ongoing score message
Since
Moodle 3.3

◆ get_password_restriction_status()

lesson::get_password_restriction_status (   $userpassword)

Check if password restriction is applied.

Parameters
string$userpasswordthe user password to check (if the restriction is set)
Return values
mixedfalse if there aren't restrictions or an object with the restriction information
Since
Moodle 3.3

◆ get_sub_pages_of()

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.

Parameters
int$pageid
array$endsAn array of LESSON_PAGE_* types that signify an end of the subtype
Return values
arrayAn array of specialised lesson_page objects

◆ get_time_restriction_status()

lesson::get_time_restriction_status ( )

Check if time restriction is applied.

Return values
mixedfalse if there aren't restrictions or an object with the restriction information
Since
Moodle 3.3

◆ get_user_timers()

lesson::get_user_timers (   $userid = null,
  $sort = '',
  $fields = '*',
  $limitfrom = 0,
  $limitnum = 0 
)

Return the timers in the current lesson for the given user.

Parameters
int$useridthe user id
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter).
string$fieldsa comma separated list of fields to return
int$limitfromreturn a subset of records, starting at this point (optional).
int$limitnumreturn a subset comprising this many records in total (optional, required if $limitfrom is set).
Return values
arraylist of timers for the given user in the lesson
Since
Moodle 3.3

◆ is_accessible()

lesson::is_accessible ( )

Check if the lesson is accessible at the present time.

Return values
boolTrue if the lesson is accessible, false otherwise

◆ is_in_review_mode()

lesson::is_in_review_mode ( )

Check if the lesson is in review mode.

(The user already finished it and retakes are not allowed).

Return values
booltrue if is in review mode
Since
Moodle 3.3

◆ is_participant()

lesson::is_participant (   $userid)

Checks user enrollment in the current course.

Parameters
int$userid
Return values
null|stdClassuser record

◆ is_sub_page_of_type()

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.

Parameters
int$pageidThe id of the page to check
array$typesAn array of types that would signify this page was a subpage
array$endsAn array of types that mean this is not a subpage
Return values
bool

◆ jumpto_is_correct()

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.

Parameters
int$pageidId of the page from which you are jumping from.
int$jumptoThe jumpto number.
Return values
booleanTrue or false after a series of tests.

◆ left_during_timed_session()

lesson::left_during_timed_session (   $retriescount)

Check if a user left a timed session.

Parameters
int$retriescountthe number of retries for the lesson (the last retry number).
Return values
trueif the user left the timed session
Since
Moodle 3.3

◆ link_for_activitylink()

lesson::link_for_activitylink ( )

Returns the link for the related activity.

Return values
string

◆ load()

static lesson::load (   $lessonid)
static

Generates a lesson object from the database given its id.

Parameters
int$lessonid
Return values
lesson

◆ load_all_pages()

lesson::load_all_pages ( )

Loads ALL of the pages for this lesson.

Return values
arrayAn array containing all pages from this lesson

◆ load_page()

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

Parameters
int$pageid
Return values
lesson_pageA lesson_page object or an object that extends it

◆ prepare_page_and_contents()

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).

Parameters
int$pageidthe given page id
mod_lesson_renderer$lessonoutputthe lesson output rendered
bool$reviewmodewhether we are in review mode or not
bool$redirectOptional, default to true. Set to false to avoid redirection and return the page to redirect.
Return values
arraythe page object and contents
Exceptions
moodle_exception
Since
Moodle 3.3

◆ process_eol_page()

lesson::process_eol_page (   $outoftime)

Process and return all the information for the end of lesson page.

Parameters
string$outoftimeused to check to see if the student ran out of time
Return values
stdclassan object with all the page data ready for rendering
Since
Moodle 3.3

◆ process_page_responses()

lesson::process_page_responses ( lesson_page  $page)

Process page responses.

Parameters
lesson_page$pagepage object
Since
Moodle 3.3

◆ properties()

lesson_base::properties ( )
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

Return values
stdClass

Reimplemented in lesson_page.

◆ resort_pages()

lesson::resort_pages (   $pageid,
  $after 
)

Move a page resorting all other pages.

Parameters
int$pageid
int$after
Return values
void

◆ set_module_viewed()

lesson::set_module_viewed ( )

Trigger module viewed event and set the module viewed for completion.

Since
Moodle 3.3

◆ show_only_active_users()

lesson::show_only_active_users ( )

Check is only active users in course should be shown.

Return values
booltrue if only active users should be shown.

◆ start_timer()

lesson::start_timer ( )

Starts the lesson time for the current user.

Return values
boolReturns true

◆ stop_timer()

lesson::stop_timer ( )

Updates the timer to the current time then stops it by unsetting the user var.

Return values
boolReturns true

◆ time_remaining()

lesson::time_remaining (   $starttime)

Returns the time a user has remaining on this lesson.

Parameters
int$starttimeStarttime timestamp
Return values
string

◆ update_effective_access()

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.

Parameters
int$useridThe userid.

◆ update_timer()

lesson::update_timer (   $restart = false,
  $continue = false,
  $endreached = false 
)

Updates the timer to the current time and returns the new timer object.

Parameters
bool$restartIf set to true the timer is restarted
bool$continueIf set to true AND $restart=true then the timer will continue from a previous attempt
Return values
stdClassThe new timer

Member Data Documentation

◆ $cm

stdClass lesson::$cm = null
protected

Course module object gets set and retrieved by directly calling $lesson->cm;

See also
get_cm()

◆ $context

stdClass lesson::$context = null
protected

Context object gets set and retrieved by directly calling $lesson->context;

See also
get_context()

◆ $courserecord

stdClass lesson::$courserecord = null
protected

Course object gets set and retrieved by directly calling $lesson->courserecord;

See also
get_courserecord()

◆ $firstpageid

int lesson::$firstpageid = null
protected

The id of the first page (where prevpageid = 0) gets set and retrieved by {.

See also
get_firstpageid()} by directly calling $lesson->firstpageid;

◆ $lastpageid

int lesson::$lastpageid = null
protected

The id of the last page (where nextpageid = 0) gets set and retrieved by {.

See also
get_lastpageid()} by directly calling $lesson->lastpageid;

◆ $pages

array lesson::$pages = array()
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 {

See also
$lesson->load_all_pages()} in order to save excess database queries. An array of lesson_page objects

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