Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mod_forum\subscriptions Class Reference

Forum subscription manager. More...

Static Public Member Functions

static fetch_discussion_subscription ($forumid, $userid=null)
 Retrieve the discussion subscription data for the specified userid and forum.
 
static fetch_subscribed_users ($forum, $groupid=0, $context=null, $fields=null, $includediscussionsubscriptions=false)
 Returns a list of user objects who are subscribed to this forum.
 
static fetch_subscription_cache ($forumid, $userid)
 Fetch the forum subscription data for the specified userid and forum.
 
static fill_discussion_subscription_cache ($forumid, $userid=null)
 Fill the discussion subscription data for the specified userid and forum.
 
static fill_subscription_cache ($forumid, $userid=null)
 Fill the forum subscription data for the specified userid and forum.
 
static fill_subscription_cache_for_course ($courseid, $userid)
 Fill the forum subscription data for all forums that the specified userid can subscribe to in the specified course.
 
static get_potential_subscribers ($context, $groupid, $fields, $sort='')
 Get the list of potential subscribers to a forum.
 
static get_subscription_mode ($forum)
 Returns the current subscription mode for the forum.
 
static get_unsubscribable_forums ()
 Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from.
 
static get_user_default_subscription ($forum, $context, $cm, ?int $discussionid)
 Gets the default subscription value for the logged in user.
 
static is_forcesubscribed ($forum)
 Helper to determine whether a forum has it's subscription mode set to forced subscription.
 
static is_subscribable ($forum)
 Helper to determine whether the specified forum can be subscribed to.
 
static is_subscribed ($userid, $forum, $discussionid=null, $cm=null)
 Whether a user is subscribed to this forum, or a discussion within the forum.
 
static reset_discussion_cache ()
 Reset the discussion cache.
 
static reset_forum_cache ()
 Reset the forum cache.
 
static set_subscription_mode ($forumid, $status=1)
 Set the forum subscription mode.
 
static subscribe_user ($userid, $forum, $context=null, $userrequest=false)
 Adds user to the subscriber list.
 
static subscribe_user_to_discussion ($userid, $discussion, $context=null)
 Subscribes the user to the specified discussion.
 
static subscription_disabled ($forum)
 Helper to determine whether a forum has it's subscription mode set to disabled.
 
static unsubscribe_user ($userid, $forum, $context=null, $userrequest=false)
 Removes user from the subscriber list.
 
static unsubscribe_user_from_discussion ($userid, $discussion, $context=null)
 Unsubscribes the user from the specified discussion.
 

Public Attributes

int const FORUM_DISCUSSION_UNSUBSCRIBED = -1
 The status value for an unsubscribed discussion.
 

Static Protected Member Functions

static add_to_discussion_cache ($forumid, $userid, $discussion, $preference)
 Add the specified discussion and user preference to the discussion subscription cache.
 
static is_subscribed_to_forum ($userid, $forum)
 Whether a user is subscribed to this forum.
 

Static Protected Attributes

static bool[] $discussionfetchedforums = array()
 The list of forums which have been wholly retrieved for the forum discussion subscription cache.
 
static bool[] $fetchedforums = array()
 The list of forums which have been wholly retrieved for the forum subscription cache.
 
static array[] $forumcache = array()
 The subscription cache for forums.
 
static array[] $forumdiscussioncache = array()
 The subscription cache for forum discussions.
 

Detailed Description

Forum subscription manager.

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

Member Function Documentation

◆ add_to_discussion_cache()

static mod_forum\subscriptions::add_to_discussion_cache ( $forumid,
$userid,
$discussion,
$preference )
staticprotected

Add the specified discussion and user preference to the discussion subscription cache.

Parameters
int$forumidThe ID of the forum that this preference belongs to
int$useridThe ID of the user that this preference belongs to
int$discussionThe ID of the discussion that this preference relates to
int$preferenceThe preference to store

◆ fetch_discussion_subscription()

static mod_forum\subscriptions::fetch_discussion_subscription ( $forumid,
$userid = null )
static

Retrieve the discussion subscription data for the specified userid and forum.

This is returned as an array of discussions for that forum which contain the preference in a stdClass.

Parameters
int$forumidThe forum to retrieve a cache for
int$useridThe user ID
Return values
arrayof stdClass objects with one per discussion in the forum.

◆ fetch_subscribed_users()

static mod_forum\subscriptions::fetch_subscribed_users ( $forum,
$groupid = 0,
$context = null,
$fields = null,
$includediscussionsubscriptions = false )
static

Returns a list of user objects who are subscribed to this forum.

Parameters
stdClass$forumThe forum record.
int$groupidThe group id if restricting subscriptions to a group of users, or 0 for all.
context_module$contextthe forum context, to save re-fetching it where possible.
string$fieldsrequested user fields (with "u." table prefix).
boolean$includediscussionsubscriptionsWhether to take discussion subscriptions and unsubscriptions into consideration.
Return values
arraylist of users.

◆ fetch_subscription_cache()

static mod_forum\subscriptions::fetch_subscription_cache ( $forumid,
$userid )
static

Fetch the forum subscription data for the specified userid and forum.

Parameters
int$forumidThe forum to retrieve a cache for
int$useridThe user ID
Return values
boolean

◆ fill_discussion_subscription_cache()

static mod_forum\subscriptions::fill_discussion_subscription_cache ( $forumid,
$userid = null )
static

Fill the discussion subscription data for the specified userid and forum.

If the userid is not specified, then all discussion subscription data for that forum is fetched in a single query and used for subsequent lookups without requiring further database queries.

Parameters
int$forumidThe forum to retrieve a cache for
int$useridThe user ID
Return values
void

◆ fill_subscription_cache()

static mod_forum\subscriptions::fill_subscription_cache ( $forumid,
$userid = null )
static

Fill the forum subscription data for the specified userid and forum.

If the userid is not specified, then all subscription data for that forum is fetched in a single query and used for subsequent lookups without requiring further database queries.

Parameters
int$forumidThe forum to retrieve a cache for
int$useridThe user ID
Return values
void

◆ fill_subscription_cache_for_course()

static mod_forum\subscriptions::fill_subscription_cache_for_course ( $courseid,
$userid )
static

Fill the forum subscription data for all forums that the specified userid can subscribe to in the specified course.

Parameters
int$courseidThe course to retrieve a cache for
int$useridThe user ID
Return values
void

◆ get_potential_subscribers()

static mod_forum\subscriptions::get_potential_subscribers ( $context,
$groupid,
$fields,
$sort = '' )
static

Get the list of potential subscribers to a forum.

Parameters
context_module$contextthe forum context.
integer$groupidthe id of a group, or 0 for all groups.
string$fieldsthe list of fields to return for each user. As for get_users_by_capability.
string$sortsort order. As for get_users_by_capability.
Return values
arraylist of users.

◆ get_subscription_mode()

static mod_forum\subscriptions::get_subscription_mode ( $forum)
static

Returns the current subscription mode for the forum.

Parameters
stdClass$forumThe record of the forum to set
Return values
intThe forum subscription mode

◆ get_unsubscribable_forums()

static mod_forum\subscriptions::get_unsubscribable_forums ( )
static

Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from.

Return values
arrayAn array of unsubscribable forums

◆ get_user_default_subscription()

static mod_forum\subscriptions::get_user_default_subscription ( $forum,
$context,
$cm,
?int $discussionid )
static

Gets the default subscription value for the logged in user.

Parameters
stdClass$forumThe forum record
context$contextThe course context
cm_info$cmcm_info
int | null$discussionidThe discussion we are checking against
Return values
boolDefault subscription
Exceptions
coding_exception

◆ is_forcesubscribed()

static mod_forum\subscriptions::is_forcesubscribed ( $forum)
static

Helper to determine whether a forum has it's subscription mode set to forced subscription.

Parameters
stdClass$forumThe record of the forum to test
Return values
bool

◆ is_subscribable()

static mod_forum\subscriptions::is_subscribable ( $forum)
static

Helper to determine whether the specified forum can be subscribed to.

Parameters
stdClass$forumThe record of the forum to test
Return values
bool

◆ is_subscribed()

static mod_forum\subscriptions::is_subscribed ( $userid,
$forum,
$discussionid = null,
$cm = null )
static

Whether a user is subscribed to this forum, or a discussion within the forum.

If a discussion is specified, then report whether the user is subscribed to posts to this particular discussion, taking into account the forum preference.

If it is not specified then only the forum preference is considered.

Parameters
int$useridThe user ID
stdClass$forumThe record of the forum to test
int$discussionidThe ID of the discussion to check
$cmThe coursemodule record. If not supplied, this will be calculated using get_fast_modinfo instead.
Return values
boolean

◆ is_subscribed_to_forum()

static mod_forum\subscriptions::is_subscribed_to_forum ( $userid,
$forum )
staticprotected

Whether a user is subscribed to this forum.

Parameters
int$useridThe user ID
stdClass$forumThe record of the forum to test
Return values
boolean

◆ reset_discussion_cache()

static mod_forum\subscriptions::reset_discussion_cache ( )
static

Reset the discussion cache.

This cache is used to reduce the number of database queries when checking forum discussion subscription states.

◆ reset_forum_cache()

static mod_forum\subscriptions::reset_forum_cache ( )
static

Reset the forum cache.

This cache is used to reduce the number of database queries when checking forum subscription states.

◆ set_subscription_mode()

static mod_forum\subscriptions::set_subscription_mode ( $forumid,
$status = 1 )
static

Set the forum subscription mode.

By default when called without options, this is set to FORUM_FORCESUBSCRIBE.

Parameters
stdClass$forumThe record of the forum to set
int$statusThe new subscription state
Return values
bool

◆ subscribe_user()

static mod_forum\subscriptions::subscribe_user ( $userid,
$forum,
$context = null,
$userrequest = false )
static

Adds user to the subscriber list.

Parameters
int$useridThe ID of the user to subscribe
stdClass$forumThe forum record for this forum.
context_module | null$contextModule context, may be omitted if not known or if called for the current module set in page.
boolean$userrequestWhether the user requested this change themselves. This has an effect on whether discussion subscriptions are removed too.
Return values
bool|intReturns true if the user is already subscribed, or the forum_subscriptions ID if the user was successfully subscribed.

◆ subscribe_user_to_discussion()

static mod_forum\subscriptions::subscribe_user_to_discussion ( $userid,
$discussion,
$context = null )
static

Subscribes the user to the specified discussion.

Parameters
int$useridThe userid of the user being subscribed
stdClass$discussionThe discussion to subscribe to
context_module | null$contextModule context, may be omitted if not known or if called for the current module set in page.
Return values
booleanWhether a change was made

◆ subscription_disabled()

static mod_forum\subscriptions::subscription_disabled ( $forum)
static

Helper to determine whether a forum has it's subscription mode set to disabled.

Parameters
stdClass$forumThe record of the forum to test
Return values
bool

◆ unsubscribe_user()

static mod_forum\subscriptions::unsubscribe_user ( $userid,
$forum,
$context = null,
$userrequest = false )
static

Removes user from the subscriber list.

Parameters
int$useridThe ID of the user to unsubscribe
stdClass$forumThe forum record for this forum.
context_module | null$contextModule context, may be omitted if not known or if called for the current module set in page.
boolean$userrequestWhether the user requested this change themselves. This has an effect on whether discussion subscriptions are removed too.
Return values
booleanAlways returns true.

◆ unsubscribe_user_from_discussion()

static mod_forum\subscriptions::unsubscribe_user_from_discussion ( $userid,
$discussion,
$context = null )
static

Unsubscribes the user from the specified discussion.

Parameters
int$useridThe userid of the user being unsubscribed
stdClass$discussionThe discussion to unsubscribe from
context_module | null$contextModule context, may be omitted if not known or if called for the current module set in page.
Return values
booleanWhether a change was made

Member Data Documentation

◆ $discussionfetchedforums

bool [] mod_forum\subscriptions::$discussionfetchedforums = array()
staticprotected

The list of forums which have been wholly retrieved for the forum discussion subscription cache.

This allows for prior caching of an entire forum to reduce the number of DB queries in a subscription check loop.

◆ $fetchedforums

bool [] mod_forum\subscriptions::$fetchedforums = array()
staticprotected

The list of forums which have been wholly retrieved for the forum subscription cache.

This allows for prior caching of an entire forum to reduce the number of DB queries in a subscription check loop.

◆ $forumcache

array [] mod_forum\subscriptions::$forumcache = array()
staticprotected

The subscription cache for forums.

The first level key is the user ID The second level is the forum ID The Value then is bool for subscribed of not.

An array of arrays.

◆ $forumdiscussioncache

array [] mod_forum\subscriptions::$forumdiscussioncache = array()
staticprotected

The subscription cache for forum discussions.

The first level key is the user ID The second level is the forum ID The third level key is the discussion ID The value is then the users preference (int)


The documentation for this class was generated from the following file: