Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Static Public Member Functions | Public Attributes | Static Protected Member Functions | List of all members
tool_monitor\subscription_manager Class Reference

Class to manage subscriptions. More...

Static Public Member Functions

static activate_subscriptions (array $ids)
 Activates a group of subscriptions based on an input array of ids. More...
 
static count_rule_subscriptions ($ruleid)
 Get count of subscriptions for a given rule. More...
 
static count_user_subscriptions ($userid=0)
 Get count of subscriptions for a given user. More...
 
static count_user_subscriptions_for_course ($courseid, $userid=0)
 Get count of subscriptions for a given user in a given course. More...
 
static create_subscription ($ruleid, $courseid, $cmid, $userid=0)
 Subscribe a user to a given rule. More...
 
static deactivate_subscriptions (array $ids)
 Deactivates a group of subscriptions based on an input array of ids. More...
 
static delete_cm_subscriptions ($cmid)
 Delete all subscriptions for a course module. More...
 
static delete_stale_subscriptions ($userid=0)
 Deletes subscriptions which have been inactive for a period of time. More...
 
static delete_subscription ($subscriptionorid, $checkuser=true)
 Delete a subscription. More...
 
static delete_user_subscriptions ($userid)
 Delete all subscriptions for a user. More...
 
static event_has_subscriptions ($eventname, $courseid)
 Returns true if an event in a particular course has a subscription. More...
 
static get_subscription ($subscriptionorid)
 Get a subscription instance for an given subscription id. More...
 
static get_subscriptions_by_event (\stdClass $event)
 Return a list of subscriptions for a given event. More...
 
static get_user_subscriptions ($limitfrom=0, $limitto=0, $userid=0, $order='s.courseid ASC, r.name')
 Get an array of subscriptions for a given user. More...
 
static get_user_subscriptions_for_course ($courseid, $limitfrom=0, $limitto=0, $userid=0, $order='s.timecreated DESC')
 Get an array of subscriptions for a given user in a given course. More...
 
static remove_all_subscriptions_for_rule ($ruleid, $coursecontext=null)
 Delete all subscribers for a given rule. More...
 
static remove_all_subscriptions_in_course ($coursecontext)
 Delete all subscriptions in a course. More...
 
static subscription_is_active (subscription $subscription)
 Check whether a subscription is active. More...
 

Public Attributes

const INACTIVE_SUBSCRIPTION_LIFESPAN_IN_DAYS = 30
 @const Period of time, in days, after which an inactive subscription will be removed completely.
 

Static Protected Member Functions

static get_instances ($arr)
 Helper method to convert db records to instances. More...
 
static get_subscription_join_rule_sql ($count=false)
 Return sql to join rule and subscription table. More...
 

Detailed Description

Class to manage subscriptions.

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

Member Function Documentation

◆ activate_subscriptions()

static tool_monitor\subscription_manager::activate_subscriptions ( array  $ids)
static

Activates a group of subscriptions based on an input array of ids.

Since
3.2.0
Parameters
array$idsof subscription ids.
Return values
booltrue if the operation was successful, false otherwise.

◆ count_rule_subscriptions()

static tool_monitor\subscription_manager::count_rule_subscriptions (   $ruleid)
static

Get count of subscriptions for a given rule.

Parameters
int$ruleidrule id of the subscription.
Return values
intnumber of subscriptions

◆ count_user_subscriptions()

static tool_monitor\subscription_manager::count_user_subscriptions (   $userid = 0)
static

Get count of subscriptions for a given user.

Parameters
int$useridId of the user for which the subscription needs to be fetched. Defaults to $USER;
Return values
intnumber of subscriptions

◆ count_user_subscriptions_for_course()

static tool_monitor\subscription_manager::count_user_subscriptions_for_course (   $courseid,
  $userid = 0 
)
static

Get count of subscriptions for a given user in a given course.

Parameters
int$courseidcourse id.
int$useridId of the user for which the subscription needs to be fetched. Defaults to $USER;
Return values
intnumber of subscriptions

◆ create_subscription()

static tool_monitor\subscription_manager::create_subscription (   $ruleid,
  $courseid,
  $cmid,
  $userid = 0 
)
static

Subscribe a user to a given rule.

Parameters
int$ruleidRule id.
int$courseidCourse id.
int$cmidCourse module id.
int$useridUser who is subscribing, defaults to $USER.
Return values
bool|intreturns id of the created subscription.

◆ deactivate_subscriptions()

static tool_monitor\subscription_manager::deactivate_subscriptions ( array  $ids)
static

Deactivates a group of subscriptions based on an input array of ids.

Since
3.2.0
Parameters
array$idsof subscription ids.
Return values
booltrue if the operation was successful, false otherwise.

◆ delete_cm_subscriptions()

static tool_monitor\subscription_manager::delete_cm_subscriptions (   $cmid)
static

Delete all subscriptions for a course module.

Parameters
int$cmidcm id.
Return values
mixed

◆ delete_stale_subscriptions()

static tool_monitor\subscription_manager::delete_stale_subscriptions (   $userid = 0)
static

Deletes subscriptions which have been inactive for a period of time.

Since
3.2.0
Parameters
int$useridif provided, only this user's stale subscriptions will be deleted.
Return values
booltrue if the operation was successful, false otherwise.

◆ delete_subscription()

static tool_monitor\subscription_manager::delete_subscription (   $subscriptionorid,
  $checkuser = true 
)
static

Delete a subscription.

Parameters
subscription | int$subscriptionoridan instance of subscription class or id.
bool$checkuserCheck if the subscription belongs to current user before deleting.
Return values
bool
Exceptions
coding_exceptionif $checkuser is true and the subscription doesn't belong to the current user.

◆ delete_user_subscriptions()

static tool_monitor\subscription_manager::delete_user_subscriptions (   $userid)
static

Delete all subscriptions for a user.

Parameters
int$useriduser id.
Return values
mixed

◆ event_has_subscriptions()

static tool_monitor\subscription_manager::event_has_subscriptions (   $eventname,
  $courseid 
)
static

Returns true if an event in a particular course has a subscription.

Parameters
string$eventnamethe name of the event
int$courseidthe course id
Return values
boolreturns true if the event has subscriptions in a given course, false otherwise.

◆ get_instances()

static tool_monitor\subscription_manager::get_instances (   $arr)
staticprotected

Helper method to convert db records to instances.

Parameters
array$arrof subscriptions.
Return values
arrayof subscriptions as instances.

◆ get_subscription()

static tool_monitor\subscription_manager::get_subscription (   $subscriptionorid)
static

Get a subscription instance for an given subscription id.

Parameters
subscription | int$subscriptionoridan instance of subscription class or id.
Return values
subscriptionreturns a instance of subscription class.

◆ get_subscription_join_rule_sql()

static tool_monitor\subscription_manager::get_subscription_join_rule_sql (   $count = false)
staticprotected

Return sql to join rule and subscription table.

Parameters
bool$countWeather if this is a count query or not.
Return values
stringthe sql.

◆ get_subscriptions_by_event()

static tool_monitor\subscription_manager::get_subscriptions_by_event ( \stdClass  $event)
static

Return a list of subscriptions for a given event.

Parameters
stdClass$eventthe event object.
Return values
array

◆ get_user_subscriptions()

static tool_monitor\subscription_manager::get_user_subscriptions (   $limitfrom = 0,
  $limitto = 0,
  $userid = 0,
  $order = 's.courseid ASC,
r.name'   
)
static

Get an array of subscriptions for a given user.

Parameters
int$limitfromLimit from which to fetch rules.
int$limittoLimit to which rules need to be fetched.
int$useridId of the user for which the subscription needs to be fetched. Defaults to $USER;
string$orderOrder to sort the subscriptions.
Return values
arraylist of subscriptions

◆ get_user_subscriptions_for_course()

static tool_monitor\subscription_manager::get_user_subscriptions_for_course (   $courseid,
  $limitfrom = 0,
  $limitto = 0,
  $userid = 0,
  $order = 's.timecreated DESC' 
)
static

Get an array of subscriptions for a given user in a given course.

Parameters
int$courseidcourse id.
int$limitfromLimit from which to fetch rules.
int$limittoLimit to which rules need to be fetched.
int$useridId of the user for which the subscription needs to be fetched. Defaults to $USER;
string$orderOrder to sort the subscriptions.
Return values
arraylist of subscriptions

◆ remove_all_subscriptions_for_rule()

static tool_monitor\subscription_manager::remove_all_subscriptions_for_rule (   $ruleid,
  $coursecontext = null 
)
static

Delete all subscribers for a given rule.

Parameters
int$ruleidrule id.
context | null$coursecontextthe context of the course - this is passed when we can not get the context via context_course as the course has been deleted.
Return values
bool

◆ remove_all_subscriptions_in_course()

static tool_monitor\subscription_manager::remove_all_subscriptions_in_course (   $coursecontext)
static

Delete all subscriptions in a course.

This is called after a course was deleted, context no longer exists but we kept the object

Parameters
context_course$coursecontextthe context of the course

◆ subscription_is_active()

static tool_monitor\subscription_manager::subscription_is_active ( subscription  $subscription)
static

Check whether a subscription is active.

Since
3.2.0
Parameters
tool_monitor::subscription$subscriptioninstance.
Return values
booltrue if the subscription is active, false otherwise.

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