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.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

Class to manage subscriptions.

Copyright: 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 563 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: subscription_manager  - X-Ref

Class to manage subscriptions.

create_subscription($ruleid, $courseid, $cmid, $userid = 0)   X-Ref
Subscribe a user to a given rule.

param: int $ruleid  Rule id.
param: int $courseid Course id.
param: int $cmid Course module id.
param: int $userid User who is subscribing, defaults to $USER.
return: bool|int returns id of the created subscription.

delete_subscription($subscriptionorid, $checkuser = true)   X-Ref
Delete a subscription.

param: subscription|int $subscriptionorid an instance of subscription class or id.
param: bool $checkuser Check if the subscription belongs to current user before deleting.
return: bool

delete_user_subscriptions($userid)   X-Ref
Delete all subscriptions for a user.

param: int $userid user id.
return: mixed

delete_cm_subscriptions($cmid)   X-Ref
Delete all subscriptions for a course module.

param: int $cmid cm id.
return: mixed

remove_all_subscriptions_for_rule($ruleid, $coursecontext = null)   X-Ref
Delete all subscribers for a given rule.

param: int $ruleid rule id.
param: \context|null $coursecontext the context of the course - this is passed when we
return: bool

remove_all_subscriptions_in_course($coursecontext)   X-Ref
Delete all subscriptions in a course.

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

param: \context_course $coursecontext the context of the course

get_subscription($subscriptionorid)   X-Ref
Get a subscription instance for an given subscription id.

param: subscription|int $subscriptionorid an instance of subscription class or id.
return: subscription returns a instance of subscription class.

get_user_subscriptions_for_course($courseid, $limitfrom = 0, $limitto = 0, $userid = 0,$order = 's.timecreated DESC' )   X-Ref
Get an array of subscriptions for a given user in a given course.

param: int $courseid course id.
param: int $limitfrom Limit from which to fetch rules.
param: int $limitto  Limit to which rules need to be fetched.
param: int $userid Id of the user for which the subscription needs to be fetched. Defaults to $USER;
param: string $order Order to sort the subscriptions.
return: array list of subscriptions

count_user_subscriptions_for_course($courseid, $userid = 0)   X-Ref
Get count of subscriptions for a given user in a given course.

param: int $courseid course id.
param: int $userid Id of the user for which the subscription needs to be fetched. Defaults to $USER;
return: int number of subscriptions

get_user_subscriptions($limitfrom = 0, $limitto = 0, $userid = 0,$order = 's.courseid ASC, r.name' )   X-Ref
Get an array of subscriptions for a given user.

param: int $limitfrom Limit from which to fetch rules.
param: int $limitto  Limit to which rules need to be fetched.
param: int $userid Id of the user for which the subscription needs to be fetched. Defaults to $USER;
param: string $order Order to sort the subscriptions.
return: array list of subscriptions

count_user_subscriptions($userid = 0)   X-Ref
Get count of subscriptions for a given user.

param: int $userid Id of the user for which the subscription needs to be fetched. Defaults to $USER;
return: int number of subscriptions

get_subscriptions_by_event(\stdClass $event)   X-Ref
Return a list of subscriptions for a given event.

param: \stdClass $event the event object.
return: array

get_subscription_join_rule_sql($count = false)   X-Ref
Return sql to join rule and subscription table.

param: bool $count Weather if this is a count query or not.
return: string the sql.

get_instances($arr)   X-Ref
Helper method to convert db records to instances.

param: array $arr of subscriptions.
return: array of subscriptions as instances.

count_rule_subscriptions($ruleid)   X-Ref
Get count of subscriptions for a given rule.

param: int $ruleid rule id of the subscription.
return: int number of subscriptions

event_has_subscriptions($eventname, $courseid)   X-Ref
Returns true if an event in a particular course has a subscription.

param: string $eventname the name of the event
param: int $courseid the course id
return: bool returns true if the event has subscriptions in a given course, false otherwise.

activate_subscriptions(array $ids)   X-Ref
Activates a group of subscriptions based on an input array of ids.

param: array $ids of subscription ids.
return: bool true if the operation was successful, false otherwise.

deactivate_subscriptions(array $ids)   X-Ref
Deactivates a group of subscriptions based on an input array of ids.

param: array $ids of subscription ids.
return: bool true if the operation was successful, false otherwise.

delete_stale_subscriptions($userid = 0)   X-Ref
Deletes subscriptions which have been inactive for a period of time.

param: int $userid if provided, only this user's stale subscriptions will be deleted.
return: bool true if the operation was successful, false otherwise.

subscription_is_active(subscription $subscription)   X-Ref
Check whether a subscription is active.

param: \tool_monitor\subscription $subscription instance.
return: bool true if the subscription is active, false otherwise.