Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/course/ -> lib.php (source)

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

Library of useful functions

Copyright: 1999 Martin Dougiamas http://dougiamas.com
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 4883 lines (192 kb)
Included or required: 13 times
Referenced: 42 times
Includes or requires: 0 files

Defines 1 class

course_request:: (55 methods):
  prepare()
  create()
  summary_editor_options()
  __construct()
  __get()
  __isset()
  get_requester()
  check_shortname_collision()
  can_approve()
  get_category()
  approve()
  reject()
  delete()
  notify()
  can_request()
  course_page_type_list()
  course_ajax_enabled()
  include_course_ajax()
  get_sorted_course_formats()
  course_get_url()
  create_module()
  update_module()
  mod_duplicate_activity()
  duplicate_module()
  compare_activities_by_time_desc()
  compare_activities_by_time_asc()
  course_change_visibility()
  course_change_sortorder_by_one()
  course_change_sortorder_after_course()
  course_view()
  course_get_tagged_courses()
  core_course_inplace_editable()
  core_course_core_calendar_get_valid_event_timestart_range()
  course_get_tagged_course_modules()
  course_get_user_navigation_options()
  course_get_user_administration_options()
  course_validate_dates()
  course_check_updates()
  course_classify_for_timeline()
  course_classify_end_date()
  course_classify_start_date()
  course_classify_courses_for_timeline()
  course_get_enrolled_courses_for_logged_in_user()
  course_filter_courses_by_timeline_classification()
  course_filter_courses_by_favourites()
  course_filter_courses_by_customfield()
  course_check_module_updates_since()
  course_can_view_participants()
  course_require_view_participants()
  can_download_from_backup_filearea()
  get_hidden_courses_on_timeline()
  course_get_recent_courses()
  course_get_course_dates_for_user_ids()
  course_get_course_dates_for_user_id()
  course_output_fragment_new_base_form()

Defines 55 functions


Class: course_request  - X-Ref

This class pertains to course requests and contains methods associated with
create, approving, and removing course requests.

Please note we do not allow embedded images here because there is no context
to store them with proper access control.

prepare($data=null)   X-Ref
Static function to prepare the summary editor for working with a course
request.

param: null|stdClass $data Optional, an object containing the default values
return: stdClass An object that can be used to set the default values for

create($data)   X-Ref
Static function to create a new course request when passed an array of properties
for it.

This function also handles saving any files that may have been used in the editor

param: stdClass $data
return: course_request The newly created course request

summary_editor_options()   X-Ref
Returns an array of options to use with a summary editor

return: array An array of options to use with the editor

__construct($properties)   X-Ref
Loads the properties for this course request object. Id is required and if
only id is provided then we load the rest of the properties from the database

param: stdClass|int $properties Either an object containing properties

__get($key)   X-Ref
Returns the requested property

param: string $key
return: mixed

__isset($key)   X-Ref
Override this to ensure empty($request->blah) calls return a reliable answer...

This is required because we define the __get method

param: mixed $key
return: bool True is it not empty, false otherwise

get_requester()   X-Ref
Returns the user who requested this course

Uses a static var to cache the results and cut down the number of db queries

return: stdClass The user who requested the course

check_shortname_collision($shortnamemark = '[*]')   X-Ref
Checks that the shortname used by the course does not conflict with any other
courses that exist

param: string|null $shortnamemark The string to append to the requests shortname
return: bool true is there is a conflict, false otherwise

can_approve()   X-Ref
Checks user capability to approve a requested course

If course was requested without category for some reason (might happen if $CFG->defaultrequestcategory is
misconfigured), we check capabilities 'moodle/site:approvecourse' and 'moodle/course:changecategory'.

return: bool

get_category()   X-Ref
Returns the category where this course request should be created

Note that we don't check here that user has a capability to view
hidden categories if he has capabilities 'moodle/site:approvecourse' and
'moodle/course:changecategory'

return: core_course_category

approve()   X-Ref
This function approves the request turning it into a course

This function converts the course request into a course, at the same time
transferring any files used in the summary to the new course and then removing
the course request and the files associated with it.

return: int The id of the course that was created from this request

reject($notice)   X-Ref
Reject a course request

This function rejects a course request, emailing the requesting user the
provided notice and then removing the request from the database

param: string $notice The message to display to the user

delete()   X-Ref
Deletes the course request and any associated files


notify($touser, $fromuser, $name, $subject, $message, $courseid = null)   X-Ref
Send a message from one user to another using events_trigger

param: object $touser
param: object $fromuser
param: string $name
param: string $subject
param: string $message
param: int|null $courseid

can_request(context $context)   X-Ref
Checks if current user can request a course in this context

param: context $context
return: bool

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

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

course_ajax_enabled($course)   X-Ref
Determine whether course ajax should be enabled for the specified course

param: stdClass $course The course to test against
return: boolean Whether course ajax is enabled or note

include_course_ajax($course, $usedmodules = array()   X-Ref
Include the relevant javascript and language strings for the resource
toolbox YUI module

param: integer $id The ID of the course being applied to
param: array $usedmodules An array containing the names of the modules in use on the page
param: array $enabledmodules An array containing the names of the enabled (visible) modules on this site
param: stdClass $config An object containing configuration parameters for ajax modules including:
return: bool

get_sorted_course_formats($enabledonly = false)   X-Ref
Returns the sorted list of available course formats, filtered by enabled if necessary

param: bool $enabledonly return only formats that are enabled
return: array array of sorted format names

course_get_url($courseorid, $section = null, $options = array()   X-Ref
The URL to use for the specified course (with section)

param: int|stdClass $courseorid The course to get the section name for (either object or just course id)
param: int|stdClass $section Section object from database or just field course_sections.section
param: array $options options for view URL. At the moment core uses:
return: moodle_url The url of course

create_module($moduleinfo)   X-Ref
Create a module.

It includes:
- capability checks and other checks
- create the module from the module info

param: object $module
return: object the created module info

update_module($moduleinfo)   X-Ref
Update a module.

It includes:
- capability and other checks
- update the module

param: object $module
return: object the updated module info

mod_duplicate_activity($course, $cm, $sr = null)   X-Ref
Duplicate a module on the course for ajax.

param: object $course The course
param: object $cm The course module to duplicate
param: int $sr The section to link back to (used for creating the links)
return: Object containing:

duplicate_module($course, $cm)   X-Ref
Api to duplicate a module.

param: object $course course object.
param: object $cm course module object to be duplicated.
return: cm_info|null cminfo object if we sucessfully duplicated the mod and found the new cm.

compare_activities_by_time_desc($a, $b)   X-Ref
Compare two objects to find out their correct order based on timestamp (to be used by usort).
Sorts by descending order of time.

param: stdClass $a First object
param: stdClass $b Second object
return: int 0,1,-1 representing the order

compare_activities_by_time_asc($a, $b)   X-Ref
Compare two objects to find out their correct order based on timestamp (to be used by usort).
Sorts by ascending order of time.

param: stdClass $a First object
param: stdClass $b Second object
return: int 0,1,-1 representing the order

course_change_visibility($courseid, $show = true)   X-Ref
Changes the visibility of a course.

param: int $courseid The course to change.
param: bool $show True to make it visible, false otherwise.
return: bool

course_change_sortorder_by_one($course, $up)   X-Ref
Changes the course sortorder by one, moving it up or down one in respect to sort order.

param: stdClass|core_course_list_element $course
param: bool $up If set to true the course will be moved up one. Otherwise down one.
return: bool

course_change_sortorder_after_course($courseorid, $moveaftercourseid)   X-Ref
Changes the sort order of courses in a category so that the first course appears after the second.

param: int|stdClass $courseorid The course to focus on.
param: int $moveaftercourseid The course to shifter after or 0 if you want it to be the first course in the category.
return: bool

course_view($context, $sectionnumber = 0)   X-Ref
Trigger course viewed event. This API function is used when course view actions happens,
usually in course/view.php but also in external functions.

param: stdClass  $context course context object
param: int $sectionnumber section number

course_get_tagged_courses($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0)   X-Ref
Returns courses tagged with a specified tag.

param: core_tag_tag $tag
param: bool $exclusivemode if set to true it means that no other entities tagged with this tag
param: int $fromctx context id where the link was displayed, may be used by callbacks
param: int $ctx context id where to search for records
param: bool $rec search in subcontexts as well
param: int $page 0-based number of page being displayed
return: \core_tag\output\tagindex

core_course_inplace_editable($itemtype, $itemid, $newvalue)   X-Ref
Implements callback inplace_editable() allowing to edit values in-place

param: string $itemtype
param: int $itemid
param: mixed $newvalue
return: \core\output\inplace_editable

core_course_core_calendar_get_valid_event_timestart_range(\calendar_event $event, $course)   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 date must be after this date'],
[1506741172, 'The date must be before this date']
]

param: calendar_event $event The calendar event to get the time range for
param: stdClass $course The course object to get the range from
return: array Returns an array with min and max date.

course_get_tagged_course_modules($tag, $exclusivemode = false, $fromcontextid = 0, $contextid = 0,$recursivecontext = 1, $page = 0)   X-Ref
Returns course modules tagged with a specified tag ready for output on tag/index.php page

This is a callback used by the tag area core/course_modules to search for course modules
tagged with a specific tag.

param: core_tag_tag $tag
param: bool $exclusivemode if set to true it means that no other entities tagged with this tag
param: int $fromcontextid context id where the link was displayed, may be used by callbacks
param: int $contextid context id where to search for records
param: bool $recursivecontext search in subcontexts as well
param: int $page 0-based number of page being displayed
return: \core_tag\output\tagindex

course_get_user_navigation_options($context, $course = null)   X-Ref
Return an object with the list of navigation options in a course that are avaialable or not for the current user.
This function also handles the frontpage course.

param: stdClass $context context object (it can be a course context or the system context for frontpage settings)
param: stdClass $course  the course where the settings are being rendered
return: stdClass          the navigation options in a course and their availability status

course_get_user_administration_options($course, $context)   X-Ref
Return an object with the list of administration options in a course that are available or not for the current user.
This function also handles the frontpage settings.

param: stdClass $course  course object (for frontpage it should be a clone of $SITE)
param: stdClass $context context object (course context)
return: stdClass          the administration options in a course and their availability status

course_validate_dates($coursedata)   X-Ref
Validates course start and end dates.

Checks that the end course date is not greater than the start course date.

$coursedata['startdate'] or $coursedata['enddate'] may not be set, it depends on the form and user input.

param: array $coursedata May contain startdate and enddate timestamps, depends on the user input.
return: mixed False if everything alright, error codes otherwise.

course_check_updates($course, $tocheck, $filter = array()   X-Ref
Check for course updates in the given context level instances (only modules supported right Now)

param: stdClass $course  course object
param: array $tocheck    instances to check for updates
param: array $filter check only for updates in these areas
return: array list of warnings and instances with updates information

course_classify_for_timeline($course, $user = null, $completioninfo = null)   X-Ref
This function classifies a course as past, in progress or future.

This function may incur a DB hit to calculate course completion.
param: stdClass $course Course record
param: stdClass $user User record (optional - defaults to $USER).
param: completion_info $completioninfo Completion record for the user (optional - will be fetched if required).
return: string (one of COURSE_TIMELINE_FUTURE, COURSE_TIMELINE_INPROGRESS or COURSE_TIMELINE_PAST)

course_classify_end_date($course)   X-Ref
This function calculates the end date to use for display classification purposes,
incorporating the grace period, if any.

param: stdClass $course The course record.
return: int The new enddate.

course_classify_start_date($course)   X-Ref
This function calculates the start date to use for display classification purposes,
incorporating the grace period, if any.

param: stdClass $course The course record.
return: int The new startdate.

course_classify_courses_for_timeline(array $courses)   X-Ref
Group a list of courses into either past, future, or in progress.

The return value will be an array indexed by the COURSE_TIMELINE_* constants
with each value being an array of courses in that group.
E.g.
[
COURSE_TIMELINE_PAST => [... list of past courses ...],
COURSE_TIMELINE_FUTURE => [],
COURSE_TIMELINE_INPROGRESS => []
]

param: array $courses List of courses to be grouped.
return: array

course_get_enrolled_courses_for_logged_in_user(int $limit = 0,int $offset = 0,string $sort = null,string $fields = null,int $dbquerylimit = COURSE_DB_QUERY_LIMIT,array $includecourses = [],array $hiddencourses = [])   X-Ref
Get the list of enrolled courses for the current user.

This function returns a Generator. The courses will be loaded from the database
in chunks rather than a single query.

param: int $limit Restrict result set to this amount
param: int $offset Skip this number of records from the start of the result set
param: string|null $sort SQL string for sorting
param: string|null $fields SQL string for fields to be returned
param: int $dbquerylimit The number of records to load per DB request
param: array $includecourses courses ids to be restricted
param: array $hiddencourses courses ids to be excluded
return: Generator

course_filter_courses_by_timeline_classification($courses,string $classification,int $limit = 0)   X-Ref
Search the given $courses for any that match the given $classification up to the specified
$limit.

This function will return the subset of courses that match the classification as well as the
number of courses it had to process to build that subset.

It is recommended that for larger sets of courses this function is given a Generator that loads
the courses from the database in chunks.

param: array|Traversable $courses List of courses to process
param: string $classification One of the COURSE_TIMELINE_* constants
param: int $limit Limit the number of results to this amount
return: array First value is the filtered courses, second value is the number of courses processed

course_filter_courses_by_favourites($courses,$favouritecourseids,int $limit = 0)   X-Ref
Search the given $courses for any that match the given $classification up to the specified
$limit.

This function will return the subset of courses that are favourites as well as the
number of courses it had to process to build that subset.

It is recommended that for larger sets of courses this function is given a Generator that loads
the courses from the database in chunks.

param: array|Traversable $courses List of courses to process
param: array $favouritecourseids Array of favourite courses.
param: int $limit Limit the number of results to this amount
return: array First value is the filtered courses, second value is the number of courses processed

course_filter_courses_by_customfield($courses,$customfieldname,$customfieldvalue,int $limit = 0)   X-Ref
Search the given $courses for any that have a $customfieldname value that matches the given
$customfieldvalue, up to the specified $limit.

This function will return the subset of courses that matches the value as well as the
number of courses it had to process to build that subset.

It is recommended that for larger sets of courses this function is given a Generator that loads
the courses from the database in chunks.

param: array|Traversable $courses List of courses to process
param: string $customfieldname the shortname of the custom field to match against
param: string $customfieldvalue the value this custom field needs to match
param: int $limit Limit the number of results to this amount
return: array First value is the filtered courses, second value is the number of courses processed

course_check_module_updates_since($cm, $from, $fileareas = array()   X-Ref
Check module updates since a given time.
This function checks for updates in the module config, file areas, completion, grades, comments and ratings.

param: cm_info $cm        course module data
param: int $from          the time to check
param: array $fileareas   additional file ares to check
param: array $filter      if we need to filter and return only selected updates
return: stdClass object with the different updates

course_can_view_participants($context)   X-Ref
Returns true if the user can view the participant page, false otherwise,

param: context $context The context we are checking.
return: bool

course_require_view_participants($context)   X-Ref
Checks if a user can view the participant page, if not throws an exception.

param: context $context The context we are checking.

can_download_from_backup_filearea($filearea, \context $context, stdClass $user = null)   X-Ref
Return whether the user can download from the specified backup file area in the given context.

param: string $filearea the backup file area. E.g. 'course', 'backup' or 'automated'.
param: \context $context
param: stdClass $user the user object. If not provided, the current user will be checked.
return: bool true if the user is allowed to download in the context, false otherwise.

get_hidden_courses_on_timeline($user = null)   X-Ref
Get a list of hidden courses

param: int|object|null $user User override to get the filter from. Defaults to current user
return: array $ids List of hidden courses

course_get_recent_courses(int $userid = null, int $limit = 0, int $offset = 0, string $sort = null)   X-Ref
Returns a list of the most recently courses accessed by a user

param: int $userid User id from which the courses will be obtained
param: int $limit Restrict result set to this amount
param: int $offset Skip this number of records from the start of the result set
param: string|null $sort SQL string for sorting
return: array

course_get_course_dates_for_user_ids(stdClass $course, array $userids)   X-Ref
Calculate the course start date and offset for the given user ids.

If the course is a fixed date course then the course start date will be returned.
If the course is a relative date course then the course date will be calculated and
and offset provided.

The dates are returned as an array with the index being the user id. The array
contains the start date and start offset values for the user.

If the user is not enrolled in the course then the course start date will be returned.

If we have a course which starts on 1563244000 and 2 users, id 123 and 456, where the
former is enrolled in the course at 1563244693 and the latter is not enrolled then the
return value would look like:
[
'123' => [
'start' => 1563244693,
'startoffset' => 693
],
'456' => [
'start' => 1563244000,
'startoffset' => 0
]
]

param: stdClass $course The course to fetch dates for.
param: array $userids The list of user ids to get dates for.
return: array

course_get_course_dates_for_user_id(stdClass $course, int $userid)   X-Ref
Calculate the course start date and offset for the given user id.

If the course is a fixed date course then the course start date will be returned.
If the course is a relative date course then the course date will be calculated and
and offset provided.

The return array contains the start date and start offset values for the user.

If the user is not enrolled in the course then the course start date will be returned.

If we have a course which starts on 1563244000. If a user's enrolment starts on 1563244693
then the return would be:
[
'start' => 1563244693,
'startoffset' => 693
]

If the use was not enrolled then the return would be:
[
'start' => 1563244000,
'startoffset' => 0
]

param: stdClass $course The course to fetch dates for.
param: int $userid The user id to get dates for.
return: array

course_output_fragment_new_base_form($args)   X-Ref
Renders the course copy form for the modal on the course management screen.

param: array $args
return: string $o Form HTML.

Functions that are not part of a class:

make_log_url($module, $url)   X-Ref
No description

build_mnet_logs_array($hostid, $course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',$modname="", $modid=0, $modaction="", $groupid=0)   X-Ref
No description

course_integrity_check($courseid, $rawmods = null, $sections = null, $fullcheck = false, $checkonly = false)   X-Ref
Checks the integrity of the course data.

In summary - compares course_sections.sequence and course_modules.section.

More detailed, checks that:
- course_sections.sequence contains each module id not more than once in the course
- for each moduleid from course_sections.sequence the field course_modules.section
refers to the same section id (this means course_sections.sequence is more
important if they are different)
- ($fullcheck only) each module in the course is present in one of
course_sections.sequence
- ($fullcheck only) removes non-existing course modules from section sequences

If there are any mismatches, the changes are made and records are updated in DB.

Course cache is NOT rebuilt if there are any errors!

This function is used each time when course cache is being rebuilt with $fullcheck = false
and in CLI script admin/cli/fix_course_sequence.php with $fullcheck = true

param: int $courseid id of the course
param: array $rawmods result of funciton {@link get_course_mods()} - containst
param: array $sections records from course_sections table for this course.
param: bool $fullcheck Will add orphaned modules to their sections and remove non-existing
param: bool $checkonly Only performs the check without updating DB, outputs all errors as debug messages.
return: array array of messages with found problems. Empty output means everything is ok

get_array_of_activities($courseid)   X-Ref
For a given course, returns an array of course activity objects
Each item in the array contains he following properties:


get_module_types_names($plural = false)   X-Ref
Returns an array where the key is the module name (component name without 'mod_')
and the value is a lang_string object with a human-readable string.

param: bool $plural If true, the function returns the plural forms of the names.
return: lang_string[] Localised human-readable names of all used modules.

course_set_marker($courseid, $marker)   X-Ref
Set highlighted section. Only one section can be highlighted at the time.

param: int $courseid course id
param: int $marker highlight section with this number, 0 means remove higlightin
return: void

set_section_visible($courseid, $sectionnumber, $visibility)   X-Ref
For a given course section, marks it visible or hidden,
and does the same for every activity in that section

param: int $courseid course id
param: int $sectionnumber The section number to adjust
param: int $visibility The new visibility
return: array A list of resources which were hidden in the section

get_category_or_system_context($categoryid)   X-Ref
Return the course category context for the category with id $categoryid, except
that if $categoryid is 0, return the system context.

param: integer $categoryid a category id or 0.
return: context the corresponding context

print_course_request_buttons($context)   X-Ref
Print the buttons relating to course requests.

param: context $context current page context.

can_edit_in_category($categoryid = 0)   X-Ref
Does the user have permission to edit things in this category?

param: integer $categoryid The id of the category we are showing, or 0 for system context.
return: boolean has_any_capability(array(...), ...); in the appropriate context.

add_course_module($mod)   X-Ref
No description

course_create_section($courseorid, $position = 0, $skipcheck = false)   X-Ref
Creates a course section and adds it to the specified position

param: int|stdClass $courseorid course id or course object
param: int $position position to add to, 0 means to the end. If position is greater than
param: bool $skipcheck the check has already been made and we know that the section with this position does not exist
return: stdClass created section object

course_create_sections_if_missing($courseorid, $sections)   X-Ref
Creates missing course section(s) and rebuilds course cache

param: int|stdClass $courseorid course id or course object
param: int|array $sections list of relative section numbers to create
return: bool if there were any sections created

course_add_cm_to_section($courseorid, $cmid, $sectionnum, $beforemod = null)   X-Ref
Adds an existing module to the section

Updates both tables {course_sections} and {course_modules}

Note: This function does not use modinfo PROVIDED that the section you are
adding the module to already exists. If the section does not exist, it will
build modinfo if necessary and create the section.

param: int|stdClass $courseorid course id or course object
param: int $cmid id of the module already existing in course_modules table
param: int $sectionnum relative number of the section (field course_sections.section)
param: int|stdClass $beforemod id or object with field id corresponding to the module
return: int The course_sections ID where the module is inserted

set_coursemodule_groupmode($id, $groupmode)   X-Ref
Change the group mode of a course module.

Note: Do not forget to trigger the event \core\event\course_module_updated as it needs
to be triggered manually, refer to {@link \core\event\course_module_updated::create_from_cm()}.

param: int $id course module ID.
param: int $groupmode the new groupmode value.
return: bool True if the $groupmode was updated.

set_coursemodule_idnumber($id, $idnumber)   X-Ref
No description

set_coursemodule_visible($id, $visible, $visibleoncoursepage = 1)   X-Ref
Set the visibility of a module and inherent properties.

Note: Do not forget to trigger the event \core\event\course_module_updated as it needs
to be triggered manually, refer to {@link \core\event\course_module_updated::create_from_cm()}.

From 2.4 the parameter $prevstateoverrides has been removed, the logic it triggered
has been moved to {@link set_section_visible()} which was the only place from which
the parameter was used.

param: int $id of the module
param: int $visible state of the module
param: int $visibleoncoursepage state of the module on the course page
return: bool false when the module was not found, true otherwise

set_coursemodule_name($id, $name)   X-Ref
Changes the course module name

param: int $id course module id
param: string $name new value for a name
return: bool whether a change was made

course_delete_module($cmid, $async = false)   X-Ref
This function will handle the whole deletion process of a module. This includes calling
the modules delete_instance function, deleting files, events, grades, conditional data,
the data in the course_module and course_sections table and adding a module deletion
event to the DB.

param: int $cmid the course module id
param: bool $async whether or not to try to delete the module using an adhoc task. Async also depends on a plugin hook.

course_module_flag_for_async_deletion($cmid)   X-Ref
Schedule a course module for deletion in the background using an adhoc task.

This method should not be called directly. Instead, please use course_delete_module($cmid, true), to denote async deletion.
The real deletion of the module is handled by the task, which calls 'course_delete_module($cmid)'.

param: int $cmid the course module id.
return: bool whether the module was successfully scheduled for deletion.

course_modules_pending_deletion(int $courseid, bool $onlygradable = false)   X-Ref
Checks whether the given course has any course modules scheduled for adhoc deletion.

param: int $courseid the id of the course.
param: bool $onlygradable whether to check only gradable modules or all modules.
return: bool true if the course contains any modules pending deletion, false otherwise.

course_module_instance_pending_deletion($courseid, $modulename, $instanceid)   X-Ref
Checks whether the course module, as defined by modulename and instanceid, is scheduled for deletion within the given course.

param: int $courseid the course id.
param: string $modulename the module name. E.g. 'assign', 'book', etc.
param: int $instanceid the module instance id.
return: bool true if the course module is pending deletion, false otherwise.

delete_mod_from_section($modid, $sectionid)   X-Ref
No description

course_module_update_calendar_events($modulename, $instance = null, $cm = null)   X-Ref
This function updates the calendar events from the information stored in the module table and the course
module table.

param: string $modulename Module name
param: stdClass $instance Module object. Either the $instance or the $cm must be supplied.
param: stdClass $cm Course module object. Either the $instance or the $cm must be supplied.
return: bool Returns true if calendar events are updated.

course_module_bulk_update_calendar_events($modulename, $courseid = 0)   X-Ref
Update all instances through out the site or in a course.

param: string  $modulename Module type to update.
param: integer $courseid   Course id to update events. 0 for the whole site.
return: bool Returns True if the update was successful.

course_module_calendar_event_update_process($instance, $cm)   X-Ref
Calendar events for a module instance are updated.

param: stdClass $instance Module instance object.
param: stdClass $cm Course Module object.

move_section_to($course, $section, $destination, $ignorenumsections = false)   X-Ref
Moves a section within a course, from a position to another.
Be very careful: $section and $destination refer to section number,
not id!.

param: object $course
param: int $section Section number (not id!!!)
param: int $destination
param: bool $ignorenumsections
return: boolean Result

course_delete_section($course, $section, $forcedeleteifnotempty = true, $async = false)   X-Ref
This method will delete a course section and may delete all modules inside it.

No permissions are checked here, use {@link course_can_delete_section()} to
check if section can actually be deleted.

param: int|stdClass $course
param: int|stdClass|section_info $section
param: bool $forcedeleteifnotempty if set to false section will not be deleted if it has modules in it.
param: bool $async whether or not to try to delete the section using an adhoc task. Async also depends on a plugin hook.
return: bool whether section was deleted

course_delete_section_async($section, $forcedeleteifnotempty = true)   X-Ref
Course section deletion, using an adhoc task for deletion of the modules it contains.
1. Schedule all modules within the section for adhoc removal.
2. Move all modules to course section 0.
3. Delete the resulting empty section.

param: \stdClass $section the section to schedule for deletion.
param: bool $forcedeleteifnotempty whether to force section deletion if it contains modules.
return: bool true if the section was scheduled for deletion, false otherwise.

course_update_section($course, $section, $data)   X-Ref
Updates the course section

This function does not check permissions or clean values - this has to be done prior to calling it.

param: int|stdClass $course
param: stdClass $section record from course_sections table - it will be updated with the new values
param: array|stdClass $data

course_can_delete_section($course, $section)   X-Ref
Checks if the current user can delete a section (if course format allows it and user has proper permissions).

param: int|stdClass $course
param: int|stdClass|section_info $section
return: bool

reorder_sections($sections, $origin_position, $target_position)   X-Ref
Reordering algorithm for course sections. Given an array of section->section indexed by section->id,
an original position number and a target position number, rebuilds the array so that the
move is made without any duplication of section positions.
Note: The target_position is the position AFTER WHICH the moved section will be inserted. If you want to
insert a section before the first one, you must give 0 as the target (section 0 can never be moved).

param: array $sections
param: int $origin_position
param: int $target_position
return: array

moveto_module($mod, $section, $beforemod=NULL)   X-Ref
Move the module object $mod to the specified $section
If $beforemod exists then that is the module
before which $modid should be inserted

param: stdClass|cm_info $mod
param: stdClass|section_info $section
param: int|stdClass $beforemod id or object with field id corresponding to the module
return: int new value for module visibility (0 or 1)

course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null)   X-Ref
Returns the list of all editing actions that current user can perform on the module

param: cm_info $mod The module to produce editing buttons for
param: int $indent The current indenting (default -1 means no move left-right actions)
param: int $sr The section to link back to (used for creating the links)
return: array array of action_link or pix_icon objects

course_get_cm_move(cm_info $mod, $sr = null)   X-Ref
Returns the move action.

param: cm_info $mod The module to produce a move button for
param: int $sr The section to link back to (used for creating the links)
return: The markup for the move action, or an empty string if not available.

course_format_name($course,$max=100)   X-Ref
given a course object with shortname & fullname, this function will
truncate the the number of chars allowed and add ... if it was too long


course_allowed_module($course, $modname, \stdClass $user = null)   X-Ref
Is the user allowed to add this type of module to this course?

param: object $course the course settings. Only $course->id is used.
param: string $modname the module name. E.g. 'forum' or 'quiz'.
param: \stdClass $user the user to check, defaults to the global user if not provided.
return: bool whether the current user is allowed to add this type of module to this course.

move_courses($courseids, $categoryid)   X-Ref
Efficiently moves many courses around while maintaining
sortorder in order.

param: array $courseids is an array of course ids
param: int $categoryid
return: bool success

get_section_name($courseorid, $section)   X-Ref
Returns the display name of the given section that the course prefers

Implementation of this function is provided by course format
param: int|stdClass $courseorid The course to get the section name for (object or just course id)
param: int|stdClass $section Section object from database or just field course_sections.section
return: string Display name that the course format prefers, e.g. "Week 2"

course_format_uses_sections($format)   X-Ref
Tells if current course format uses sections

param: string $format Course format ID e.g. 'weeks' $course->format
return: bool

course_format_ajax_support($format)   X-Ref
Returns the information about the ajax support in the given source format

The returned object's property (boolean)capable indicates that
the course format supports Moodle course ajax features.

param: string $format
return: stdClass

can_delete_course($courseid)   X-Ref
Can the current user delete this course?
Course creators have exception,
1 day after the creation they can sill delete the course.

param: int $courseid
return: boolean

save_local_role_names($courseid, $data)   X-Ref
Save the Your name for 'Some role' strings.

param: integer $courseid the id of this course.
param: array $data the data that came from the course settings form.

course_overviewfiles_options($course)   X-Ref
Returns options to use in course overviewfiles filemanager

param: null|stdClass|core_course_list_element|int $course either object that has 'id' property or just the course id;
return: array|null array of options such as maxfiles, maxbytes, accepted_types, etc.

create_course($data, $editoroptions = NULL)   X-Ref
Create a course and either return a $course object

Please note this functions does not verify any access control,
the calling code is responsible for all validation (usually it is the form definition).

param: array $editoroptions course description editor options
param: object $data  - all the data needed for an entry in the 'course' table
return: object new course instance

update_course($data, $editoroptions = NULL)   X-Ref
Update a course.

Please note this functions does not verify any access control,
the calling code is responsible for all validation (usually it is the form definition).

param: object $data  - all the data needed for an entry in the 'course' table
param: array $editoroptions course description editor options
return: void

average_number_of_participants(bool $onlyactive = false, int $lastloginsince = null)   X-Ref
Calculate the average number of enrolled participants per course.

This is intended for statistics purposes during the site registration. Only visible courses are taken into account.
Front page enrolments are excluded.

param: bool $onlyactive Consider only active enrolments in enabled plugins and obey the enrolment time restrictions.
param: int $lastloginsince If specified, count only users who logged in after this timestamp.
return: float

average_number_of_courses_modules()   X-Ref
Average number of course modules

return: integer