Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

File Size: 274 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

check_subscriptions:: (7 methods):
  get_name()
  execute()
  is_user_setup()
  user_can_access_course()
  get_subscription_from_rowdata()
  get_course_from_rowdata()
  get_user_from_rowdata()


Class: check_subscriptions  - X-Ref

Simple task class responsible for activating, deactivating and removing subscriptions.

Activation/deactivation is managed by looking at the same access rules used to determine whether a user can
subscribe to the rule in the first place.

Removal occurs when a subscription has been inactive for a period of time exceeding the lifespan, as set by
subscription_manager::get_inactive_subscription_lifespan().

I.e.
- Activation:   If a user can subscribe currently, then an existing subscription should be made active.
- Deactivation: If a user cannot subscribe currently, then an existing subscription should be made inactive.
- Removal:      If a user has a subscription that has been inactive for longer than the prescribed period, then
delete the subscription entirely.

get_name()   X-Ref
Get a descriptive name for this task.

return: string name of the task.

execute()   X-Ref
Checks all course-level rule subscriptions and activates/deactivates based on current course access.

The ordering of checks within the task is important for optimisation purposes. The aim is to be able to make a decision
about whether to activate/deactivate each subscription without making unnecessary checks. The ordering roughly follows the
context model, starting with system and user checks and moving down to course and course-module only when necessary.

For example, if the user is suspended, then any active subscription is made inactive right away. I.e. there is no need to
check site-level, course-level or course-module-level permissions. Likewise, if a subscriptions is site-level, there is no
need to check course-level and course-module-level permissions.

The task performs the following checks, in this order:
1. Check for a suspended user, breaking if suspended.
2. Check for an incomplete (not set up) user, breaking if not fully set up.
3. Check for the required capability in the relevant context, breaking if the capability is not found.
4. Check whether the subscription is site-context, breaking if true.
5. Check whether the user has course access, breaking only if the subscription is not also course-module-level.
6. Check whether the user has course-module access.


is_user_setup($user)   X-Ref
Determines whether a user is fully set up, using cached results where possible.

param: \stdClass $user the user record.
return: bool true if the user is fully set up, false otherwise.

user_can_access_course($user, $course, $capability)   X-Ref
Determines a user's access to a course with a given capability, using cached results where possible.

param: \stdClass $user the user record.
param: \stdClass $course the course record.
param: string $capability the capability to check.
return: bool true if the user can access the course with the specified capability, false otherwise.

get_subscription_from_rowdata($rowdata)   X-Ref
Returns a partial subscription record, created from properties of the supplied recordset row object.
Intended to return a minimal record for specific use within this class and in subsequent access control calls only.

param: \stdClass $rowdata the row object.
return: \stdClass a partial subscription record.

get_course_from_rowdata($rowdata)   X-Ref
Returns a partial course record, created from properties of the supplied recordset row object.
Intended to return a minimal record for specific use within this class and in subsequent access control calls only.

param: \stdClass $rowdata the row object.
return: \stdClass a partial course record.

get_user_from_rowdata($rowdata)   X-Ref
Returns a partial user record, created from properties of the supplied recordset row object.
Intended to return a minimal record for specific use within this class and in subsequent access control calls only.

param: \stdClass $rowdata the row object.
return: \stdClass a partial user record.