Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/mod/lesson/ -> lib.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 402] [Versions 400 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: 0 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.

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

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.

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

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.

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

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

return: bool
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).

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.

return: bool
param: int $id

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

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

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.

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

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.

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

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

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

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

return: void
param: object $lesson Lesson form data

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

return: void
param: object $lesson Lesson form data

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.

return: array
param: object $course

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.

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

lesson_supports($feature)   X-Ref

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

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

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

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

return: bool false if file not found, does not return if found - justsend the file
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

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

return: file_info_stored
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

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.

return: \core_calendar\local\event\entities\action_interface|null
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).

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.

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

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.

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

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']
]

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

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.

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