message_service_interface
Public contract for the message_service facade.
Extensions depend ONLY on this interface — never on the core implementation. No Moodle/Core dependencies are allowed inside this contract.
Table of Contents
Methods
- email() : void
- Send an email message.
- get_conversation_id() : int
- Get or create a conversation ID for a message.
- message() : mixed
- Send a Moodle message (non-notification).
- notification() : mixed
- Send a Moodle notification.
- prepare() : mixed
- Prepare a structured message object.
- prepare_text() : array<string, mixed>
- Replace template variables in a message.
Methods
email()
Send an email message.
public
email(mixed $from, mixed $to, string $subject, string $text[, int $courseid = SITEID ][, null|array<string|int, mixed> $attachments = null ]) : void
Parameters
- $from : mixed
-
Sender descriptor (user or address)
- $to : mixed
-
Recipient descriptor (user or address)
- $subject : string
-
Email subject
- $text : string
-
Email body
- $courseid : int = SITEID
-
Course context for messaging
- $attachments : null|array<string|int, mixed> = null
-
Optional list of attachments
get_conversation_id()
Get or create a conversation ID for a message.
public
get_conversation_id(mixed $message) : int
Parameters
- $message : mixed
-
Prepared message structure
Return values
int —Conversation identifier
message()
Send a Moodle message (non-notification).
public
message(mixed $from, mixed $to, string $subject, string $text[, int $courseid = SITEID ]) : mixed
Parameters
- $from : mixed
-
Sender descriptor (user or address)
- $to : mixed
-
Recipient descriptor (user or address)
- $subject : string
-
Message subject
- $text : string
-
Message body
- $courseid : int = SITEID
-
Course context for messaging
Return values
mixed —Implementation-defined result of the send operation
notification()
Send a Moodle notification.
public
notification(mixed $from, mixed $to, string $subject, string $text[, int $courseid = SITEID ][, null|mixed $url = null ][, null|string $urlname = null ]) : mixed
Parameters
- $from : mixed
-
Sender descriptor (user or address)
- $to : mixed
-
Recipient descriptor (user or address)
- $subject : string
-
Notification subject
- $text : string
-
Notification body
- $courseid : int = SITEID
-
Course context for messaging
- $url : null|mixed = null
-
Optional URL payload
- $urlname : null|string = null
-
Optional URL label
Return values
mixed —Implementation-defined result of the send operation
prepare()
Prepare a structured message object.
public
prepare(mixed $from, mixed $to, string $subject, string $text[, int $courseid = SITEID ]) : mixed
Parameters
- $from : mixed
-
Sender descriptor (user or address)
- $to : mixed
-
Recipient descriptor (user or address)
- $subject : string
-
Message subject
- $text : string
-
Message body
- $courseid : int = SITEID
-
Course context for messaging
Return values
mixed —Prepared message structure
prepare_text()
Replace template variables in a message.
public
prepare_text(mixed $course, mixed $user) : array<string, mixed>
Parameters
- $course : mixed
-
Course reference
- $user : mixed
-
User reference
Return values
array<string, mixed> —Prepared text placeholders