class message_support

internal  
 

Utility functions for Moodle messaging and emails.

Constants

CONVERSATION_TYPE_SELF

CONVERSATION_TYPE_INDIVIDUAL

Methods

static message
create_message()

Creates a new Moodle message object.

static false|int
send(message $msg)

Sends a message using Moodle's message API.

static bool
email(stdClass $to, stdClass $from, string $subject, string $html, string $text, string $attachment = '', string $name = '')

Sends an email to a user.

static stdClass
get_noreply_user()

Retrieves the Moodle no-reply user record.

static array
create_temp_attachment(stored_file $file)

Creates a temporary attachment from a stored file.

static int
get_conversation_id(message $message)

Retrieves the conversation ID for a given message.

static string
create_link(moodle_url $url, string $text)

Creates an HTML link for use in messages.

static false|stdClass
get_self_conversation(int $userid)

Retrieves the self-conversation object for a user.

static stdClass
create_conversation(int $type, array $userids)

Creates a new conversation between users.

static false|int
get_conversation_between_users(array $userids)

Retrieves the ID of a conversation between specific users.

Details

at line 45
static message create_message()

Creates a new Moodle message object.

Return Value

message

Message object

at line 57
static false|int send(message $msg)

Sends a message using Moodle's message API.

Parameters

message $msg

Message object

Return Value

false|int

Message ID or false on failure

at line 75
static bool email(stdClass $to, stdClass $from, string $subject, string $html, string $text, string $attachment = '', string $name = '')

Sends an email to a user.

Parameters

stdClass $to

Recipient user object

stdClass $from

Sender user object

string $subject

the email subject

string $html

the HTML content

string $text

the plain text content

string $attachment

path to attachment file

string $name

attachment name

Return Value

bool

True on success, false otherwise

at line 85
static stdClass get_noreply_user()

Retrieves the Moodle no-reply user record.

Return Value

stdClass

the no-reply user object

at line 97
static array create_temp_attachment(stored_file $file)

Creates a temporary attachment from a stored file.

Parameters

stored_file $file

the stored file object

Return Value

array

at line 114
static int get_conversation_id(message $message)

Retrieves the conversation ID for a given message.

Parameters

message $message

Message object

Return Value

int

the conversation ID

Creates an HTML link for use in messages.

Parameters

moodle_url $url

the destination URL

string $text

the link text

Return Value

string

the generated HTML link

at line 161
static false|stdClass get_self_conversation(int $userid)

Retrieves the self-conversation object for a user.

Parameters

int $userid

User ID

Return Value

false|stdClass

the conversation object or false

at line 174
static stdClass create_conversation(int $type, array $userids)

Creates a new conversation between users.

Parameters

int $type

the conversation type

array $userids

list of user IDs

Return Value

stdClass

the conversation object

at line 186
static false|int get_conversation_between_users(array $userids)

Retrieves the ID of a conversation between specific users.

Parameters

array $userids

list of user IDs

Return Value

false|int

the conversation ID or false if not found