Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/mod/lesson/ -> lib.php (source)

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

Standard library of functions and constants for lesson

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1742 lines (63 kb)
Included or required:0 times
Referenced: 2 times
Includes or requires: 1 file
 mod/lesson/deprecatedlib.php

Defines 38 functions


Functions that are not part of a class:

lesson_add_instance($data, $mform)   X-Ref
Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will create a new instance and return the id number
of the new instance.

param: object $lesson Lesson post data from the form
return: int

lesson_update_instance($data, $mform)   X-Ref
Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will update an existing instance with new data.

param: object $lesson Lesson post data from the form
return: boolean

lesson_update_events($lesson, $override = null)   X-Ref
This function updates the events associated to the lesson.
If $override is non-zero, then it updates only the events
associated with the specified override.

param: object $lesson the lesson object.
param: object $override (optional) limit to a specific override

lesson_get_group_override_priorities($lessonid)   X-Ref
Calculates the priorities of timeopen and timeclose values for group overrides for a lesson.

param: int $lessonid The lesson ID.
return: array|null Array of group override priorities for open and close times. Null if there are no group overrides.

lesson_refresh_events($courseid = 0, $instance = null, $cm = null)   X-Ref
This standard function will check all instances of this module
and make sure there are up-to-date events created for each of them.
If courseid = 0, then every lesson event in the site is checked, else
only lesson events belonging to the course specified are checked.
This function is used, in its new format, by restore_refresh_events()

param: int $courseid
param: int|stdClass $instance Lesson module instance or ID.
param: int|stdClass $cm Course module object or ID (not used in this module).
return: bool

lesson_delete_instance($id)   X-Ref
Given an ID of an instance of this module,
this function will permanently delete the instance
and any data that depends on it.

param: int $id
return: bool

lesson_user_outline($course, $user, $mod, $lesson)   X-Ref
Return a small object with summary information about what a
user has done with a given particular instance of this module
Used for user activity reports.
$return->time = the time they did it
$return->info = a short text description

param: object $course
param: object $user
param: object $mod
param: object $lesson
return: object

lesson_user_complete($course, $user, $mod, $lesson)   X-Ref
Print a detailed representation of what a  user has done with
a given particular instance of this module, for user activity reports.

param: object $course
param: object $user
param: object $mod
param: object $lesson
return: bool

lesson_print_overview()   X-Ref


lesson_cron()   X-Ref
Function to be run periodically according to the moodle cron
This function searches for things that need to be done, such
as sending out mail, toggling flags etc ...

return: bool true

lesson_get_user_grades($lesson, $userid=0)   X-Ref
Return grade for given user or all users.

param: int $lessonid id of lesson
param: int $userid optional user id, 0 means all users
return: array array of grades, false if none

lesson_update_grades($lesson, $userid=0, $nullifnone=true)   X-Ref
Update grades in central gradebook

param: object $lesson
param: int $userid specific user only, 0 means all
param: bool $nullifnone

lesson_grade_item_update($lesson, $grades=null)   X-Ref
Create grade item for given lesson

param: object $lesson object with extra cmidnumber
param: array|object $grades optional array/object of grade(s); 'reset' means reset grades in gradebook
return: int 0 if ok, error code otherwise

lesson_get_view_actions()   X-Ref
List the actions that correspond to a view of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = 'r' and edulevel = LEVEL_PARTICIPATING will
be considered as view action.

return: array

lesson_get_post_actions()   X-Ref
List the actions that correspond to a post of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING
will be considered as post action.

return: array

lesson_process_pre_save(&$lesson)   X-Ref
Runs any processes that must run before
a lesson insert/update

param: object $lesson Lesson form data
return: void

lesson_process_post_save(&$lesson)   X-Ref
Runs any processes that must be run
after a lesson insert/update

param: object $lesson Lesson form data
return: void

lesson_reset_course_form_definition(&$mform)   X-Ref
Implementation of the function for printing the form elements that control
whether the course reset functionality affects the lesson.

param: $mform form passed by reference

lesson_reset_course_form_defaults($course)   X-Ref
Course reset form defaults.

param: object $course
return: array

lesson_reset_gradebook($courseid, $type='')   X-Ref
Removes all grades from gradebook

param: int $courseid
param: string optional type

lesson_reset_userdata($data)   X-Ref
Actual implementation of the reset course functionality, delete all the
lesson attempts for course $data->courseid.

param: object $data the data submitted from the reset course.
return: array status array

lesson_supports($feature)   X-Ref

param: string $feature FEATURE_xx constant for requested feature
return: mixed True if module supports feature, false if not, null if doesn't know or string for the module purpose.

lesson_extend_settings_navigation(settings_navigation $settings, navigation_node $lessonnode)   X-Ref
This function extends the settings navigation block for the site.

It is safe to rely on PAGE here as we will only ever be within the module
context when this is called

param: settings_navigation $settings
param: navigation_node $lessonnode

lesson_get_import_export_formats($type)   X-Ref
Get list of available import or export formats

Copied and modified from lib/questionlib.php

param: string $type 'import' if import list, otherwise export list assumed
return: array sorted list of import/export formats available

lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()   X-Ref
Serves the lesson attachments. Implements needed access control ;-)

param: stdClass $course course object
param: stdClass $cm course module object
param: stdClass $context context object
param: string $filearea file area
param: array $args extra arguments
param: bool $forcedownload whether or not force download
param: array $options additional options affecting the file serving
return: bool false if file not found, does not return if found - justsend the file

lesson_get_file_areas()   X-Ref
Returns an array of file areas

return: array a list of available file areas

lesson_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename)   X-Ref
Returns a file_info_stored object for the file being requested here

param: file_browse $browser file browser instance
param: array $areas file areas
param: stdClass $course course object
param: stdClass $cm course module object
param: stdClass $context context object
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info_stored

lesson_page_type_list($pagetype, $parentcontext, $currentcontext)   X-Ref
Return a list of page types

param: string $pagetype current page type
param: stdClass $parentcontext Block's parent context
param: stdClass $currentcontext Current context of block

lesson_update_media_file($lessonid, $context, $draftitemid)   X-Ref
Update the lesson activity to include any file
that was uploaded, or if there is none, set the
mediafile field to blank.

param: int $lessonid the lesson id
param: stdClass $context the context
param: int $draftitemid the draft item

mod_lesson_get_fontawesome_icon_map()   X-Ref
Get icon mapping for font-awesome.


lesson_check_updates_since(cm_info $cm, $from, $filter = array()   X-Ref
No description

mod_lesson_core_calendar_provide_event_action(calendar_event $event,\core_calendar\action_factory $factory,int $userid = 0)   X-Ref
This function receives a calendar event and returns the action associated with it, or null if there is none.

This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
is not displayed on the block.

param: calendar_event $event
param: \core_calendar\action_factory $factory
param: int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
return: \core_calendar\local\event\entities\action_interface|null

lesson_get_coursemodule_info($coursemodule)   X-Ref
Add a get_coursemodule_info function in case any lesson type wants to add 'extra' information
for the course (see resource).

Given a course_module object, this function returns any "extra" information that may be needed
when printing this activity in a course listing.  See get_array_of_activities() in course/lib.php.

param: stdClass $coursemodule The coursemodule object (record).
return: cached_cm_info An object on information that the courses

mod_lesson_cm_info_dynamic(cm_info $cm)   X-Ref
Sets dynamic information about a course module

This function is called from cm_info when displaying the module

param: cm_info $cm

mod_lesson_get_completion_active_rule_descriptions($cm)   X-Ref
Callback which returns human-readable strings describing the active completion custom rules for the module instance.

param: cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules']
return: array $descriptions the array of descriptions for the custom rules.

mod_lesson_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance)   X-Ref
This function calculates the minimum and maximum cutoff values for the timestart of
the given event.

It will return an array with two values, the first being the minimum cutoff value and
the second being the maximum cutoff value. Either or both values can be null, which
indicates there is no minimum or maximum, respectively.

If a cutoff is required then the function must return an array containing the cutoff
timestamp and error string to display to the user if the cutoff value is violated.

A minimum and maximum cutoff return value will look like:
[
[1505704373, 'The due date must be after the start date'],
[1506741172, 'The due date must be before the cutoff date']
]

param: calendar_event $event The calendar event to get the time range for
param: stdClass $instance The module instance to get the range from
return: array

mod_lesson_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $lesson)   X-Ref
This function will update the lesson module according to the
event that has been modified.

It will set the available or deadline value of the lesson instance
according to the type of event provided.

param: \calendar_event $event
param: stdClass $lesson The module instance to get the range from

mod_lesson_core_calendar_get_event_action_string(string $eventtype)   X-Ref
Callback to fetch the activity event type lang string.

param: string $eventtype The event type.
return: lang_string The event type lang string.