Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
lib.php File Reference

Functions

 forum_activity_actionbar (?forum_entity $forum, $groupid, stdClass $course, string $search='')
 Retrieve HTML for the page action.
 
object forum_add_attachment ($post, $forum, $cm, $mform=null, $unused=null)
 If successful, this function returns the name of the file.
 
 forum_add_discussion ($discussion, $mform=null, $unused=null, $userid=null)
 Given an object containing all the necessary data, create a new discussion and return the id.
 
 forum_add_instance ($forum, $mform=null)
 STANDARD FUNCTIONS ///////////////////////////////////////////////////////////.
 
 forum_add_new_post ($post, $mform, $unused=null)
 Add a new post in an existing discussion.
 
 forum_can_create_attachment ($forum, $context)
 Check if the user can create attachments in a forum.
 
object forum_change_discussionid ($postid, $discussionid)
 recursively sets the discussion field to $discussionid on $postid and all its children used when pruning a post
 
 forum_check_blocking_threshold ($thresholdwarning)
 Throws an error if the user is no longer allowed to post due to having reached or exceeded the number of posts specified in 'Post threshold for blocking' setting.
 
 forum_check_throttling ($forum, $cm=null)
 Returns a warning object if a user has reached the number of posts equal to the warning/blocking setting, or false if there is no warning to show.
 
 forum_check_updates_since (cm_info $cm, $from, $filter=array())
 Check if the module has any update that affects the current user since a given time.
 
 forum_count_discussion_replies ($forumid, $forumsort="", $limit=-1, $page=-1, $perpage=0, $canseeprivatereplies=false)
 Returns an array of counts of replies to each discussion.
 
object forum_count_discussions ($forum, $cm, $course)
 @global object @global object
 
object forum_count_user_posts ($forumid, $userid)
 Get all the posts for a user in a forum suitable for forum_print_post.
 
object forum_delete_discussion ($discussion, $fulldelete, $course, $cm, $forum)
 Deletes a discussion and handles all associated cleanup.
 
object forum_delete_instance ($id)
 Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it.
 
object forum_delete_post ($post, $children, $course, $cm, $forum, $skipcompletion=false)
 Deletes a single forum post.
 
 forum_discussion_is_locked ($forum, $discussion)
 Determine whether the specified discussion is time-locked.
 
 forum_discussion_pin ($modcontext, $forum, $discussion)
 Set the discussion to pinned and trigger the discussion pinned event.
 
 forum_discussion_unpin ($modcontext, $forum, $discussion)
 Set discussion to unpinned and trigger the discussion unpin event.
 
object forum_discussion_update_last_post ($discussionid)
 Sets the last post for a given discussion.
 
 forum_discussion_view ($modcontext, $forum, $discussion)
 Trigger the discussion viewed event.
 
object forum_discussions_user_has_posted_in ($forumid, $userid)
 @global object
 
 forum_extend_settings_navigation (settings_navigation $settingsnav, navigation_node $forumnode)
 Adds module specific settings to the settings block.
 
 forum_filter_user_groups_discussions ()
 
 forum_get_all_discussion_posts ($discussionid, $sort, $tracking=false)
 Gets all posts in discussion including top parent.
 
 forum_get_context ($forumid, $context=null)
 Determine the current context if one was not already specified.
 
object forum_get_course_forum ($courseid, $type)
 @global object
 
 forum_get_coursemodule_info ($coursemodule)
 Add a get_coursemodule_info function in case any forum type wants to add 'extra' information for the course (see resource).
 
moodle_database forum_get_courses_user_posted_in ($user, $discussionsonly=false, $includecontexts=true, $limitfrom=null, $limitnum=null)
 Gets all of the courses where the provided user has posted in a forum.
 
 forum_get_default_sort_order ($desc=true, $compare='d.timemodified', $prefix='d', $pinned=true)
 Get the sql to use in the ORDER BY clause for forum discussions.
 
 forum_get_discussion_neighbours ($cm, $discussion, $forum)
 Gets the neighbours (previous and next) of a discussion.
 
 forum_get_discussion_subscription_icon ($forum, $discussionid, $returnurl=null, $includetext=false)
 Return the markup for the discussion subscription toggling icon.
 
 forum_get_discussion_subscription_icon_preloaders ()
 Return a pair of spans containing classes to allow the subscribe and unsubscribe icons to be pre-loaded by a browser.
 
object forum_get_discussions ($cm, $forumsort="", $fullpost=true, $unused=-1, $limit=-1, $userlastmodified=false, $page=-1, $perpage=0, $groupid=-1, $updatedsince=0)
 Get all discussions in a forum.
 
object forum_get_discussions_count ($cm)
 @global object @global object @uses CONEXT_MODULE @uses VISIBLEGROUPS
 
object forum_get_discussions_unread ($cm)
 @global object @global object @uses CONTEXT_MODULE @uses VISIBLEGROUPS
 
 forum_get_email_message_id ($postid, $usertoid)
 Create a message-id string to use in the custom headers of forum notification emails.
 
 forum_get_extra_capabilities ()
 Returns all other caps used in module.
 
 forum_get_file_areas ($course, $cm, $context)
 Lists all browsable file areas.
 
 forum_get_file_info ($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename)
 File browsing support for forum module.
 
object forum_get_firstpost_from_discussion ($discussionid)
 Given a discussion id, return the first post from the discussion.
 
 forum_get_forum_types ()
 Returns array of forum types chooseable on the forum editing form.
 
 forum_get_forum_types_all ()
 Returns array of all forum layout modes.
 
moodle_database forum_get_forums_user_posted_in ($user, array $courseids=null, $discussionsonly=false, $limitfrom=null, $limitnum=null)
 Gets all of the forums a user has posted in for one or more courses.
 
 forum_get_layout_modes (bool $useexperimentalui=false)
 Returns array of forum layout modes.
 
 forum_get_post_actions ()
 List the actions that correspond to a post of this module.
 
object forum_get_post_from_log ($log)
 Given a log entry, return the forum post details for it.
 
object forum_get_post_full ($postid)
 Gets a post with all info ready for forum_print_post Most of these joins are just to get the forum id.
 
moodle_database forum_get_posts_by_user ($user, array $courses, $musthaveaccess=false, $discussionsonly=false, $limitfrom=0, $limitnum=50)
 Returns posts made by the selected user in the requested courses.
 
object forum_get_readable_forums ($userid, $courseid=0)
 An array of forum objects that the user is allowed to read/search through.
 
object forum_get_recent_mod_activity (&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0)
 Returns all forum posts since a given time in specified forum.
 
 forum_get_subscribe_link ($forum, $context, $messages=array(), $cantaccessagroup=false, $unused1=true, $backtoindex=false, $unused2=null)
 Generate and return the subscribe or unsubscribe link for a forum.
 
 forum_get_subscriptionmode_options ()
 List the options for forum subscription modes.
 
 forum_get_user_digest_options ($user=null)
 Retrieve the list of available user digest options.
 
object forum_get_user_involved_discussions ($forumid, $userid)
 Get all the discussions user participated in.
 
 forum_get_user_maildigest_bulk ($digests, $user, $forumid)
 Determine the maildigest setting for the specified user against the specified forum.
 
 forum_get_user_posted_mailnow (int $did, int $userid)
 Returns true if user posted with mailnow in given discussion.
 
object forum_get_user_posted_time ($did, $userid)
 Returns creation time of the first user's post in given discussion $DB.
 
object forum_get_user_posts ($forumid, $userid)
 Get all the posts for a user in a forum suitable for forum_print_post.
 
 forum_get_view_actions ()
 List the actions that correspond to a view of this module.
 
object forum_go_back_to ($default)
 
 forum_grade_item_delete ($forum)
 Delete grade item for given forum.
 
 forum_grade_item_update ($forum, $ratings=null, $forumgrades=null)
 Create/update grade items for given forum.
 
 forum_grading_areas_list ()
 Lists all gradable areas for the advanced grading methods gramework.
 
 forum_instance_created ($context, $forum)
 Handle changes following the creation of a forum instance.
 
 forum_is_author_hidden ($post, $forum)
 Checks whether the author's name and picture for a given post should be hidden or not.
 
 forum_is_cutoff_date_reached ($forum)
 Determine whether the specified forum's cutoff date is reached.
 
 forum_is_due_date_reached ($forum)
 Determine whether the specified forum's due date is reached.
 
 forum_is_user_group_discussion (cm_info $cm, $discussiongroupid)
 Returns whether the discussion group is visible by the current user or not.
 
object forum_move_attachments ($discussion, $forumfrom, $forumto)
 Given a discussion object that is being moved to $forumto, this function checks all posts in that discussion for attachments, and if any are found, these are moved to the new forum directory.
 
 forum_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types.
 
 forum_pluginfile ($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array())
 Serves the forum attachments.
 
 forum_post_is_visible_privately ($post, $cm)
 Check whether the forum post is a private reply visible to this user.
 
 forum_post_subscription ($fromform, $forum, $discussion)
 Given a new post, subscribes or unsubscribes as appropriate.
 
object forum_print_attachments ($post, $cm, $type)
 Returns attachments as formated text/html optionally with separate images.
 
 forum_print_mode_form ($id, $mode, $forumtype='')
 Print the drop down that allows the user to select how they want to have the discussion displayed.
 
 forum_print_overview ()
 
object forum_print_recent_activity ($course, $viewfullnames, $timestart)
 Given a course and a date, prints a summary of all the new messages posted in the course since that date.
 
 forum_print_recent_mod_activity ($activity, $courseid, $detail, $modnames, $viewfullnames)
 Outputs the forum post indicated by $activity.
 
 forum_rating_permissions ($contextid, $component, $ratingarea)
 Return rating related permissions.
 
 forum_rating_validate ($params)
 Validates a submitted rating.
 
 forum_refresh_events (int $courseid, stdClass $instance, stdClass $cm)
 This callback will check the provided instance of this module and make sure there are up-to-date events created for it.
 
 forum_reset_course_form_defaults ($course)
 Course reset form defaults.
 
 forum_reset_course_form_definition (&$mform)
 Called by course/reset.php.
 
object forum_reset_gradebook ($courseid, $type='')
 Removes all grades from gradebook.
 
object forum_reset_userdata ($data)
 This function is used by the reset_course_userdata function in moodlelib.
 
 forum_scale_used_anywhere (int $scaleid)
 Checks if scale is being used by any instance of forum.
 
object forum_search_form ($course, $search='')
 
object forum_search_posts ($searchterms, $courseid, $limitfrom, $limitnum, &$totalcount, $extrasql='')
 Returns a list of posts found using an array of search terms.
 
object forum_set_return ()
 @global object
 
 forum_set_user_maildigest ($forum, $maildigest, $user=null)
 Set the per-forum maildigest option for the specified user.
 
 forum_supports ($feature)
 Indicates API features that the forum supports.
 
object forum_tp_add_read_record ($userid, $postid)
 Mark post as read.
 
object forum_tp_can_track_forums ($forum=false, $user=false)
 Determine if a user can track forums and optionally a particular forum.
 
object forum_tp_clean_read_records ()
 Clean old records from the forum_read table.
 
object forum_tp_count_forum_unread_posts ($cm, $course, $resetreadcache=false)
 Returns the count of records for the provided user and forum and [optionally] group.
 
object forum_tp_delete_read_records ($userid=-1, $postid=-1, $discussionid=-1, $forumid=-1)
 Deletes read records for the specified index.
 
object forum_tp_get_course_unread_posts ($userid, $courseid)
 Returns the count of records for the provided user and course.
 
object forum_tp_get_untracked_forums ($userid, $courseid)
 Get a list of forums not tracked by the user.
 
object forum_tp_is_post_old ($post, $time=null)
 
object forum_tp_is_post_read ($userid, $post)
 
object forum_tp_is_tracked ($forum, $user=false)
 Tells whether a specific forum is tracked by the user.
 
object forum_tp_mark_discussion_read ($user, $discussionid)
 Marks a whole discussion as read, for a given user.
 
object forum_tp_mark_forum_read ($user, $forumid, $groupid=false)
 Marks a whole forum as read, for a given user.
 
 forum_tp_mark_post_read ($userid, $post, $unused=null)
 If its an old post, do nothing.
 
object forum_tp_mark_posts_read ($user, $postids)
 Mark posts as read.
 
object forum_tp_start_tracking ($forumid, $userid=false)
 @global object
 
object forum_tp_stop_tracking ($forumid, $userid=false)
 @global object
 
 forum_trigger_content_uploaded_event ($post, $cm, $name)
 Sends post content to plagiarism plugin.
 
 forum_trigger_post_updated_event ($post, $discussion, $context, $forum)
 Trigger post updated event.
 
 forum_update_grades ($forum, $userid=0)
 Update activity grades.
 
object forum_update_instance ($forum, $mform)
 Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will update an existing instance with new data.
 
 forum_update_post ($newpost, $mform, $unused=null)
 Update a post.
 
object forum_user_can_post ($forum, $discussion, $user=NULL, $cm=NULL, $course=NULL, $context=NULL)
 This function checks whether the user can reply to posts in a forum discussion.
 
object forum_user_can_post_discussion ($forum, $currentgroup=null, $unused=-1, $cm=NULL, $context=NULL)
 
 forum_user_can_reply_privately (\context_module $context, stdClass $parent)
 Check whether the user can reply privately to the parent post.
 
object forum_user_can_see_discussion ($forum, $discussion, $context, $user=NULL)
 @global object @uses DEBUG_DEVELOPER
 
 forum_user_can_see_group_discussion ($discussion, $cm, $context)
 Check to ensure a user can view a group discussion.
 
 forum_user_can_see_post ($forum, $discussion, $post, $user=null, $cm=null, $checkdeleted=true)
 Check whether a user can see the specified post.
 
 forum_user_can_see_timed_discussion ($discussion, $user, $context)
 Check to ensure a user can view a timed discussion.
 
object forum_user_complete ($course, $user, $mod, $forum)
 @global object
 
object forum_user_has_posted ($forumid, $did, $userid)
 @global object
 
 forum_user_has_posted_discussion ($forumid, $userid, $groupid=null)
 Returns true if user created new discussion already.
 
 forum_user_outline ($course, $user, $mod, $forum)
 
 forum_view ($forum, $course, $cm, $context)
 Mark the activity completed (if required) and trigger the course_module_viewed event.
 
 mod_forum_core_calendar_event_action_shows_item_count (calendar_event $event, $itemcount=0)
 Callback function that determines whether an action event should be showing its item count based on the event type and the item count.
 
 mod_forum_core_calendar_event_timestart_updated (\calendar_event $event, stdClass $forum)
 This function will update the forum module according to the event that has been modified.
 
 mod_forum_core_calendar_get_event_action_string (string $eventtype)
 Callback to fetch the activity event type lang string.
 
 mod_forum_core_calendar_get_valid_event_timestart_range (\calendar_event $event, stdClass $forum)
 This function calculates the minimum and maximum cutoff values for the timestart of the given event.
 
 mod_forum_core_calendar_provide_event_action (calendar_event $event, core_calendar\action_factory $factory, int $userid=0)
 This function receives a calendar event and returns the action associated with it, or null if there is none.
 
 mod_forum_count_all_discussions (\mod_forum\local\entities\forum $forum, stdClass $user, ?int $groupid)
 Get a count of all discussions in a forum.
 
 mod_forum_get_completion_active_rule_descriptions ($cm)
 Callback which returns human-readable strings describing the active completion custom rules for the module instance.
 
 mod_forum_get_discussion_summaries (\mod_forum\local\entities\forum $forum, stdClass $user, ?int $groupid, ?int $sortorder, ?int $pageno=0, ?int $pagesize=0)
 Fetch the data used to display the discussions on the current page.
 
 mod_forum_get_fontawesome_icon_map ()
 Get icon mapping for font-awesome.
 
 mod_forum_get_groups_from_groupid (\mod_forum\local\entities\forum $forum, stdClass $user, ?int $groupid)
 Get the list of groups to show based on the current user and requested groupid.
 
 mod_forum_inplace_editable ($itemtype, $itemid, $newvalue)
 Manage inplace editable saves.
 
 mod_forum_myprofile_navigation (core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)
 Add nodes to myprofile page.
 
 mod_forum_rating_can_see_item_ratings ($params)
 Can the current user see ratings for a given itemid?
 
 mod_forum_user_preferences ()
 Return a list of all the user preferences used by mod_forum.
 

Variables

const FORUM_CHOOSESUBSCRIBE 0
 
const FORUM_DISALLOWSUBSCRIBE 3
 
const FORUM_DISCUSSION_PINNED 1
 
const FORUM_DISCUSSION_UNPINNED 0
 
const FORUM_FORCESUBSCRIBE 1
 
const FORUM_INITIALSUBSCRIBE 2
 
const FORUM_MAILED_ERROR 2
 
const FORUM_MAILED_PENDING 0
 
const FORUM_MAILED_SUCCESS 1
 
const FORUM_MODE_FLATNEWEST -1
 
const FORUM_MODE_FLATOLDEST 1
 Include required files.
 
const FORUM_MODE_NESTED 3
 
const FORUM_MODE_NESTED_V2 4
 
const FORUM_MODE_THREADED 2
 
const FORUM_POSTS_ALL_USER_GROUPS (!defined('FORUM_CRON_USER_CACHE')) -2
 FORUM_POSTS_ALL_USER_GROUPS - All the posts in groups where the user is enrolled.
 
const FORUM_TRACKING_FORCED 2
 FORUM_TRACKING_FORCED - Tracking is on, regardless of user setting.
 
const FORUM_TRACKING_OFF 0
 FORUM_TRACKING_OFF - Tracking is not available for this forum.
 
const FORUM_TRACKING_OPTIONAL 1
 FORUM_TRACKING_OPTIONAL - Tracking is based on user preference.