Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Classes | Functions | Variables
lib.php File Reference

Library of useful functions. More...

Classes

class  course_request
 

Functions

 add_course_module ($mod)
 MODULE FUNCTIONS /////////////////////////////////////////////////////////////////.
 
 average_number_of_courses_modules ()
 Average number of course modules. More...
 
 average_number_of_participants (bool $onlyactive=false, int $lastloginsince=null)
 Calculate the average number of enrolled participants per course. More...
 
 build_mnet_logs_array ($hostid, $course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='', $modname="", $modid=0, $modaction="", $groupid=0)
 
 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. More...
 
 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. More...
 
 can_edit_in_category ($categoryid=0)
 Does the user have permission to edit things in this category? More...
 
 compare_activities_by_time_asc ($a, $b)
 Compare two objects to find out their correct order based on timestamp (to be used by usort). More...
 
 compare_activities_by_time_desc ($a, $b)
 Compare two objects to find out their correct order based on timestamp (to be used by usort). More...
 
 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. More...
 
 core_course_inplace_editable ($itemtype, $itemid, $newvalue)
 Implements callback inplace_editable() allowing to edit values in-place. More...
 
 course_add_cm_to_section ($courseorid, $cmid, $sectionnum, $beforemod=null)
 Adds an existing module to the section. More...
 
 course_ajax_enabled ($course)
 Determine whether course ajax should be enabled for the specified course. More...
 
 course_allowed_module ($course, $modname, stdClass $user=null)
 Is the user allowed to add this type of module to this course? More...
 
 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). More...
 
 course_can_view_participants ($context)
 Returns true if the user can view the participant page, false otherwise,. More...
 
 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. More...
 
 course_change_sortorder_by_one ($course, $up)
 Changes the course sortorder by one, moving it up or down one in respect to sort order. More...
 
 course_change_visibility ($courseid, $show=true)
 Changes the visibility of a course. More...
 
 course_check_module_updates_since ($cm, $from, $fileareas=array(), $filter=array())
 Check module updates since a given time. More...
 
 course_check_updates ($course, $tocheck, $filter=array())
 Check for course updates in the given context level instances (only modules supported right Now) More...
 
 course_classify_courses_for_timeline (array $courses)
 Group a list of courses into either past, future, or in progress. More...
 
 course_classify_end_date ($course)
 This function calculates the end date to use for display classification purposes, incorporating the grace period, if any. More...
 
 course_classify_for_timeline ($course, $user=null, $completioninfo=null)
 This function classifies a course as past, in progress or future. More...
 
 course_classify_start_date ($course)
 This function calculates the start date to use for display classification purposes, incorporating the grace period, if any. More...
 
 course_create_section ($courseorid, $position=0, $skipcheck=false)
 Creates a course section and adds it to the specified position. More...
 
 course_create_sections_if_missing ($courseorid, $sections)
 Creates missing course section(s) and rebuilds course cache. More...
 
 course_delete_module ($cmid, $async=false)
 This function will handle the whole deletion process of a module. More...
 
 course_delete_section ($course, $section, $forcedeleteifnotempty=true, $async=false)
 This method will delete a course section and may delete all modules inside it. More...
 
 course_delete_section_async ($section, $forcedeleteifnotempty=true)
 Course section deletion, using an adhoc task for deletion of the modules it contains. More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 course_format_ajax_support ($format)
 Returns the information about the ajax support in the given source format. More...
 
 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. More...
 
 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. More...
 
 course_get_cm_move (cm_info $mod, $sr=null)
 Returns the move action. More...
 
 course_get_course_dates_for_user_id (stdClass $course, int $userid)
 Calculate the course start date and offset for the given user id. More...
 
 course_get_course_dates_for_user_ids (stdClass $course, array $userids)
 Calculate the course start date and offset for the given user ids. More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 course_get_tagged_courses ($tag, $exclusivemode=false, $fromctx=0, $ctx=0, $rec=1, $page=0)
 Returns courses tagged with a specified tag. More...
 
 course_get_url ($courseorid, $section=null, $options=array())
 The URL to use for the specified course (with section) More...
 
 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. More...
 
 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. More...
 
 course_integrity_check ($courseid, $rawmods=null, $sections=null, $fullcheck=false, $checkonly=false)
 Checks the integrity of the course data. More...
 
 course_module_bulk_update_calendar_events ($modulename, $courseid=0)
 Update all instances through out the site or in a course. More...
 
 course_module_calendar_event_update_process ($instance, $cm)
 Calendar events for a module instance are updated. More...
 
 course_module_flag_for_async_deletion ($cmid)
 Schedule a course module for deletion in the background using an adhoc task. More...
 
 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. More...
 
 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. More...
 
 course_modules_pending_deletion (int $courseid, bool $onlygradable=false)
 Checks whether the given course has any course modules scheduled for adhoc deletion. More...
 
 course_output_fragment_new_base_form ($args)
 Renders the course copy form for the modal on the course management screen. More...
 
 course_overviewfiles_options ($course)
 Returns options to use in course overviewfiles filemanager. More...
 
 course_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types. More...
 
 course_require_view_participants ($context)
 Checks if a user can view the participant page, if not throws an exception. More...
 
 course_set_marker ($courseid, $marker)
 Set highlighted section. More...
 
 course_update_section ($course, $section, $data)
 Updates the course section. More...
 
 course_validate_dates ($coursedata)
 Validates course start and end dates. More...
 
 course_view ($context, $sectionnumber=0)
 Trigger course viewed event. More...
 
 create_course ($data, $editoroptions=NULL)
 Create a course and either return a $course object. More...
 
 create_module ($moduleinfo)
 Create a module. More...
 
 delete_mod_from_section ($modid, $sectionid)
 
 duplicate_module ($course, $cm)
 Api to duplicate a module. More...
 
 get_array_of_activities ($courseid)
 For a given course, returns an array of course activity objects Each item in the array contains he following properties:
 
 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. More...
 
 get_hidden_courses_on_timeline ($user=null)
 Get a list of hidden courses. More...
 
 get_module_types_names ($plural=false)
 Returns the localised human-readable names of all used modules. More...
 
 get_section_name ($courseorid, $section)
 Returns the display name of the given section that the course prefers. More...
 
 get_sorted_course_formats ($enabledonly=false)
 Returns the sorted list of available course formats, filtered by enabled if necessary. More...
 
 include_course_ajax ($course, $usedmodules=array(), $enabledmodules=null, $config=null)
 Include the relevant javascript and language strings for the resource toolbox YUI module. More...
 
 make_categories_options ()
 Returns the list of full course categories to be used in html_writer::select() More...
 
 make_log_url ($module, $url)
 
 mod_duplicate_activity ($course, $cm, $sr=null)
 Duplicate a module on the course for ajax. More...
 
 move_courses ($courseids, $categoryid)
 Efficiently moves many courses around while maintaining sortorder in order. More...
 
 move_section_to ($course, $section, $destination, $ignorenumsections=false)
 Moves a section within a course, from a position to another. More...
 
 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. More...
 
 print_course_request_buttons ($context)
 Print the buttons relating to course requests. More...
 
 reorder_sections ($sections, $origin_position, $target_position)
 Reordering algorithm for course sections. More...
 
 save_local_role_names ($courseid, $data)
 Save the Your name for 'Some role' strings. More...
 
 set_coursemodule_groupmode ($id, $groupmode)
 Change the group mode of a course module. More...
 
 set_coursemodule_idnumber ($id, $idnumber)
 
 set_coursemodule_name ($id, $name)
 Changes the course module name. More...
 
 set_coursemodule_visible ($id, $visible, $visibleoncoursepage=1)
 Set the visibility of a module and inherent properties. More...
 
 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. More...
 
 update_course ($data, $editoroptions=NULL)
 Update a course. More...
 
 update_module ($moduleinfo)
 Update a module. More...
 

Variables

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

Library of useful functions.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later