Search moodle.org's
Developer Documentation

See Release Notes

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

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

(no description)

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 7008 lines (258 kb)
Included or required: 6 times
Referenced: 57 times
Includes or requires: 1 file
 mod/forum/deprecatedlib.php

Defines 139 functions

  forum_add_instance()
  forum_instance_created()
  forum_update_instance()
  forum_delete_instance()
  forum_supports()
  forum_get_email_message_id()
  forum_user_outline()
  forum_user_complete()
  forum_filter_user_groups_discussions()
  forum_is_user_group_discussion()
  forum_print_overview()
  forum_print_recent_activity()
  forum_update_grades()
  forum_grade_item_update()
  forum_grade_item_delete()
  forum_scale_used_anywhere()
  forum_get_post_full()
  forum_get_all_discussion_posts()
  forum_get_readable_forums()
  forum_search_posts()
  forum_get_user_posts()
  forum_get_user_involved_discussions()
  forum_count_user_posts()
  forum_get_post_from_log()
  forum_get_firstpost_from_discussion()
  forum_count_discussion_replies()
  forum_count_discussions()
  forum_get_discussions()
  forum_get_discussion_neighbours()
  forum_get_default_sort_order()
  forum_get_discussions_unread()
  forum_get_discussions_count()
  forum_get_course_forum()
  forum_rating_permissions()
  forum_rating_validate()
  mod_forum_rating_can_see_item_ratings()
  forum_print_discussion_header()
  forum_get_discussion_subscription_icon()
  forum_get_discussion_subscription_icon_preloaders()
  forum_print_mode_form()
  forum_search_form()
  forum_set_return()
  forum_go_back_to()
  forum_move_attachments()
  forum_print_attachments()
  forum_get_file_areas()
  forum_get_file_info()
  forum_pluginfile()
  forum_add_attachment()
  forum_add_new_post()
  forum_trigger_post_updated_event()
  forum_update_post()
  forum_add_discussion()
  forum_delete_discussion()
  forum_delete_post()
  forum_trigger_content_uploaded_event()
  forum_post_subscription()
  forum_get_subscribe_link()
  forum_user_has_posted_discussion()
  forum_discussions_user_has_posted_in()
  forum_user_has_posted()
  forum_get_user_posted_time()
  forum_user_can_post_discussion()
  forum_user_can_post()
  forum_user_can_see_timed_discussion()
  forum_user_can_see_group_discussion()
  forum_user_can_see_discussion()
  forum_user_can_see_post()
  forum_get_recent_mod_activity()
  forum_print_recent_mod_activity()
  forum_change_discussionid()
  forum_update_subscriptions_button()
  forum_tp_mark_posts_read()
  forum_tp_add_read_record()
  forum_tp_mark_post_read()
  forum_tp_mark_forum_read()
  forum_tp_mark_discussion_read()
  forum_tp_is_post_read()
  forum_tp_is_post_old()
  forum_tp_get_course_unread_posts()
  forum_tp_count_forum_unread_posts()
  forum_tp_delete_read_records()
  forum_tp_get_untracked_forums()
  forum_tp_can_track_forums()
  forum_tp_is_tracked()
  forum_tp_start_tracking()
  forum_tp_stop_tracking()
  forum_tp_clean_read_records()
  forum_discussion_update_last_post()
  forum_get_view_actions()
  forum_get_subscriptionmode_options()
  forum_get_post_actions()
  forum_check_throttling()
  forum_check_blocking_threshold()
  forum_reset_gradebook()
  forum_reset_userdata()
  forum_reset_course_form_definition()
  forum_reset_course_form_defaults()
  forum_get_layout_modes()
  forum_get_forum_types()
  forum_get_forum_types_all()
  forum_get_extra_capabilities()
  forum_extend_settings_navigation()
  forum_cm_info_view()
  forum_page_type_list()
  forum_get_courses_user_posted_in()
  forum_get_forums_user_posted_in()
  forum_get_posts_by_user()
  forum_set_user_maildigest()
  forum_get_user_maildigest_bulk()
  forum_get_user_digest_options()
  forum_get_context()
  forum_view()
  forum_discussion_view()
  forum_discussion_pin()
  forum_discussion_unpin()
  mod_forum_myprofile_navigation()
  forum_is_author_hidden()
  mod_forum_inplace_editable()
  forum_is_cutoff_date_reached()
  forum_is_due_date_reached()
  forum_discussion_is_locked()
  forum_check_updates_since()
  forum_can_create_attachment()
  mod_forum_get_fontawesome_icon_map()
  mod_forum_core_calendar_event_action_shows_item_count()
  mod_forum_core_calendar_provide_event_action()
  forum_get_coursemodule_info()
  mod_forum_get_completion_active_rule_descriptions()
  forum_post_is_visible_privately()
  forum_user_can_reply_privately()
  mod_forum_core_calendar_get_valid_event_timestart_range()
  mod_forum_core_calendar_event_timestart_updated()
  mod_forum_get_discussion_summaries()
  mod_forum_count_all_discussions()
  mod_forum_get_groups_from_groupid()
  mod_forum_user_preferences()
  forum_grading_areas_list()
  forum_refresh_events()

Functions that are not part of a class:

forum_add_instance($forum, $mform = null)   X-Ref
Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will create a new instance and return the id number
of the new instance.

param: stdClass $forum add forum instance
param: mod_forum_mod_form $mform
return: int intance id

forum_instance_created($context, $forum)   X-Ref
Handle changes following the creation of a forum instance.
This function is typically called by the course_module_created observer.

param: object $context the forum context
param: stdClass $forum The forum object
return: void

forum_update_instance($forum, $mform)   X-Ref
Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will update an existing instance with new data.

param: object $forum forum instance (with magic quotes)
return: bool success

forum_delete_instance($id)   X-Ref
Given an ID of an instance of this module,
this function will permanently delete the instance
and any data that depends on it.

param: int $id forum instance id
return: bool success

forum_supports($feature)   X-Ref
Indicates API features that the forum supports.

param: string $feature
return: mixed True if yes (some features may use other values)

forum_get_email_message_id($postid, $usertoid)   X-Ref
Create a message-id string to use in the custom headers of forum notification emails

message-id is used by email clients to identify emails and to nest conversations

param: int $postid The ID of the forum post we are notifying the user about
param: int $usertoid The ID of the user being notified
return: string A unique message-id

forum_user_outline($course, $user, $mod, $forum)   X-Ref

param: object $course
param: object $user
param: object $mod TODO this is not used in this function, refactor
param: object $forum
return: object A standard object with 2 variables: info (number of posts for this user) and time (last modified)

forum_user_complete($course, $user, $mod, $forum)   X-Ref

param: object $coure
param: object $user
param: object $mod
param: object $forum

forum_filter_user_groups_discussions()   X-Ref


forum_is_user_group_discussion(cm_info $cm, $discussiongroupid)   X-Ref
Returns whether the discussion group is visible by the current user or not.

param: cm_info $cm The discussion course module
param: int $discussiongroupid The discussion groupid
return: bool

forum_print_overview()   X-Ref


forum_print_recent_activity($course, $viewfullnames, $timestart)   X-Ref
Given a course and a date, prints a summary of all the new
messages posted in the course since that date

param: object $course
param: bool $viewfullnames capability
param: int $timestart
return: bool success

forum_update_grades($forum, $userid = 0)   X-Ref
Update activity grades.

param: object $forum
param: int $userid specific user only, 0 means all

forum_grade_item_update($forum, $ratings = null, $forumgrades = null)   X-Ref
Create/update grade items for given forum.

param: stdClass $forum Forum object with extra cmidnumber
param: mixed $grades Optional array/object of grade(s); 'reset' means reset grades in gradebook

forum_grade_item_delete($forum)   X-Ref
Delete grade item for given forum.

param: stdClass $forum Forum object

forum_scale_used_anywhere(int $scaleid)   X-Ref
Checks if scale is being used by any instance of forum.

This is used to find out if scale used anywhere.

param: $scaleid int
return: boolean True if the scale is used by any forum

forum_get_post_full($postid)   X-Ref
Gets a post with all info ready for forum_print_post
Most of these joins are just to get the forum id

param: int $postid
return: mixed array of posts or false

forum_get_all_discussion_posts($discussionid, $sort, $tracking = false)   X-Ref
Gets all posts in discussion including top parent.

param: int     $discussionid   The Discussion to fetch.
param: string  $sort           The sorting to apply.
param: bool    $tracking       Whether the user tracks this forum.
return: array                   The posts in the discussion.

forum_get_readable_forums($userid, $courseid=0)   X-Ref
An array of forum objects that the user is allowed to read/search through.

param: int $userid
param: int $courseid if 0, we look for forums throughout the whole site.
return: array of forum objects, or false if no matches

forum_search_posts($searchterms, $courseid, $limitfrom, $limitnum,&$totalcount, $extrasql='')   X-Ref
Returns a list of posts found using an array of search terms.

param: array $searchterms array of search terms, e.g. word +word -word
param: int $courseid if 0, we search through the whole site
param: int $limitfrom
param: int $limitnum
param: int &$totalcount
param: string $extrasql
return: array|bool Array of posts found or false

forum_get_user_posts($forumid, $userid)   X-Ref
Get all the posts for a user in a forum suitable for forum_print_post

return: array

forum_get_user_involved_discussions($forumid, $userid)   X-Ref
Get all the discussions user participated in

param: int $forumid
param: int $userid
return: array Array or false

forum_count_user_posts($forumid, $userid)   X-Ref
Get all the posts for a user in a forum suitable for forum_print_post

param: int $forumid
param: int $userid
return: array of counts or false

forum_get_post_from_log($log)   X-Ref
Given a log entry, return the forum post details for it.

param: object $log
return: array|null

forum_get_firstpost_from_discussion($discussionid)   X-Ref
Given a discussion id, return the first post from the discussion

param: int $dicsussionid
return: array

forum_count_discussion_replies($forumid, $forumsort = "", $limit = -1, $page = -1, $perpage = 0,$canseeprivatereplies = false)   X-Ref
Returns an array of counts of replies to each discussion

param: int     $forumid
param: string  $forumsort
param: int     $limit
param: int     $page
param: int     $perpage
param: boolean $canseeprivatereplies   Whether the current user can see private replies.
return: array

forum_count_discussions($forum, $cm, $course)   X-Ref

param: object $forum
param: object $cm
param: object $course
return: mixed

forum_get_discussions($cm, $forumsort="", $fullpost=true, $unused=-1, $limit=-1,$userlastmodified=false, $page=-1, $perpage=0, $groupid = -1,$updatedsince = 0)   X-Ref
Get all discussions in a forum

param: object $cm
param: string $forumsort
param: bool $fullpost
param: int $unused
param: int $limit
param: bool $userlastmodified
param: int $page
param: int $perpage
param: int $groupid if groups enabled, get discussions for this group overriding the current group.
param: int $updatedsince retrieve only discussions updated since the given time
return: array

forum_get_discussion_neighbours($cm, $discussion, $forum)   X-Ref
Gets the neighbours (previous and next) of a discussion.

The calculation is based on the timemodified when time modified or time created is identical
It will revert to using the ID to sort consistently. This is better tha skipping a discussion.

For blog-style forums, the calculation is based on the original creation time of the
blog post.

Please note that this does not check whether or not the discussion passed is accessible
by the user, it simply uses it as a reference to find the neighbours. On the other hand,
the returned neighbours are checked and are accessible to the current user.

param: object $cm The CM record.
param: object $discussion The discussion record.
param: object $forum The forum instance record.
return: array That always contains the keys 'prev' and 'next'. When there is a result

forum_get_default_sort_order($desc = true, $compare = 'd.timemodified', $prefix = 'd', $pinned = true)   X-Ref
Get the sql to use in the ORDER BY clause for forum discussions.

This has the ordering take timed discussion windows into account.

param: bool $desc True for DESC, False for ASC.
param: string $compare The field in the SQL to compare to normally sort by.
param: string $prefix The prefix being used for the discussion table.
param: bool $pinned sort pinned posts to the top
return: string

forum_get_discussions_unread($cm)   X-Ref

param: object $cm
return: array

forum_get_discussions_count($cm)   X-Ref

param: object $cm
return: array

forum_get_course_forum($courseid, $type)   X-Ref

param: int $courseid
param: string $type

forum_rating_permissions($contextid, $component, $ratingarea)   X-Ref
Return rating related permissions

param: string $options the context id
return: array an associative array of the user's rating permissions

forum_rating_validate($params)   X-Ref
Validates a submitted rating

param: array $params submitted data
return: boolean true if the rating is valid. Will throw rating_exception if not

mod_forum_rating_can_see_item_ratings($params)   X-Ref
Can the current user see ratings for a given itemid?

param: array $params submitted data
return: bool

forum_print_discussion_header(&$post, $forum, $group = -1, $datestring = "",$cantrack = true, $forumtracked = true, $canviewparticipants = true, $modcontext = null,$canviewhiddentimedposts = false)   X-Ref
This function prints the overview of a discussion in the forum listing.
It needs some discussion information and some post information, these
happen to be combined for efficiency in the $post parameter by the function
that calls this one: forum_print_latest_discussions()

param: object $post The post object (passed by reference for speed).
param: object $forum The forum object.
param: int $group Current group.
param: string $datestring Format to use for the dates.
param: boolean $cantrack Is tracking enabled for this forum.
param: boolean $forumtracked Is the user tracking this forum.
param: boolean $canviewparticipants True if user has the viewparticipants permission for this course
param: boolean $canviewhiddentimedposts True if user has the viewhiddentimedposts permission for this forum

forum_get_discussion_subscription_icon($forum, $discussionid, $returnurl = null, $includetext = false)   X-Ref
Return the markup for the discussion subscription toggling icon.

param: stdClass $forum The forum object.
param: int $discussionid The discussion to create an icon for.
return: string The generated markup.

forum_get_discussion_subscription_icon_preloaders()   X-Ref
Return a pair of spans containing classes to allow the subscribe and
unsubscribe icons to be pre-loaded by a browser.

return: string The generated markup

forum_print_mode_form($id, $mode, $forumtype='')   X-Ref
Print the drop down that allows the user to select how they want to have
the discussion displayed.

param: int $id forum id if $forumtype is 'single',
param: mixed $mode forum layout mode
param: string $forumtype optional

forum_search_form($course, $search='')   X-Ref

param: object $course
param: string $search
return: string

forum_set_return()   X-Ref


forum_go_back_to($default)   X-Ref

param: string|\moodle_url $default
return: string

forum_move_attachments($discussion, $forumfrom, $forumto)   X-Ref
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.

param: object $discussion
param: int $forumfrom source forum id
param: int $forumto target forum id
return: bool success

forum_print_attachments($post, $cm, $type)   X-Ref
Returns attachments as formated text/html optionally with separate images

param: object $post
param: object $cm
param: string $type html/text/separateimages
return: mixed string or array of (html text withouth images and image HTML)

forum_get_file_areas($course, $cm, $context)   X-Ref
Lists all browsable file areas

param: stdClass $course course object
param: stdClass $cm course module object
param: stdClass $context context object
return: array

forum_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename)   X-Ref
File browsing support for forum module.

param: stdClass $browser file browser object
param: stdClass $areas file areas
param: stdClass $course course object
param: stdClass $cm course module
param: stdClass $context context module
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info instance or null if not found

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

param: stdClass $course course object
param: stdClass $cm course module object
param: stdClass $context context object
param: string $filearea file area
param: array $args extra arguments
param: bool $forcedownload whether or not force download
param: array $options additional options affecting the file serving
return: bool false if file not found, does not return if found - justsend the file

forum_add_attachment($post, $forum, $cm, $mform=null, $unused=null)   X-Ref
If successful, this function returns the name of the file

param: object $post is a full post record, including course and forum
param: object $forum
param: object $cm
param: mixed $mform
param: string $unused
return: bool

forum_add_new_post($post, $mform, $unused = null)   X-Ref
Add a new post in an existing discussion.

param: stdClass    $post       The post data
param: mixed       $mform      The submitted form
param: string      $unused
return: int

forum_trigger_post_updated_event($post, $discussion, $context, $forum)   X-Ref
Trigger post updated event.

param: object $post forum post object
param: object $discussion discussion object
param: object $context forum context object
param: object $forum forum object
return: void

forum_update_post($newpost, $mform, $unused = null)   X-Ref
Update a post.

param: stdClass    $newpost    The post to update
param: mixed       $mform      The submitted form
param: string      $unused
return: bool

forum_add_discussion($discussion, $mform=null, $unused=null, $userid=null)   X-Ref
Given an object containing all the necessary data,
create a new discussion and return the id

param: object $post
param: mixed $mform
param: string $unused
param: int $userid
return: object

forum_delete_discussion($discussion, $fulldelete, $course, $cm, $forum)   X-Ref
Deletes a discussion and handles all associated cleanup.

param: object $discussion Discussion to delete
param: bool $fulldelete True when deleting entire forum
param: object $course Course
param: object $cm Course-module
param: object $forum Forum
return: bool

forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion=false)   X-Ref
Deletes a single forum post.

param: object $post Forum post object
param: mixed $children Whether to delete children. If false, returns false
param: object $course Course
param: object $cm Course-module
param: object $forum Forum
param: bool $skipcompletion True to skip updating completion state if it
return: bool

forum_trigger_content_uploaded_event($post, $cm, $name)   X-Ref
Sends post content to plagiarism plugin

param: object $post Forum post object
param: object $cm Course-module
param: string $name
return: bool

forum_post_subscription($fromform, $forum, $discussion)   X-Ref
Given a new post, subscribes or unsubscribes as appropriate.
Returns some text which describes what happened.

param: object $fromform The submitted form
param: stdClass $forum The forum record
param: stdClass $discussion The forum discussion record
return: string

forum_get_subscribe_link($forum, $context, $messages = array()   X-Ref
Generate and return the subscribe or unsubscribe link for a forum.

param: object $forum the forum. Fields used are $forum->id and $forum->forcesubscribe.
param: object $context the context object for this forum.
param: array $messages text used for the link in its various states
param: bool $cantaccessagroup
param: bool $unused1
param: bool $backtoindex
param: array $unused2
return: string

forum_user_has_posted_discussion($forumid, $userid, $groupid = null)   X-Ref
Returns true if user created new discussion already.

param: int $forumid  The forum to check for postings
param: int $userid   The user to check for postings
param: int $groupid  The group to restrict the check to
return: bool

forum_discussions_user_has_posted_in($forumid, $userid)   X-Ref

param: int $forumid
param: int $userid
return: array

forum_user_has_posted($forumid, $did, $userid)   X-Ref

param: int $forumid
param: int $did
param: int $userid
return: bool

forum_get_user_posted_time($did, $userid)   X-Ref
Returns creation time of the first user's post in given discussion

param: int $did Discussion id
param: int $userid User id
return: int|bool post creation time stamp or return false

forum_user_can_post_discussion($forum, $currentgroup=null, $unused=-1, $cm=NULL, $context=NULL)   X-Ref

param: object $forum
param: object $currentgroup
param: int $unused
param: object $cm
param: object $context
return: bool

forum_user_can_post($forum, $discussion, $user=NULL, $cm=NULL, $course=NULL, $context=NULL)   X-Ref
This function checks whether the user can reply to posts in a forum
discussion. Use forum_user_can_post_discussion() to check whether the user
can start discussions.

param: object $forum forum object
param: object $discussion
param: object $user
param: object $cm
param: object $course
param: object $context
return: bool

forum_user_can_see_timed_discussion($discussion, $user, $context)   X-Ref
Check to ensure a user can view a timed discussion.

param: object $discussion
param: object $user
param: object $context
return: boolean returns true if they can view post, false otherwise

forum_user_can_see_group_discussion($discussion, $cm, $context)   X-Ref
Check to ensure a user can view a group discussion.

param: object $discussion
param: object $cm
param: object $context
return: boolean returns true if they can view post, false otherwise

forum_user_can_see_discussion($forum, $discussion, $context, $user=NULL)   X-Ref

param: object $forum
param: object $discussion
param: object $context
param: object $user
return: bool

forum_user_can_see_post($forum, $discussion, $post, $user = null, $cm = null, $checkdeleted = true)   X-Ref
Check whether a user can see the specified post.

param: \stdClass $forum The forum to chcek
param: \stdClass $discussion The discussion the post is in
param: \stdClass $post The post in question
param: \stdClass $user The user to test - if not specified, the current user is checked.
param: \stdClass $cm The Course Module that the forum is in (required).
param: bool      $checkdeleted Whether to check the deleted flag on the post.
return: bool

forum_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0)   X-Ref
Returns all forum posts since a given time in specified forum.


forum_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames)   X-Ref
Outputs the forum post indicated by $activity.

param: object $activity      the activity object the forum resides in
param: int    $courseid      the id of the course the forum resides in
param: bool   $detail        not used, but required for compatibilty with other modules
param: int    $modnames      not used, but required for compatibilty with other modules
param: bool   $viewfullnames not used, but required for compatibilty with other modules

forum_change_discussionid($postid, $discussionid)   X-Ref
recursively sets the discussion field to $discussionid on $postid and all its children
used when pruning a post

param: int $postid
param: int $discussionid
return: bool

forum_update_subscriptions_button($courseid, $forumid)   X-Ref
Prints the editing button on subscribers page

param: int $courseid
param: int $forumid
return: string

forum_tp_mark_posts_read($user, $postids)   X-Ref
Mark posts as read.

param: object $user object
param: array $postids array of post ids
return: boolean success

forum_tp_add_read_record($userid, $postid)   X-Ref
Mark post as read.

param: int $userid
param: int $postid

forum_tp_mark_post_read($userid, $post, $unused = null)   X-Ref
If its an old post, do nothing. If the record exists, the maintenance will clear it up later.

param: int     $userid The ID of the user to mark posts read for.
param: object  $post   The post record for the post to mark as read.
param: mixed   $unused
return: bool

forum_tp_mark_forum_read($user, $forumid, $groupid=false)   X-Ref
Marks a whole forum as read, for a given user

param: object $user
param: int $forumid
param: int|bool $groupid
return: bool

forum_tp_mark_discussion_read($user, $discussionid)   X-Ref
Marks a whole discussion as read, for a given user

param: object $user
param: int $discussionid
return: bool

forum_tp_is_post_read($userid, $post)   X-Ref

param: int $userid
param: object $post

forum_tp_is_post_old($post, $time=null)   X-Ref

param: object $post
param: int $time Defautls to time()

forum_tp_get_course_unread_posts($userid, $courseid)   X-Ref
Returns the count of records for the provided user and course.
Please note that group access is ignored!

param: int $userid
param: int $courseid
return: array

forum_tp_count_forum_unread_posts($cm, $course, $resetreadcache = false)   X-Ref
Returns the count of records for the provided user and forum and [optionally] group.

param: object $cm
param: object $course
param: bool   $resetreadcache optional, true to reset the function static $readcache var
return: int

forum_tp_delete_read_records($userid=-1, $postid=-1, $discussionid=-1, $forumid=-1)   X-Ref
Deletes read records for the specified index. At least one parameter must be specified.

param: int $userid
param: int $postid
param: int $discussionid
param: int $forumid
return: bool

forum_tp_get_untracked_forums($userid, $courseid)   X-Ref
Get a list of forums not tracked by the user.

param: int $userid The id of the user to use.
param: int $courseid The id of the course being checked.
return: mixed An array indexed by forum id, or false.

forum_tp_can_track_forums($forum=false, $user=false)   X-Ref
Determine if a user can track forums and optionally a particular forum.
Checks the site settings, the user settings and the forum settings (if
requested).

param: mixed $forum The forum object to test, or the int id (optional).
param: mixed $userid The user object to check for (optional).
return: boolean

forum_tp_is_tracked($forum, $user=false)   X-Ref
Tells whether a specific forum is tracked by the user. A user can optionally
be specified. If not specified, the current user is assumed.

param: mixed $forum If int, the id of the forum being checked; if object, the forum object
param: int $userid The id of the user being checked (optional).
return: boolean

forum_tp_start_tracking($forumid, $userid=false)   X-Ref

param: int $forumid
param: int $userid

forum_tp_stop_tracking($forumid, $userid=false)   X-Ref

param: int $forumid
param: int $userid

forum_tp_clean_read_records()   X-Ref
Clean old records from the forum_read table.

return: void

forum_discussion_update_last_post($discussionid)   X-Ref
Sets the last post for a given discussion

param: into $discussionid
return: bool|int

forum_get_view_actions()   X-Ref
List the actions that correspond to a view of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = 'r' and edulevel = LEVEL_PARTICIPATING will
be considered as view action.

return: array

forum_get_subscriptionmode_options()   X-Ref
List the options for forum subscription modes.
This is used by the settings page and by the mod_form page.

return: array

forum_get_post_actions()   X-Ref
List the actions that correspond to a post of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING
will be considered as post action.

return: array

forum_check_throttling($forum, $cm = null)   X-Ref
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.

param: int|stdClass $forum the forum id or the forum object
param: stdClass $cm the course module
return: stdClass|bool returns an object with the warning information, else

forum_check_blocking_threshold($thresholdwarning)   X-Ref
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.

param: stdClass $thresholdwarning the warning information returned

forum_reset_gradebook($courseid, $type='')   X-Ref
Removes all grades from gradebook

param: int $courseid
param: string $type optional

forum_reset_userdata($data)   X-Ref
This function is used by the reset_course_userdata function in moodlelib.
This function will remove all posts from the specified forum
and clean up any related data.

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

forum_reset_course_form_definition(&$mform)   X-Ref
Called by course/reset.php

param: $mform form passed by reference

forum_reset_course_form_defaults($course)   X-Ref
Course reset form defaults.

return: array

forum_get_layout_modes(bool $useexperimentalui = false)   X-Ref
Returns array of forum layout modes

param: bool $useexperimentalui use experimental layout modes or not
return: array

forum_get_forum_types()   X-Ref
Returns array of forum types chooseable on the forum editing form

return: array

forum_get_forum_types_all()   X-Ref
Returns array of all forum layout modes

return: array

forum_get_extra_capabilities()   X-Ref
Returns all other caps used in module

return: array

forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode)   X-Ref
Adds module specific settings to the settings block

param: settings_navigation $settings The settings navigation object
param: navigation_node $forumnode The node to add module settings to

forum_cm_info_view(cm_info $cm)   X-Ref
Adds information about unread messages, that is only required for the course view page (and
similar), to the course-module object.

param: cm_info $cm Course-module object

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

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

forum_get_courses_user_posted_in($user, $discussionsonly = false, $includecontexts = true, $limitfrom = null, $limitnum = null)   X-Ref
Gets all of the courses where the provided user has posted in a forum.

param: stdClass $user The user who's posts we are looking for
param: bool $discussionsonly If true only look for discussions started by the user
param: bool $includecontexts If set to trye contexts for the courses will be preloaded
param: int $limitfrom The offset of records to return
param: int $limitnum The number of records to return
return: array An array of courses

forum_get_forums_user_posted_in($user, array $courseids = null, $discussionsonly = false, $limitfrom = null, $limitnum = null)   X-Ref
Gets all of the forums a user has posted in for one or more courses.

param: stdClass $user
param: array $courseids An array of courseids to search or if not provided
param: bool $discussionsonly If true then only forums where the user has started
param: int $limitfrom The offset of records to return
param: int $limitnum The number of records to return
return: array An array of forums the user has posted within in the provided courses

forum_get_posts_by_user($user, array $courses, $musthaveaccess = false, $discussionsonly = false, $limitfrom = 0, $limitnum = 50)   X-Ref
Returns posts made by the selected user in the requested courses.

This method can be used to return all of the posts made by the requested user
within the given courses.
For each course the access of the current user and requested user is checked
and then for each post access to the post and forum is checked as well.

This function is safe to use with usercapabilities.

param: stdClass $user The user whose posts we want to get
param: array $courses The courses to search
param: bool $musthaveaccess If set to true errors will be thrown if the user
param: bool $discussionsonly If set to true only discussion starting posts
param: int $limitfrom The offset of records to return
param: int $limitnum The number of records to return
return: stdClass An object the following properties

forum_set_user_maildigest($forum, $maildigest, $user = null)   X-Ref
Set the per-forum maildigest option for the specified user.

param: stdClass $forum The forum to set the option for.
param: int $maildigest The maildigest option.
param: stdClass $user The user object. This defaults to the global $USER object.

forum_get_user_maildigest_bulk($digests, $user, $forumid)   X-Ref
Determine the maildigest setting for the specified user against the
specified forum.

param: Array $digests An array of forums and user digest settings.
param: stdClass $user The user object containing the id and maildigest default.
param: int $forumid The ID of the forum to check.
return: int The calculated maildigest setting for this user and forum.

forum_get_user_digest_options($user = null)   X-Ref
Retrieve the list of available user digest options.

param: stdClass $user The user object. This defaults to the global $USER object.
return: array The mapping of values to digest options.

forum_get_context($forumid, $context = null)   X-Ref
Determine the current context if one was not already specified.

If a context of type context_module is specified, it is immediately
returned and not checked.

param: int $forumid The ID of the forum
param: context_module $context The current context.
return: context_module The context determined

forum_view($forum, $course, $cm, $context)   X-Ref
Mark the activity completed (if required) and trigger the course_module_viewed event.

param: stdClass $forum   forum object
param: stdClass $course  course object
param: stdClass $cm      course module object
param: stdClass $context context object

forum_discussion_view($modcontext, $forum, $discussion)   X-Ref
Trigger the discussion viewed event

param: stdClass $modcontext module context object
param: stdClass $forum      forum object
param: stdClass $discussion discussion object

forum_discussion_pin($modcontext, $forum, $discussion)   X-Ref
Set the discussion to pinned and trigger the discussion pinned event

param: stdClass $modcontext module context object
param: stdClass $forum      forum object
param: stdClass $discussion discussion object

forum_discussion_unpin($modcontext, $forum, $discussion)   X-Ref
Set discussion to unpinned and trigger the discussion unpin event

param: stdClass $modcontext module context object
param: stdClass $forum      forum object
param: stdClass $discussion discussion object

mod_forum_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course)   X-Ref
Add nodes to myprofile page.

param: \core_user\output\myprofile\tree $tree Tree object
param: stdClass $user user object
param: bool $iscurrentuser
param: stdClass $course Course object
return: bool

forum_is_author_hidden($post, $forum)   X-Ref
Checks whether the author's name and picture for a given post should be hidden or not.

param: object $post The forum post.
param: object $forum The forum object.
return: bool

mod_forum_inplace_editable($itemtype, $itemid, $newvalue)   X-Ref
Manage inplace editable saves.

param: string      $itemtype       The type of item.
param: int         $itemid         The ID of the item.
param: mixed       $newvalue       The new value
return: string

forum_is_cutoff_date_reached($forum)   X-Ref
Determine whether the specified forum's cutoff date is reached.

param: stdClass $forum The forum
return: bool

forum_is_due_date_reached($forum)   X-Ref
Determine whether the specified forum's due date is reached.

param: stdClass $forum The forum
return: bool

forum_discussion_is_locked($forum, $discussion)   X-Ref
Determine whether the specified discussion is time-locked.

param: stdClass    $forum          The forum that the discussion belongs to
param: stdClass    $discussion     The discussion to test
return: bool

forum_check_updates_since(cm_info $cm, $from, $filter = array()   X-Ref
Check if the module has any update that affects the current user since a given time.

param: cm_info $cm course module data
param: int $from the time to check updates from
param: array $filter  if we need to check only specific updates
return: stdClass an object with the different type of areas indicating if they were updated or not

forum_can_create_attachment($forum, $context)   X-Ref
Check if the user can create attachments in a forum.

param: stdClass $forum   forum object
param: stdClass $context context object
return: bool true if the user can create attachments, false otherwise

mod_forum_get_fontawesome_icon_map()   X-Ref
Get icon mapping for font-awesome.

return: array

mod_forum_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0)   X-Ref
Callback function that determines whether an action event should be showing its item count
based on the event type and the item count.

param: calendar_event $event The calendar event.
param: int $itemcount The item count associated with the action event.
return: bool

mod_forum_core_calendar_provide_event_action(calendar_event $event,\core_calendar\action_factory $factory,int $userid = 0)   X-Ref
This function receives a calendar event and returns the action associated with it, or null if there is none.

This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
is not displayed on the block.

param: calendar_event $event
param: \core_calendar\action_factory $factory
param: int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
return: \core_calendar\local\event\entities\action_interface|null

forum_get_coursemodule_info($coursemodule)   X-Ref
Add a get_coursemodule_info function in case any forum type wants to add 'extra' information
for the course (see resource).

Given a course_module object, this function returns any "extra" information that may be needed
when printing this activity in a course listing.  See get_array_of_activities() in course/lib.php.

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

mod_forum_get_completion_active_rule_descriptions($cm)   X-Ref
Callback which returns human-readable strings describing the active completion custom rules for the module instance.

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

forum_post_is_visible_privately($post, $cm)   X-Ref
Check whether the forum post is a private reply visible to this user.

param: stdClass    $post   The post to check.
param: cm_info     $cm     The context module instance.
return: bool                Whether the post is visible in terms of private reply configuration.

forum_user_can_reply_privately(\context_module $context, \stdClass $parent)   X-Ref
Check whether the user can reply privately to the parent post.

param: \context_module $context
param: \stdClass   $parent
return: bool

mod_forum_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $forum)   X-Ref
This function calculates the minimum and maximum cutoff values for the timestart of
the given event.

It will return an array with two values, the first being the minimum cutoff value and
the second being the maximum cutoff value. Either or both values can be null, which
indicates there is no minimum or maximum, respectively.

If a cutoff is required then the function must return an array containing the cutoff
timestamp and error string to display to the user if the cutoff value is violated.

A minimum and maximum cutoff return value will look like:
[
[1505704373, 'The date must be after this date'],
[1506741172, 'The date must be before this date']
]

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

mod_forum_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $forum)   X-Ref
This function will update the forum module according to the
event that has been modified.

It will set the timeclose value of the forum instance
according to the type of event provided.

param: \calendar_event $event
param: stdClass $forum The module instance to get the range from

mod_forum_get_discussion_summaries(\mod_forum\local\entities\forum $forum, stdClass $user, ?int $groupid, ?int $sortorder,?int $pageno = 0, ?int $pagesize = 0)   X-Ref
Fetch the data used to display the discussions on the current page.

param: \mod_forum\local\entities\forum  $forum The forum entity
param: stdClass                         $user The user to render for
param: int[]|null                       $groupid The group to render
param: int|null                         $sortorder The sort order to use when selecting the discussions in the list
param: int|null                         $pageno The zero-indexed page number to use
param: int|null                         $pagesize The number of discussions to show on the page
return: array                            The data to use for display

mod_forum_count_all_discussions(\mod_forum\local\entities\forum $forum, stdClass $user, ?int $groupid)   X-Ref
Get a count of all discussions in a forum.

param: \mod_forum\local\entities\forum  $forum The forum entity
param: stdClass                         $user The user to render for
param: int                              $groupid The group to render
return: int                              The number of discussions in a forum

mod_forum_get_groups_from_groupid(\mod_forum\local\entities\forum $forum, stdClass $user, ?int $groupid)   X-Ref
Get the list of groups to show based on the current user and requested groupid.

param: \mod_forum\local\entities\forum  $forum The forum entity
param: stdClass                         $user The user viewing
param: int                              $groupid The groupid requested
return: array                            The list of groups to show

mod_forum_user_preferences()   X-Ref
Return a list of all the user preferences used by mod_forum.

return: array

forum_grading_areas_list()   X-Ref
Lists all gradable areas for the advanced grading methods gramework.

return: array('string'=>'string') An array with area names as keys and descriptions as values

forum_refresh_events(int $courseid, stdClass $instance, stdClass $cm)   X-Ref
This callback will check the provided instance of this module
and make sure there are up-to-date events created for it.

param: int $courseid Not used.
param: stdClass $instance Forum module instance.
param: stdClass $cm Course module object.