Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
core_course

Topics

 external
 
 
 test
 
 

Namespaces

namespace  core_course\analytics\indicator
 Activities due indicator.
 
namespace  core_course\analytics\target
 Course competencies achievement target.
 
namespace  core_course\customfield
 Course handler for custom fields.
 
namespace  core_course\external
 Class for exporting a course module summary from an stdClass.
 
namespace  core_course\local\factory
 Contains the service_factory, a locator for services for course content items.
 
namespace  core_course\management
 Course and category management helper class.
 
namespace  core_course\output
  
 
namespace  core_course\output\recommendations
 Contains activity_list renderable used for the recommended activities page.
 
namespace  core_course\privacy
 Privacy class for requesting user data.
 
namespace  core_course\reportbuilder\datasource
  
 
namespace  core_course\reportbuilder\local\entities
  
 
namespace  core_course\reportbuilder\local\formatters
  
 
namespace  core_course\search
 Search area for Moodle courses.
 
namespace  core_course\task
  
 
namespace  core_courseformat
 Contains the base definition class for any course format plugin.
 
namespace  core_courseformat\external
  
 
namespace  core_courseformat\output\local\state
  
 

Classes

class  core_course\analytics\indicator\completion_enabled
 Completion enabled set indicator. More...
 
class  core_course\analytics\indicator\no_student
 No student indicator. More...
 
class  core_course\analytics\indicator\no_teacher
 No teacher indicator. More...
 
class  core_course\analytics\indicator\potential_cognitive_depth
 Potential cognitive depth indicator. More...
 
class  core_course\analytics\indicator\potential_social_breadth
 Potential social breadth indicator. More...
 
class  core_course\analytics\target\course_competencies
 Course competencies achievement target. More...
 
class  core_course\analytics\target\course_completion
 Course completion target. More...
 
class  core_course\analytics\target\course_dropout
 Drop out course target. More...
 
class  core_course\analytics\target\course_enrolments
 Base class for targets whose analysable is a course using user enrolments as samples. More...
 
class  core_course\analytics\target\course_gradetopass
 Getting the minimum grade to pass target. More...
 
class  core_course\analytics\target\no_access_since_course_start
 No accesses since the start of the course. More...
 
class  core_course\analytics\target\no_recent_accesses
 No recent accesses. More...
 
class  core_course\analytics\target\no_teaching
 No teaching target. More...
 
class  core_course\customfield\course_handler
 Course handler for custom fields. More...
 
class  core_course\external\course_module_summary_exporter
 Class for exporting a course module summary from a cm_info class. More...
 
class  core_course\external\course_summary_exporter
 Class for exporting a course summary from an stdClass. More...
 
class  core_course\external\get_enrolled_courses_with_action_events_by_timeline_classification
 Class for fetching courses which have action event(s) and match given filter parameters. More...
 
class  core_course\external\helper_for_get_mods_by_courses
 This class helps implement the get_..._by_courses web service that every activity should have. More...
 
class  core_course\local\factory\content_item_service_factory
 Class service_factory, providing functions for location of service objects for course content items. More...
 
class  core_course\management\helper
 Course and category management interface helper class. More...
 
class  core_course\output\activity_completion
 The activity completion renderable class. More...
 
class  core_course\output\activity_dates
 The activity dates renderable class. More...
 
class  core_course\output\activity_information
 The activity information renderable class. More...
 
class  core_course\output\activity_navigation
 The class activity navigation renderable. More...
 
class  core_course\output\completion_action_bar
 Renderable class for the action bar elements in the course completion pages. More...
 
class  core_course\output\content_export_link
 Prepares content for buttons/links to course content export/download. More...
 
class  core_course\output\course_module_name
 Class to prepare a course module name for display and in-place editing. More...
 
class  core_course\output\recommendations\activity_list
 Activity list renderable. More...
 
class  core_course\output\recommendations\renderer
 Main renderer for the recommendations page. More...
 
class  core_course\privacy\provider
 Privacy class for requesting user data. More...
 
class  core_course\reportbuilder\datasource\categories
 Course categories datasource. More...
 
class  core_course\reportbuilder\datasource\courses
 Courses datasource. More...
 
class  core_course\reportbuilder\datasource\participants
 Course participants datasource. More...
 
class  core_course\reportbuilder\local\entities\access
 Course access entity implementation. More...
 
class  core_course\reportbuilder\local\entities\completion
 Course completion entity implementation. More...
 
class  core_course\reportbuilder\local\entities\course_category
 Course category entity. More...
 
class  core_course\reportbuilder\local\formatters\completion
 Formatters for the course completion entity. More...
 
class  core_course\reportbuilder\local\formatters\enrolment
 Formatters for the course enrolment entity. More...
 
class  core_course\search\course
 Search area for Moodle courses. More...
 
class  core_course\search\customfield
 Search area for course custom fields. More...
 
class  core_course\search\section
 Search area for course sections (title and summary). More...
 
class  core_course\task\content_notification_task
 Class handling course content updates notifications. More...
 
class  core_course\task\course_delete_modules
 Class handling course module deletion. More...
 
class  core_course_bulk_activity_completion_renderer
 Main renderer for the bulk activity completion stuff. More...
 
class  core_course_deletecategory_form
 Delete category moodleform. More...
 
class  core_course_editcategory_form
 Edit category form. More...
 
class  core_course_management_renderer
 Main renderer for the course management pages. More...
 
class  core_courseformat\external\get_state
 Class for exporting a course state. More...
 
class  core_courseformat\external\update_course
 External secrvie to update the course from the course editor components. More...
 
class  core_courseformat\output\local\state\course
 Contains the ajax update course structure. More...
 
class  core_courseformat\output\local\state\section
 Contains the ajax update section structure. More...
 
class  core_courseformat\stateupdates
 Class to track state actions. More...
 
class  course_request
 This class pertains to course requests and contains methods associated with create, approving, and removing course requests. More...
 
class  coursetags_form
 Edit course tags form. More...
 
class  format_legacy
 Course format class to allow plugins developed for Moodle 2.3 to work in the new API. More...
 
class  format_site
 Pseudo course format used for the site main page. More...
 
class  moodleform_mod
 This class adds extra methods to form wrapper specific to be used for module add / update forms mod/{modname}/mod_form.php replaced deprecated mod/{modname}/mod.html Moodleform. More...
 
class  switchrole_form
 Defines the course completion settings form. More...
 

Functions

 add_course_module ($mod)
 MODULE FUNCTIONS /////////////////////////////////////////////////////////////////.
 
 add_moduleinfo ($moduleinfo, $course, $mform=null)
 Add course module.
 
 average_number_of_courses_modules ()
 Average number of course modules.
 
 average_number_of_participants (bool $onlyactive=false, int $lastloginsince=null)
 Calculate the average number of enrolled participants per course.
 
 build_mnet_logs_array ($hostid, $course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='', $modname="", $modid=0, $modaction="", $groupid=0)
 
 can_add_moduleinfo ($course, $modulename, $section)
 Check that the user can add a module.
 
 can_delete_course ($courseid)
 Can the current user delete this course? Course creators have exception, 1 day after the creation they can sill delete the course.
 
 can_download_from_backup_filearea ($filearea, context $context, stdClass $user=null)
 Return whether the user can download from the specified backup file area in the given context.
 
 can_edit_in_category ($categoryid=0)
 Does the user have permission to edit things in this category?
 
 can_update_moduleinfo ($cm)
 Check if user is allowed to update module info and returns related item/data to the module.
 
 clean_param_if_not_null ($param, string $type=PARAM_RAW)
 Cleans the given param, unless it is null.
 
 compare_activities_by_time_asc ($a, $b)
 Compare two objects to find out their correct order based on timestamp (to be used by usort).
 
 compare_activities_by_time_desc ($a, $b)
 Compare two objects to find out their correct order based on timestamp (to be used by usort).
 
 contract_value (array &$dest, array $source, array $option, string $optionname)
 'Converts' a value from what is stored in the database into what is used by edit forms.
 
 core_course_core_calendar_get_valid_event_timestart_range (\calendar_event $event, $course)
 This function calculates the minimum and maximum cutoff values for the timestart of the given event.
 
 core_course_drawer ()
 Render the message drawer to be included in the top of the body of each page.
 
 core_course_inplace_editable ($itemtype, $itemid, $newvalue)
 Implements callback inplace_editable() allowing to edit values in-place.
 
 core_courseformat_output_fragment_cmitem ($args)
 Course-module fragment renderer method.
 
 core_courseformat_output_fragment_section ($args)
 Section fragment renderer method.
 
 course_add_cm_to_section ($courseorid, $cmid, $sectionnum, $beforemod=null)
 Adds an existing module to the section.
 
 course_ajax_enabled ($course)
 Determine whether course ajax should be enabled for the specified course.
 
 course_allowed_module ($course, $modname, stdClass $user=null)
 Is the user allowed to add this type of module to this course?
 
 course_can_delete_section ($course, $section)
 Checks if the current user can delete a section (if course format allows it and user has proper permissions).
 
 course_can_view_participants ($context)
 Returns true if the user can view the participant page, false otherwise,.
 
 course_change_sortorder_after_course ($courseorid, $moveaftercourseid)
 Changes the sort order of courses in a category so that the first course appears after the second.
 
 course_change_sortorder_by_one ($course, $up)
 Changes the course sortorder by one, moving it up or down one in respect to sort order.
 
 course_change_visibility ($courseid, $show=true)
 Changes the visibility of a course.
 
 course_check_module_updates_since ($cm, $from, $fileareas=array(), $filter=array())
 Check module updates since a given time.
 
 course_check_updates ($course, $tocheck, $filter=array())
 Check for course updates in the given context level instances (only modules supported right Now)
 
 course_classify_courses_for_timeline (array $courses)
 Group a list of courses into either past, future, or in progress.
 
 course_classify_end_date ($course)
 This function calculates the end date to use for display classification purposes, incorporating the grace period, if any.
 
 course_classify_for_timeline ($course, $user=null, $completioninfo=null)
 This function classifies a course as past, in progress or future.
 
 course_classify_start_date ($course)
 This function calculates the start date to use for display classification purposes, incorporating the grace period, if any.
 
 course_create_section ($courseorid, $position=0, $skipcheck=false)
 Creates a course section and adds it to the specified position.
 
 course_create_sections_if_missing ($courseorid, $sections)
 Creates missing course section(s) and rebuilds course cache.
 
 course_delete_module ($cmid, $async=false)
 This function will handle the whole deletion process of a module.
 
 course_delete_section ($course, $section, $forcedeleteifnotempty=true, $async=false)
 This method will delete a course section and may delete all modules inside it.
 
 course_delete_section_async ($section, $forcedeleteifnotempty=true)
 Course section deletion, using an adhoc task for deletion of the modules it contains.
 
 course_filter_courses_by_customfield ( $courses, $customfieldname, $customfieldvalue, int $limit=0)
 Search the given $courses for any that have a $customfieldname value that matches the given $customfieldvalue, up to the specified $limit.
 
 course_filter_courses_by_favourites ( $courses, $favouritecourseids, int $limit=0)
 Search the given $courses for any that match the given $classification up to the specified $limit.
 
 course_filter_courses_by_timeline_classification ( $courses, string $classification, int $limit=0)
 Search the given $courses for any that match the given $classification up to the specified $limit.
 
 course_format_ajax_support ($format)
 Returns the information about the ajax support in the given source format.
 
 course_format_name ($course, $max=100)
 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_format_uses_sections ($format)
 Tells if current course format uses sections.
 
 course_get_cm_edit_actions (cm_info $mod, $indent=-1, $sr=null)
 Returns the list of all editing actions that current user can perform on the module.
 
 course_get_cm_move (cm_info $mod, $sr=null)
 Returns the move action.
 
 course_get_communication_instance_data (int $courseid)
 Get course specific data for configuring a communication instance.
 
 course_get_course_dates_for_user_id (stdClass $course, int $userid)
 Calculate the course start date and offset for the given user id.
 
 course_get_course_dates_for_user_ids (stdClass $course, array $userids)
 Calculate the course start date and offset for the given user ids.
 
 course_get_courseimage (\stdClass $course)
 Get the current course image for the given course.
 
 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=[])
 Get the list of enrolled courses for the current user.
 
 course_get_enrolled_courses_for_logged_in_user_from_search (int $limit=0, int $offset=0, string $sort=null, string $fields=null, int $dbquerylimit=COURSE_DB_QUERY_LIMIT, array $searchcriteria=[], array $options=[])
 Get the list of enrolled courses the current user searched for.
 
 course_get_format ($courseorid)
 Returns an instance of format class (extending course_format) for given course.
 
 course_get_recent_courses (int $userid=null, int $limit=0, int $offset=0, string $sort=null)
 Returns a list of the most recently courses accessed by a user.
 
 course_get_tagged_course_modules ($tag, $exclusivemode=false, $fromcontextid=0, $contextid=0, $recursivecontext=1, $page=0)
 Returns course modules tagged with a specified tag ready for output on tag/index.php page.
 
 course_get_tagged_courses ($tag, $exclusivemode=false, $fromctx=0, $ctx=0, $rec=1, $page=0)
 Returns courses tagged with a specified tag.
 
 course_get_url ($courseorid, $section=null, $options=array())
 The URL to use for the specified course (with section)
 
 course_get_user_administration_options ($course, $context)
 Return an object with the list of administration options in a course that are available or not for the current user.
 
 course_get_user_navigation_options ($context, $course=null)
 Return an object with the list of navigation options in a course that are avaialable or not for the current user.
 
 course_integrity_check ($courseid, $rawmods=null, $sections=null, $fullcheck=false, $checkonly=false)
 Checks the integrity of the course data.
 
 course_module_bulk_update_calendar_events ($modulename, $courseid=0)
 Update all instances through out the site or in a course.
 
 course_module_calendar_event_update_process ($instance, $cm)
 Calendar events for a module instance are updated.
 
 course_module_flag_for_async_deletion ($cmid)
 Schedule a course module for deletion in the background using an adhoc task.
 
 course_module_instance_pending_deletion ($courseid, $modulename, $instanceid)
 Checks whether the course module, as defined by modulename and instanceid, is scheduled for deletion within the given course.
 
 course_module_update_calendar_events ($modulename, $instance=null, $cm=null)
 This function updates the calendar events from the information stored in the module table and the course module table.
 
 course_modules_pending_deletion (int $courseid, bool $onlygradable=false)
 Checks whether the given course has any course modules scheduled for adhoc deletion.
 
 course_output_fragment_new_base_form ($args)
 Renders the course copy form for the modal on the course management screen.
 
 course_overviewfiles_options ($course)
 Returns options to use in course overviewfiles filemanager.
 
 course_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types.
 
 course_require_view_participants ($context)
 Checks if a user can view the participant page, if not throws an exception.
 
 course_set_marker ($courseid, $marker)
 Set highlighted section.
 
 course_update_communication_instance_data (stdClass $data)
 Update a course using communication configuration data.
 
 course_update_section ($course, $section, $data)
 Updates the course section.
 
 course_validate_dates ($coursedata)
 Validates course start and end dates.
 
 course_view ($context, $sectionnumber=0)
 Trigger course viewed event.
 
 create_course ($data, $editoroptions=NULL)
 Create a course and either return a $course object.
 
 create_module ($moduleinfo)
 Create a module.
 
 delete_mod_from_section ($modid, $sectionid)
 
 duplicate_module ($course, $cm, int $sectionid=null, bool $changename=true)
 Api to duplicate a module.
 
 edit_module_post_actions ($moduleinfo, $course)
 Common create/update module module actions that need to be processed as soon as a module is created/updaded.
 
 expand_value (array &$dest, array $source, array $option, string $optionname)
 'Converts' a value from what is used in edit forms into a value(s) to be stored in the database.
 
 get_category_or_system_context ($categoryid)
 Return the course category context for the category with id $categoryid, except that if $categoryid is 0, return the system context.
 
 get_hidden_courses_on_timeline ($user=null)
 Get a list of hidden courses.
 
 get_module_types_names ($plural=false, $resetcache=false)
 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.
 
 get_moduleinfo_data ($cm, $course)
 Get module information data required for updating the module.
 
 get_section_name ($courseorid, $section)
 Returns the display name of the given section that the course prefers.
 
 get_sorted_course_formats ($enabledonly=false)
 Returns the sorted list of available course formats, filtered by enabled if necessary.
 
 include_course_ajax ($course, $usedmodules=array(), $enabledmodules=null, $config=null)
 Include the relevant javascript and language strings for the resource toolbox YUI module.
 
 include_course_editor (course_format $format)
 Include and configure the course editor modules.
 
 include_modulelib ($modulename)
 Include once the module lib file.
 
 make_log_url ($module, $url)
 
 mod_duplicate_activity ($course, $cm, $sr=null)
 Duplicate a module on the course for ajax.
 
 move_courses ($courseids, $categoryid)
 Efficiently moves many courses around while maintaining sortorder in order.
 
 move_section_to ($course, $section, $destination, $ignorenumsections=false)
 Moves a section within a course, from a position to another.
 
 moveto_module ($mod, $section, $beforemod=NULL)
 Move the module object $mod to the specified $section If $beforemod exists then that is the module before which $modid should be inserted.
 
 plugin_extend_coursemodule_edit_post_actions ($moduleinfo, $course)
 Hook for plugins to take action when a module is created or updated.
 
 prepare_new_moduleinfo_data ($course, $modulename, $section, string $suffix='')
 Prepare the standard module information for a new module instance.
 
 print_course_request_buttons ($context)
 Print the buttons relating to course requests.
 
 reorder_sections ($sections, $origin_position, $target_position)
 Reordering algorithm for course sections.
 
 save_local_role_names ($courseid, $data)
 Save the Your name for 'Some role' strings.
 
 set_coursemodule_groupmode ($id, $groupmode)
 Change the group mode of a course module.
 
 set_coursemodule_idnumber ($id, $idnumber)
 
 set_coursemodule_name ($id, $name)
 Changes the course module name.
 
 set_coursemodule_visible ($id, $visible, $visibleoncoursepage=1, bool $rebuildcache=true)
 Set the visibility of a module and inherent properties.
 
 set_downloadcontent (int $id, bool $downloadcontent)
 Set downloadcontent value to course module.
 
 set_moduleinfo_defaults ($moduleinfo)
 Set module info default values for the unset module attributs.
 
 set_section_visible ($courseid, $sectionnumber, $visibility)
 For a given course section, marks it visible or hidden, and does the same for every activity in that section.
 
 update_course ($data, $editoroptions=NULL)
 Update a course.
 
 update_module ($moduleinfo)
 Update a module.
 
 update_moduleinfo ($cm, $moduleinfo, $course, $mform=null)
 Update the module info.
 

Variables

const COURSE_CHOOSER_FOOTER_NONE 'hidden'
 
const COURSE_CUSTOMFIELD 'customfield'
 
const COURSE_CUSTOMFIELD_EMPTY -1
 Searching for all courses that have no value for the specified custom field.
 
const COURSE_DB_QUERY_LIMIT 1000
 
const COURSE_FAVOURITES 'favourites'
 
const COURSE_MAX_COURSES_PER_DROPDOWN 1000
 
const COURSE_MAX_LOGS_PER_PAGE 1000
 
const COURSE_MAX_RECENT_PERIOD 172800
 
const COURSE_MAX_SUMMARIES_PER_PAGE 10
 Number of courses to display when summaries are included.
 
const COURSE_MAX_USERS_PER_DROPDOWN 1000
 
const COURSE_TIMELINE_ALL 'all'
 
const COURSE_TIMELINE_ALLINCLUDINGHIDDEN 'allincludinghidden'
 
const COURSE_TIMELINE_FUTURE 'future'
 
const COURSE_TIMELINE_HIDDEN 'hidden'
 
const COURSE_TIMELINE_INPROGRESS 'inprogress'
 
const COURSE_TIMELINE_PAST 'past'
 
const COURSE_TIMELINE_SEARCH 'search'
 
const DOWNLOAD_COURSE_CONTENT_DISABLED 0
 
const DOWNLOAD_COURSE_CONTENT_ENABLED 1
 
const DOWNLOAD_COURSE_CONTENT_SITE_DEFAULT 2
 
const EXCELROWS 65535
 
const FIRSTUSEDEXCELROW 3
 
const FRONTPAGEALLCOURSELIST '6'
 
const FRONTPAGECATEGORYCOMBO '4'
 
const FRONTPAGECATEGORYNAMES '2'
 
const FRONTPAGECOURSESEARCH '7'
 
const FRONTPAGEENROLLEDCOURSELIST '5'
 
const FRONTPAGENEWS '0'
 
const MOD_CLASS_ACTIVITY 0
 
const MOD_CLASS_RESOURCE 1
 

Detailed Description

Function Documentation

◆ add_moduleinfo()

add_moduleinfo ( $moduleinfo,
$course,
$mform = null )

Add course module.

The function does not check user capabilities. The function creates course module, module instance, add the module to the correct section. It also trigger common action that need to be done after adding/updating a module.

Parameters
object$moduleinfothe moudle data
object$coursethe course of the module
object$mformthis is required by an existing hack to deal with files during MODULENAME_add_instance()
Return values
objectthe updated module info

◆ average_number_of_courses_modules()

average_number_of_courses_modules ( )

Average number of course modules.

Return values
integer

◆ average_number_of_participants()

average_number_of_participants ( bool $onlyactive = false,
int $lastloginsince = null )

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.

Parameters
bool$onlyactiveConsider only active enrolments in enabled plugins and obey the enrolment time restrictions.
int$lastloginsinceIf specified, count only users who logged in after this timestamp.
Return values
float

◆ can_add_moduleinfo()

can_add_moduleinfo ( $course,
$modulename,
$section )

Check that the user can add a module.

Also returns some information like the module, context and course section info. The fucntion create the course section if it doesn't exist.

Parameters
object$coursethe course of the module
object$modulenamethe module name
object$sectionthe section of the module
Return values
arraylist containing module, context, course section.
Exceptions
moodle_exceptionif user is not allowed to perform the action or module is not allowed in this course

◆ can_delete_course()

can_delete_course ( $courseid)

Can the current user delete this course? Course creators have exception, 1 day after the creation they can sill delete the course.

Parameters
int$courseid
Return values
boolean

◆ can_download_from_backup_filearea()

can_download_from_backup_filearea ( $filearea,
context $context,
stdClass $user = null )

Return whether the user can download from the specified backup file area in the given context.

Parameters
string$fileareathe backup file area. E.g. 'course', 'backup' or 'automated'.
context$context
stdClass$userthe user object. If not provided, the current user will be checked.
Return values
booltrue if the user is allowed to download in the context, false otherwise.

◆ can_edit_in_category()

can_edit_in_category ( $categoryid = 0)

Does the user have permission to edit things in this category?

Parameters
integer$categoryidThe id of the category we are showing, or 0 for system context.
Return values
booleanhas_any_capability(array(...), ...); in the appropriate context.

◆ can_update_moduleinfo()

can_update_moduleinfo ( $cm)

Check if user is allowed to update module info and returns related item/data to the module.

Parameters
object$cmcourse module
Return values
array- list of course module, context, module, moduleinfo, and course section.
Exceptions
moodle_exceptionif user is not allowed to perform the action

◆ clean_param_if_not_null()

clean_param_if_not_null ( $param,
string $type = PARAM_RAW )

Cleans the given param, unless it is null.

Parameters
mixed$paramThe variable we are cleaning.
string$typeExpected format of param after cleaning.
Return values
mixedNull if $param is null, otherwise the cleaned value.
Exceptions
coding_exception

◆ compare_activities_by_time_asc()

compare_activities_by_time_asc ( $a,
$b )

Compare two objects to find out their correct order based on timestamp (to be used by usort).

Sorts by ascending order of time.

Parameters
stdClass$aFirst object
stdClass$bSecond object
Return values
int0,1,-1 representing the order

◆ compare_activities_by_time_desc()

compare_activities_by_time_desc ( $a,
$b )

Compare two objects to find out their correct order based on timestamp (to be used by usort).

Sorts by descending order of time.

Parameters
stdClass$aFirst object
stdClass$bSecond object
Return values
int0,1,-1 representing the order

◆ contract_value()

contract_value ( array & $dest,
array $source,
array $option,
string $optionname )

'Converts' a value from what is stored in the database into what is used by edit forms.

Parameters
array$destThe destination array
array$sourceThe source array
array$optionThe definition structure of the option.
string$optionnameThe name of the option, as provided in the definition.

◆ core_course_core_calendar_get_valid_event_timestart_range()

core_course_core_calendar_get_valid_event_timestart_range ( \calendar_event $event,
$course )

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

Parameters
calendar_event$eventThe calendar event to get the time range for
stdClass$courseThe course object to get the range from
Return values
arrayReturns an array with min and max date.

◆ core_course_drawer()

core_course_drawer ( )

Render the message drawer to be included in the top of the body of each page.

Return values
stringHTML

◆ core_course_inplace_editable()

core_course_inplace_editable ( $itemtype,
$itemid,
$newvalue )

Implements callback inplace_editable() allowing to edit values in-place.

Parameters
string$itemtype
int$itemid
mixed$newvalue
Return values
core\output\inplace_editable

◆ core_courseformat_output_fragment_cmitem()

core_courseformat_output_fragment_cmitem ( $args)

Course-module fragment renderer method.

The fragment arguments are id and sr (section return).

Parameters
array$argsThe fragment arguments.
Return values
stringThe rendered cm item.
Exceptions
require_login_exception

◆ core_courseformat_output_fragment_section()

core_courseformat_output_fragment_section ( $args)

Section fragment renderer method.

The fragment arguments are courseid, section id and sr (section return).

Parameters
array$argsThe fragment arguments.
Return values
stringThe rendered section.
Exceptions
require_login_exception

◆ course_add_cm_to_section()

course_add_cm_to_section ( $courseorid,
$cmid,
$sectionnum,
$beforemod = null )

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.

Parameters
int | stdClass$courseoridcourse id or course object
int$cmidid of the module already existing in course_modules table
int$sectionnumrelative number of the section (field course_sections.section) If section does not exist it will be created
int | stdClass$beforemodid or object with field id corresponding to the module before which the module needs to be included. Null for inserting in the end of the section
Return values
intThe course_sections ID where the module is inserted

◆ course_ajax_enabled()

course_ajax_enabled ( $course)

Determine whether course ajax should be enabled for the specified course.

Parameters
stdClass$courseThe course to test against
Return values
booleanWhether course ajax is enabled or note

◆ course_allowed_module()

course_allowed_module ( $course,
$modname,
stdClass $user = null )

Is the user allowed to add this type of module to this course?

Parameters
object$coursethe course settings. Only $course->id is used.
string$modnamethe module name. E.g. 'forum' or 'quiz'.
stdClass$userthe user to check, defaults to the global user if not provided.
Return values
boolwhether the current user is allowed to add this type of module to this course.

◆ course_can_delete_section()

course_can_delete_section ( $course,
$section )

Checks if the current user can delete a section (if course format allows it and user has proper permissions).

Parameters
int | stdClass$course
int | stdClass | section_info$section
Return values
bool

◆ course_can_view_participants()

course_can_view_participants ( $context)

Returns true if the user can view the participant page, false otherwise,.

Parameters
context$contextThe context we are checking.
Return values
bool

◆ course_change_sortorder_after_course()

course_change_sortorder_after_course ( $courseorid,
$moveaftercourseid )

Changes the sort order of courses in a category so that the first course appears after the second.

Parameters
int | stdClass$courseoridThe course to focus on.
int$moveaftercourseidThe course to shifter after or 0 if you want it to be the first course in the category.
Return values
bool

◆ course_change_sortorder_by_one()

course_change_sortorder_by_one ( $course,
$up )

Changes the course sortorder by one, moving it up or down one in respect to sort order.

Parameters
stdClass | core_course_list_element$course
bool$upIf set to true the course will be moved up one. Otherwise down one.
Return values
bool

◆ course_change_visibility()

course_change_visibility ( $courseid,
$show = true )

Changes the visibility of a course.

Parameters
int$courseidThe course to change.
bool$showTrue to make it visible, false otherwise.
Return values
bool

◆ course_check_module_updates_since()

course_check_module_updates_since ( $cm,
$from,
$fileareas = array(),
$filter = array() )

Check module updates since a given time.

This function checks for updates in the module config, file areas, completion, grades, comments and ratings.

Parameters
cm_info$cmcourse module data
int$fromthe time to check
array$fileareasadditional file ares to check
array$filterif we need to filter and return only selected updates
Return values
stdClassobject with the different updates
Since
Moodle 3.2

◆ course_check_updates()

course_check_updates ( $course,
$tocheck,
$filter = array() )

Check for course updates in the given context level instances (only modules supported right Now)

Parameters
stdClass$coursecourse object
array$tocheckinstances to check for updates
array$filtercheck only for updates in these areas
Return values
arraylist of warnings and instances with updates information
Since
Moodle 3.2

◆ course_classify_courses_for_timeline()

course_classify_courses_for_timeline ( array $courses)

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 => [] ]

Parameters
array$coursesList of courses to be grouped.
Return values
array

◆ course_classify_end_date()

course_classify_end_date ( $course)

This function calculates the end date to use for display classification purposes, incorporating the grace period, if any.

Parameters
stdClass$courseThe course record.
Return values
intThe new enddate.

◆ course_classify_for_timeline()

course_classify_for_timeline ( $course,
$user = null,
$completioninfo = null )

This function classifies a course as past, in progress or future.

This function may incur a DB hit to calculate course completion.

Parameters
stdClass$courseCourse record
stdClass$userUser record (optional - defaults to $USER).
completion_info$completioninfoCompletion record for the user (optional - will be fetched if required).
Return values
string(one of COURSE_TIMELINE_FUTURE, COURSE_TIMELINE_INPROGRESS or COURSE_TIMELINE_PAST)

◆ course_classify_start_date()

course_classify_start_date ( $course)

This function calculates the start date to use for display classification purposes, incorporating the grace period, if any.

Parameters
stdClass$courseThe course record.
Return values
intThe new startdate.

◆ course_create_section()

course_create_section ( $courseorid,
$position = 0,
$skipcheck = false )

Creates a course section and adds it to the specified position.

Parameters
int | stdClass$courseoridcourse id or course object
int$positionposition to add to, 0 means to the end. If position is greater than number of existing secitons, the section is added to the end. This will become sectionnum of the new section. All existing sections at this or bigger position will be shifted down.
bool$skipcheckthe check has already been made and we know that the section with this position does not exist
Return values
stdClasscreated section object

◆ course_create_sections_if_missing()

course_create_sections_if_missing ( $courseorid,
$sections )

Creates missing course section(s) and rebuilds course cache.

Parameters
int | stdClass$courseoridcourse id or course object
int | array$sectionslist of relative section numbers to create
Return values
boolif there were any sections created

◆ course_delete_module()

course_delete_module ( $cmid,
$async = false )

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.

Parameters
int$cmidthe course module id
bool$asyncwhether or not to try to delete the module using an adhoc task. Async also depends on a plugin hook.
Exceptions
moodle_exception
Since
Moodle 2.5

◆ course_delete_section()

course_delete_section ( $course,
$section,
$forcedeleteifnotempty = true,
$async = false )

This method will delete a course section and may delete all modules inside it.

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

Parameters
int | stdClass$course
int | stdClass | section_info$section
bool$forcedeleteifnotemptyif set to false section will not be deleted if it has modules in it.
bool$asyncwhether or not to try to delete the section using an adhoc task. Async also depends on a plugin hook.
Return values
boolwhether section was deleted

◆ course_delete_section_async()

course_delete_section_async ( $section,
$forcedeleteifnotempty = true )

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.
Parameters
stdClass$sectionthe section to schedule for deletion.
bool$forcedeleteifnotemptywhether to force section deletion if it contains modules.
Return values
booltrue if the section was scheduled for deletion, false otherwise.

◆ course_filter_courses_by_customfield()

course_filter_courses_by_customfield ( $courses,
$customfieldname,
$customfieldvalue,
int $limit = 0 )

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.

Parameters
array | Traversable$coursesList of courses to process
string$customfieldnamethe shortname of the custom field to match against
string$customfieldvaluethe value this custom field needs to match
int$limitLimit the number of results to this amount
Return values
arrayFirst value is the filtered courses, second value is the number of courses processed

◆ course_filter_courses_by_favourites()

course_filter_courses_by_favourites ( $courses,
$favouritecourseids,
int $limit = 0 )

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.

Parameters
array | Traversable$coursesList of courses to process
array$favouritecourseidsArray of favourite courses.
int$limitLimit the number of results to this amount
Return values
arrayFirst value is the filtered courses, second value is the number of courses processed

◆ course_filter_courses_by_timeline_classification()

course_filter_courses_by_timeline_classification ( $courses,
string $classification,
int $limit = 0 )

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.

Parameters
array | Traversable$coursesList of courses to process
string$classificationOne of the COURSE_TIMELINE_* constants
int$limitLimit the number of results to this amount
Return values
arrayFirst value is the filtered courses, second value is the number of courses processed

◆ course_format_ajax_support()

course_format_ajax_support ( $format)

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.

Parameters
string$format
Return values
stdClass

◆ course_format_uses_sections()

course_format_uses_sections ( $format)

Tells if current course format uses sections.

Parameters
string$formatCourse format ID e.g. 'weeks' $course->format
Return values
bool

◆ course_get_cm_edit_actions()

course_get_cm_edit_actions ( cm_info $mod,
$indent = -1,
$sr = null )

Returns the list of all editing actions that current user can perform on the module.

Parameters
cm_info$modThe module to produce editing buttons for
int$indentThe current indenting (default -1 means no move left-right actions)
int$srThe section to link back to (used for creating the links)
Return values
arrayarray of action_link or pix_icon objects

◆ course_get_cm_move()

course_get_cm_move ( cm_info $mod,
$sr = null )

Returns the move action.

Parameters
cm_info$modThe module to produce a move button for
int$srThe section to link back to (used for creating the links)
Return values
Themarkup for the move action, or an empty string if not available.

◆ course_get_communication_instance_data()

course_get_communication_instance_data ( int $courseid)

Get course specific data for configuring a communication instance.

Parameters
integer$courseidThe course id.
Return values
arrayReturns course data, context and heading.

◆ course_get_course_dates_for_user_id()

course_get_course_dates_for_user_id ( stdClass $course,
int $userid )

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 ]

Parameters
stdClass$courseThe course to fetch dates for.
int$useridThe user id to get dates for.
Return values
array

◆ course_get_course_dates_for_user_ids()

course_get_course_dates_for_user_ids ( stdClass $course,
array $userids )

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

Parameters
stdClass$courseThe course to fetch dates for.
array$useridsThe list of user ids to get dates for.
Return values
array

◆ course_get_courseimage()

course_get_courseimage ( \stdClass $course)

Get the current course image for the given course.

Parameters
stdClass$course
Return values
null|stored_file

◆ course_get_enrolled_courses_for_logged_in_user()

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 = [] )

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.

Parameters
int$limitRestrict result set to this amount
int$offsetSkip this number of records from the start of the result set
string | null$sortSQL string for sorting
string | null$fieldsSQL string for fields to be returned
int$dbquerylimitThe number of records to load per DB request
array$includecoursescourses ids to be restricted
array$hiddencoursescourses ids to be excluded
Return values
Generator

◆ course_get_enrolled_courses_for_logged_in_user_from_search()

course_get_enrolled_courses_for_logged_in_user_from_search ( int $limit = 0,
int $offset = 0,
string $sort = null,
string $fields = null,
int $dbquerylimit = COURSE_DB_QUERY_LIMIT,
array $searchcriteria = [],
array $options = [] )

Get the list of enrolled courses the current user searched for.

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

Parameters
int$limitRestrict result set to this amount
int$offsetSkip this number of records from the start of the result set
string | null$sortSQL string for sorting
string | null$fieldsSQL string for fields to be returned
int$dbquerylimitThe number of records to load per DB request
array$searchcriteriacontains search criteria
array$optionsdisplay options, same as in get_courses() except 'recursive' is ignored - search is always category-independent
Return values
Generator

◆ course_get_format()

course_get_format ( $courseorid)

Returns an instance of format class (extending course_format) for given course.

Parameters
int | stdClass$courseorideither course id or an object that has the property 'format' and may contain property 'id'
Return values
course_format

◆ course_get_recent_courses()

course_get_recent_courses ( int $userid = null,
int $limit = 0,
int $offset = 0,
string $sort = null )

Returns a list of the most recently courses accessed by a user.

Parameters
int$useridUser id from which the courses will be obtained
int$limitRestrict result set to this amount
int$offsetSkip this number of records from the start of the result set
string | null$sortSQL string for sorting
Return values
array

◆ course_get_tagged_course_modules()

course_get_tagged_course_modules ( $tag,
$exclusivemode = false,
$fromcontextid = 0,
$contextid = 0,
$recursivecontext = 1,
$page = 0 )

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.

Parameters
core_tag_tag$tag
bool$exclusivemodeif set to true it means that no other entities tagged with this tag are displayed on the page and the per-page limit may be bigger
int$fromcontextidcontext id where the link was displayed, may be used by callbacks to display items in the same context first
int$contextidcontext id where to search for records
bool$recursivecontextsearch in subcontexts as well
int$page0-based number of page being displayed
Return values
core_tag\output\tagindex

◆ course_get_tagged_courses()

course_get_tagged_courses ( $tag,
$exclusivemode = false,
$fromctx = 0,
$ctx = 0,
$rec = 1,
$page = 0 )

Returns courses tagged with a specified tag.

Parameters
core_tag_tag$tag
bool$exclusivemodeif set to true it means that no other entities tagged with this tag are displayed on the page and the per-page limit may be bigger
int$fromctxcontext id where the link was displayed, may be used by callbacks to display items in the same context first
int$ctxcontext id where to search for records
bool$recsearch in subcontexts as well
int$page0-based number of page being displayed
Return values
core_tag\output\tagindex

◆ course_get_url()

course_get_url ( $courseorid,
$section = null,
$options = array() )

The URL to use for the specified course (with section)

Parameters
int | stdClass$courseoridThe course to get the section name for (either object or just course id)
int | stdClass$sectionSection object from database or just field course_sections.section if omitted the course view page is returned
array$optionsoptions for view URL. At the moment core uses: 'navigation' (bool) if true and section has no separate page, the function returns null 'sr' (int) used by multipage formats to specify to which section to return
Return values
moodle_urlThe url of course

◆ course_get_user_administration_options()

course_get_user_administration_options ( $course,
$context )

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.

Parameters
stdClass$coursecourse object (for frontpage it should be a clone of $SITE)
stdClass$contextcontext object (course context)
Return values
stdClassthe administration options in a course and their availability status
Since
Moodle 3.2

◆ course_get_user_navigation_options()

course_get_user_navigation_options ( $context,
$course = null )

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.

Parameters
stdClass$contextcontext object (it can be a course context or the system context for frontpage settings)
stdClass$coursethe course where the settings are being rendered
Return values
stdClassthe navigation options in a course and their availability status
Since
Moodle 3.2

◆ course_integrity_check()

course_integrity_check ( $courseid,
$rawmods = null,
$sections = null,
$fullcheck = false,
$checkonly = false )

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

Parameters
int$courseidid of the course
array$rawmodsresult of funciton get_course_mods() - containst the list of enabled course modules in the course. Retrieved from DB if not specified. Argument ignored in cashe of $fullcheck, the list is retrieved form DB anyway.
array$sectionsrecords from course_sections table for this course. Retrieved from DB if not specified
bool$fullcheckWill add orphaned modules to their sections and remove non-existing course modules from sequences. Only to be used in site maintenance mode when we are sure that another user is not in the middle of the process of moving/removing a module.
bool$checkonlyOnly performs the check without updating DB, outputs all errors as debug messages.
Return values
arrayarray of messages with found problems. Empty output means everything is ok

◆ course_module_bulk_update_calendar_events()

course_module_bulk_update_calendar_events ( $modulename,
$courseid = 0 )

Update all instances through out the site or in a course.

Parameters
string$modulenameModule type to update.
integer$courseidCourse id to update events. 0 for the whole site.
Return values
boolReturns True if the update was successful.
Since
Moodle 3.3.4

◆ course_module_calendar_event_update_process()

course_module_calendar_event_update_process ( $instance,
$cm )

Calendar events for a module instance are updated.

Parameters
stdClass$instanceModule instance object.
stdClass$cmCourse Module object.
Since
Moodle 3.3.4

◆ course_module_flag_for_async_deletion()

course_module_flag_for_async_deletion ( $cmid)

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

Parameters
int$cmidthe course module id.
Return values
boolwhether the module was successfully scheduled for deletion.
Exceptions
moodle_exception

◆ course_module_instance_pending_deletion()

course_module_instance_pending_deletion ( $courseid,
$modulename,
$instanceid )

Checks whether the course module, as defined by modulename and instanceid, is scheduled for deletion within the given course.

Parameters
int$courseidthe course id.
string$modulenamethe module name. E.g. 'assign', 'book', etc.
int$instanceidthe module instance id.
Return values
booltrue if the course module is pending deletion, false otherwise.

◆ course_module_update_calendar_events()

course_module_update_calendar_events ( $modulename,
$instance = null,
$cm = null )

This function updates the calendar events from the information stored in the module table and the course module table.

Parameters
string$modulenameModule name
stdClass$instanceModule object. Either the $instance or the $cm must be supplied.
stdClass$cmCourse module object. Either the $instance or the $cm must be supplied.
Return values
boolReturns true if calendar events are updated.
Since
Moodle 3.3.4

◆ course_modules_pending_deletion()

course_modules_pending_deletion ( int $courseid,
bool $onlygradable = false )

Checks whether the given course has any course modules scheduled for adhoc deletion.

Parameters
int$courseidthe id of the course.
bool$onlygradablewhether to check only gradable modules or all modules.
Return values
booltrue if the course contains any modules pending deletion, false otherwise.

◆ course_output_fragment_new_base_form()

course_output_fragment_new_base_form ( $args)

Renders the course copy form for the modal on the course management screen.

Parameters
array$args
Return values
string\$oForm HTML.

◆ course_overviewfiles_options()

course_overviewfiles_options ( $course)

Returns options to use in course overviewfiles filemanager.

Parameters
null | stdClass | core_course_list_element | int$courseeither object that has 'id' property or just the course id; may be empty if course does not exist yet (course create form)
Return values
array|nullarray of options such as maxfiles, maxbytes, accepted_types, etc. or null if overviewfiles are disabled

◆ course_page_type_list()

course_page_type_list ( $pagetype,
$parentcontext,
$currentcontext )

Return a list of page types.

Parameters
string$pagetypecurrent page type
context$parentcontextBlock's parent context
context$currentcontextCurrent context of block
Return values
arrayarray of page types

◆ course_require_view_participants()

course_require_view_participants ( $context)

Checks if a user can view the participant page, if not throws an exception.

Parameters
context$contextThe context we are checking.
Exceptions
required_capability_exception

◆ course_set_marker()

course_set_marker ( $courseid,
$marker )

Set highlighted section.

Only one section can be highlighted at the time.

Parameters
int$courseidcourse id
int$markerhighlight section with this number, 0 means remove higlightin
Return values
void

◆ course_update_communication_instance_data()

course_update_communication_instance_data ( stdClass $data)

Update a course using communication configuration data.

Parameters
stdClass$dataThe data to update the course with.

◆ course_update_section()

course_update_section ( $course,
$section,
$data )

Updates the course section.

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

Parameters
int | stdClass$course
stdClass$sectionrecord from course_sections table - it will be updated with the new values
array | stdClass$data

◆ course_validate_dates()

course_validate_dates ( $coursedata)

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.

Parameters
array$coursedataMay contain startdate and enddate timestamps, depends on the user input.
Return values
mixedFalse if everything alright, error codes otherwise.

◆ course_view()

course_view ( $context,
$sectionnumber = 0 )

Trigger course viewed event.

This API function is used when course view actions happens, usually in course/view.php but also in external functions.

Parameters
stdClass$contextcourse context object
int$sectionnumbersection number
Since
Moodle 2.9

◆ create_course()

create_course ( $data,
$editoroptions = NULL )

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

Parameters
array$editoroptionscourse description editor options
object$data- all the data needed for an entry in the 'course' table
Return values
objectnew course instance

◆ create_module()

create_module ( $moduleinfo)

Create a module.

It includes:

  • capability checks and other checks
  • create the module from the module info
Parameters
object$module
Return values
objectthe created module info
Exceptions
moodle_exceptionif user is not allowed to perform the action or module is not allowed in this course

◆ duplicate_module()

duplicate_module ( $course,
$cm,
int $sectionid = null,
bool $changename = true )

Api to duplicate a module.

Parameters
object$coursecourse object.
object$cmcourse module object to be duplicated.
int$sectionidsection ID new course module will be placed in.
bool$changenameupdates module name with text from duplicatedmodule lang string.
Since
Moodle 2.8
Exceptions
Exception
coding_exception
moodle_exception
restore_controller_exception
Return values
cm_info|nullcminfo object if we sucessfully duplicated the mod and found the new cm.

◆ edit_module_post_actions()

edit_module_post_actions ( $moduleinfo,
$course )

Common create/update module module actions that need to be processed as soon as a module is created/updaded.

For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings... Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api.

Parameters
object$moduleinfothe module info
object$coursethe course of the module
Return values
objectmoduleinfo update with grading management info

◆ expand_value()

expand_value ( array & $dest,
array $source,
array $option,
string $optionname )

'Converts' a value from what is used in edit forms into a value(s) to be stored in the database.

Parameters
array$destThe destination array
array$sourceThe source array
array$optionThe definition structure of the option.
string$optionnameThe name of the option, as provided in the definition.

◆ get_category_or_system_context()

get_category_or_system_context ( $categoryid)

Return the course category context for the category with id $categoryid, except that if $categoryid is 0, return the system context.

Parameters
integer$categoryida category id or 0.
Return values
contextthe corresponding context

◆ get_hidden_courses_on_timeline()

get_hidden_courses_on_timeline ( $user = null)

Get a list of hidden courses.

Parameters
int | object | null$userUser override to get the filter from. Defaults to current user
Return values
array\$idsList of hidden courses
Exceptions
coding_exception

◆ get_module_types_names()

get_module_types_names ( $plural = false,
$resetcache = false )

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.

Parameters
bool$pluralIf true, the function returns the plural forms of the names.
bool$resetcacheIf true, the static cache will be reset
Return values
lang_string[]Localised human-readable names of all used modules.

◆ get_moduleinfo_data()

get_moduleinfo_data ( $cm,
$course )

Get module information data required for updating the module.

Parameters
stdClass$cmcourse module object
stdClass$coursecourse object
Return values
arrayrequired data for updating a module
Since
Moodle 3.2

◆ get_section_name()

get_section_name ( $courseorid,
$section )

Returns the display name of the given section that the course prefers.

Implementation of this function is provided by course format

See also
core_courseformat\base\get_section_name()
Parameters
int | stdClass$courseoridThe course to get the section name for (object or just course id)
int | stdClass$sectionSection object from database or just field course_sections.section
Return values
stringDisplay name that the course format prefers, e.g. "Week 2"

◆ get_sorted_course_formats()

get_sorted_course_formats ( $enabledonly = false)

Returns the sorted list of available course formats, filtered by enabled if necessary.

Parameters
bool$enabledonlyreturn only formats that are enabled
Return values
arrayarray of sorted format names

◆ include_course_ajax()

include_course_ajax ( $course,
$usedmodules = array(),
$enabledmodules = null,
$config = null )

Include the relevant javascript and language strings for the resource toolbox YUI module.

Parameters
integer$idThe ID of the course being applied to
array$usedmodulesAn array containing the names of the modules in use on the page
array$enabledmodulesAn array containing the names of the enabled (visible) modules on this site
stdClass$configAn object containing configuration parameters for ajax modules including:
  • resourceurl The URL to post changes to for resource changes
  • sectionurl The URL to post changes to for section changes
  • pageparams Additional parameters to pass through in the post
Return values
bool

◆ include_course_editor()

include_course_editor ( course_format $format)

Include and configure the course editor modules.

Parameters
course_format$formatthe course format instance.

◆ include_modulelib()

include_modulelib ( $modulename)

Include once the module lib file.

Parameters
string$modulenamemodule name of the lib to include
Exceptions
moodle_exceptionif lib.php file for the module does not exist

◆ mod_duplicate_activity()

mod_duplicate_activity ( $course,
$cm,
$sr = null )

Duplicate a module on the course for ajax.

See also
mod_duplicate_module()
Parameters
object$courseThe course
object$cmThe course module to duplicate
int$srThe section to link back to (used for creating the links)
Exceptions
moodle_exceptionif the plugin doesn't support duplication
Return values
Objectcontaining:
  • fullcontent: The HTML markup for the created CM
  • cmid: The CMID of the newly created CM
  • redirect: Whether to trigger a redirect following this change

◆ move_courses()

move_courses ( $courseids,
$categoryid )

Efficiently moves many courses around while maintaining sortorder in order.

Parameters
array$courseidsis an array of course ids
int$categoryid
Return values
boolsuccess

◆ move_section_to()

move_section_to ( $course,
$section,
$destination,
$ignorenumsections = false )

Moves a section within a course, from a position to another.

Be very careful: $section and $destination refer to section number, not id!.

Parameters
object$course
int$sectionSection number (not id!!!)
int$destination
bool$ignorenumsections
Return values
booleanResult

◆ moveto_module()

moveto_module ( $mod,
$section,
$beforemod = NULL )

Move the module object $mod to the specified $section If $beforemod exists then that is the module before which $modid should be inserted.

Parameters
stdClass | cm_info$mod
stdClass | section_info$section
int | stdClass$beforemodid or object with field id corresponding to the module before which the module needs to be included. Null for inserting in the end of the section
Return values
intnew value for module visibility (0 or 1)

◆ plugin_extend_coursemodule_edit_post_actions()

plugin_extend_coursemodule_edit_post_actions ( $moduleinfo,
$course )

Hook for plugins to take action when a module is created or updated.

Parameters
stdClass$moduleinfothe module info
stdClass$coursethe course of the module
Return values
stdClassmoduleinfo updated by plugins.

◆ prepare_new_moduleinfo_data()

prepare_new_moduleinfo_data ( $course,
$modulename,
$section,
string $suffix = '' )

Prepare the standard module information for a new module instance.

Parameters
stdClass$coursecourse object
string$modulenamemodule name
int$sectionsection number
string$suffixthe suffix to add to the name of the completion rules.
Return values
arraymodule information about other required data
Since
Moodle 3.2

◆ print_course_request_buttons()

print_course_request_buttons ( $context)

Print the buttons relating to course requests.

Parameters
context$contextcurrent page context.
Deprecated
since Moodle 4.0
Todo
Final deprecation MDL-73976

◆ reorder_sections()

reorder_sections ( $sections,
$origin_position,
$target_position )

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

Parameters
array$sections
int$origin_position
int$target_position
Return values
array

◆ save_local_role_names()

save_local_role_names ( $courseid,
$data )

Save the Your name for 'Some role' strings.

Parameters
integer$courseidthe id of this course.
array$datathe data that came from the course settings form.

◆ set_coursemodule_groupmode()

set_coursemodule_groupmode ( $id,
$groupmode )

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 core::event::course_module_updated::create_from_cm().

Parameters
int$idcourse module ID.
int$groupmodethe new groupmode value.
Return values
boolTrue if the $groupmode was updated.

◆ set_coursemodule_name()

set_coursemodule_name ( $id,
$name )

Changes the course module name.

Parameters
int$idcourse module id
string$namenew value for a name
Return values
boolwhether a change was made

◆ set_coursemodule_visible()

set_coursemodule_visible ( $id,
$visible,
$visibleoncoursepage = 1,
bool $rebuildcache = true )

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 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 set_section_visible() which was the only place from which the parameter was used.

If $rebuildcache is set to false, the calling code is responsible for ensuring the cache is purged and rebuilt as appropriate. Consider using this if set_coursemodule_visible is called multiple times (e.g. in a loop).

Parameters
int$idof the module
int$visiblestate of the module
int$visibleoncoursepagestate of the module on the course page
bool$rebuildcacheIf true (default), perform a partial cache purge and rebuild.
Return values
boolfalse when the module was not found, true otherwise

◆ set_downloadcontent()

set_downloadcontent ( int $id,
bool $downloadcontent )

Set downloadcontent value to course module.

Parameters
int$idThe id of the module.
bool$downloadcontentWhether the module can be downloaded when download course content is enabled.
Return values
boolTrue if downloadcontent has been updated, false otherwise.

◆ set_moduleinfo_defaults()

set_moduleinfo_defaults ( $moduleinfo)

Set module info default values for the unset module attributs.

Parameters
object$moduleinfothe current known data of the module
Return values
objectthe completed module info

◆ set_section_visible()

set_section_visible ( $courseid,
$sectionnumber,
$visibility )

For a given course section, marks it visible or hidden, and does the same for every activity in that section.

Parameters
int$courseidcourse id
int$sectionnumberThe section number to adjust
int$visibilityThe new visibility
Return values
arrayA list of resources which were hidden in the section

◆ update_course()

update_course ( $data,
$editoroptions = NULL )

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

Parameters
object$data- all the data needed for an entry in the 'course' table
array$editoroptionscourse description editor options
Return values
void

◆ update_module()

update_module ( $moduleinfo)

Update a module.

It includes:

  • capability and other checks
  • update the module
Parameters
object$module
Return values
objectthe updated module info
Exceptions
moodle_exceptionif current user is not allowed to update the module

◆ update_moduleinfo()

update_moduleinfo ( $cm,
$moduleinfo,
$course,
$mform = null )

Update the module info.

This function doesn't check the user capabilities. It updates the course module and the module instance. Then execute common action to create/update module process (trigger event, rebuild cache, save plagiarism settings...).

Parameters
object$cmcourse module
object$moduleinfomodule info
object$coursecourse of the module
object$mform- the mform is required by some specific module in the function MODULE_update_instance(). This is due to a hack in this function.
Return values
arraylist of course module and module info.

Variable Documentation

◆ COURSE_MAX_SUMMARIES_PER_PAGE

const COURSE_MAX_SUMMARIES_PER_PAGE 10

Number of courses to display when summaries are included.

Deprecated
since 2.4, use $CFG->courseswithsummarieslimit instead.