MIDDAG for Moodle

authorizer_interface

Authorizer Interface.

Defines the contract for validating user permissions and login requirements, isolating Moodle's capability system from the business logic.

Table of Contents

Constants

CONTEXT_BLOCK  = 80
Context level constant for BLOCK.
CONTEXT_COURSE  = 50
Context level constant for COURSE.
CONTEXT_COURSECAT  = 40
Context level constant for COURSE CATEGORY.
CONTEXT_MODULE  = 70
Context level constant for MODULE.
CONTEXT_SYSTEM  = 10
Context level constant for SYSTEM.
CONTEXT_USER  = 30
Context level constant for USER.

Methods

authorize()  : void
Requires a specific capability, throwing an exception if not met.
can()  : bool
Checks if a user has a specific capability.
require_login()  : void
Requires the user to be logged in to the system or a specific course.

Constants

CONTEXT_COURSECAT

Context level constant for COURSE CATEGORY.

public mixed CONTEXT_COURSECAT = 40

Methods

authorize()

Requires a specific capability, throwing an exception if not met.

public authorize(string $capability[, int $contextlevel = self::CONTEXT_SYSTEM ][, int $instanceid = 0 ][, null|int $userid = null ]) : void
Parameters
$capability : string

The capability name

$contextlevel : int = self::CONTEXT_SYSTEM

The context level

$instanceid : int = 0

The instance ID

$userid : null|int = null

The user ID. Null for the current user.

Tags
throws
moodle_exception

if the user does not have the required capability

can()

Checks if a user has a specific capability.

public can(string $capability[, int $contextlevel = self::CONTEXT_SYSTEM ][, int $instanceid = 0 ][, null|int $userid = null ]) : bool
Parameters
$capability : string

The capability name (e.g., 'moodle/course:view')

$contextlevel : int = self::CONTEXT_SYSTEM

The context level (e.g., self::CONTEXT_COURSE)

$instanceid : int = 0

The instance ID corresponding to the context level (e.g., course ID). Default: 0

$userid : null|int = null

The user ID. Null for the current user.

Return values
bool

true if the user has the capability, false otherwise

require_login()

Requires the user to be logged in to the system or a specific course.

public require_login([null|int $courseid = null ][, bool $autologinguest = true ]) : void
Parameters
$courseid : null|int = null

The course ID, or null for system login

$autologinguest : bool = true

Whether guest auto-login is allowed

Tags
throws
moodle_exception

if the user is not logged in


        
On this page

Search results