This commit is contained in:
Jun Pataleta 2024-03-08 08:00:41 +08:00
commit 3278ce7aba
No known key found for this signature in database
GPG key ID: F83510526D99E2C7
1147 changed files with 2621 additions and 2617 deletions

View file

@ -206,7 +206,7 @@ class api {
* @param int $limitnum
* @return array
*/
public static function message_search_users(int $userid, string $search, int $limitfrom = 0, int $limitnum = 20) : array {
public static function message_search_users(int $userid, string $search, int $limitfrom = 0, int $limitnum = 20): array {
global $CFG, $DB;
// Check if messaging is enabled.
@ -395,7 +395,7 @@ class api {
* @throws \coding_exception
* @throws \dml_exception
*/
protected static function get_linked_conversation_extra_fields(array $conversations) : array {
protected static function get_linked_conversation_extra_fields(array $conversations): array {
global $DB, $PAGE;
$renderer = $PAGE->get_renderer('core');
@ -801,7 +801,7 @@ class api {
* @throws \dml_exception
*/
public static function get_conversations_between_users(int $userid1, int $userid2,
int $limitfrom = 0, int $limitnum = 20) : array {
int $limitfrom = 0, int $limitnum = 20): array {
global $DB;
@ -968,7 +968,7 @@ class api {
* @return favourite the favourite object.
* @throws \moodle_exception if the user or conversation don't exist.
*/
public static function set_favourite_conversation(int $conversationid, int $userid) : favourite {
public static function set_favourite_conversation(int $conversationid, int $userid): favourite {
global $DB;
if (!self::is_user_in_conversation($userid, $conversationid)) {
@ -1062,7 +1062,7 @@ class api {
* @param int $userid The user id
* @return array
*/
public static function count_contacts(int $userid) : int {
public static function count_contacts(int $userid): int {
global $DB;
$sql = "SELECT COUNT(id)
@ -1105,7 +1105,7 @@ class api {
* @return array of messages
*/
public static function get_conversation_messages(int $userid, int $convid, int $limitfrom = 0, int $limitnum = 0,
string $sort = 'timecreated ASC', int $timefrom = 0, int $timeto = 0) : array {
string $sort = 'timecreated ASC', int $timefrom = 0, int $timeto = 0): array {
if (!empty($timefrom)) {
// Check the cache to see if we even need to do a DB query.
@ -1168,7 +1168,7 @@ class api {
* @param int $conversationid The id of the conversation
* @return bool Returns true if a user can delete the conversation, false otherwise.
*/
public static function can_delete_conversation(int $userid, int $conversationid = null) : bool {
public static function can_delete_conversation(int $userid, int $conversationid = null): bool {
global $USER;
if (is_null($conversationid)) {
@ -1280,7 +1280,7 @@ class api {
* @return bool true if user is permitted, false otherwise
* @since 3.6
*/
public static function can_mark_all_messages_as_read(int $userid, int $conversationid) : bool {
public static function can_mark_all_messages_as_read(int $userid, int $conversationid): bool {
global $USER;
$systemcontext = \context_system::instance();
@ -1307,7 +1307,7 @@ class api {
* @param int $userid The user whose conversations should be counted.
* @return array the array of conversations counts, indexed by type.
*/
public static function get_conversation_counts(int $userid) : array {
public static function get_conversation_counts(int $userid): array {
global $DB;
self::lazy_create_self_conversation($userid);
@ -1550,7 +1550,7 @@ class api {
* the user is still able to send a message.
* @return bool true if user is permitted, false otherwise.
*/
public static function can_send_message(int $recipientid, int $senderid, bool $evenifblocked = false) : bool {
public static function can_send_message(int $recipientid, int $senderid, bool $evenifblocked = false): bool {
$systemcontext = \context_system::instance();
if (!has_capability('moodle/site:sendmessage', $systemcontext, $senderid)) {
@ -1574,7 +1574,7 @@ class api {
* @return bool true if the user can send a message to the conversation, false otherwise.
* @throws \moodle_exception
*/
public static function can_send_message_to_conversation(int $userid, int $conversationid) : bool {
public static function can_send_message_to_conversation(int $userid, int $conversationid): bool {
global $DB;
$systemcontext = \context_system::instance();
@ -1621,7 +1621,7 @@ class api {
* @throws \moodle_exception if the user is not permitted to send a message to the conversation.
*/
public static function send_message_to_conversation(int $userid, int $conversationid, string $message,
int $format) : \stdClass {
int $format): \stdClass {
global $DB, $PAGE;
if (!self::can_send_message_to_conversation($userid, $conversationid)) {
@ -1712,7 +1712,7 @@ class api {
* @param int $userid The user identifier.
* @return int The default messaging preference.
*/
public static function get_user_privacy_messaging_preference(int $userid) : int {
public static function get_user_privacy_messaging_preference(int $userid): int {
global $CFG, $USER;
// When $CFG->messagingallusers is enabled, default value for the messaging preference will be "Anyone on the site";
@ -2165,7 +2165,7 @@ class api {
* @param \context $context The context they are creating the conversation from, most likely course context
* @return bool
*/
public static function can_create_group_conversation(int $userid, \context $context) : bool {
public static function can_create_group_conversation(int $userid, \context $context): bool {
global $CFG;
// If we can't message at all, then we can't create a conversation.
@ -2184,7 +2184,7 @@ class api {
* @param int $requesteduserid The id of the user being requested
* @return bool
*/
public static function can_create_contact(int $userid, int $requesteduserid) : bool {
public static function can_create_contact(int $userid, int $requesteduserid): bool {
global $CFG;
// If we can't message at all, then we can't create a contact.
@ -2208,7 +2208,7 @@ class api {
* @param int $requesteduserid The id of the user being requested
* @return \stdClass the request
*/
public static function create_contact_request(int $userid, int $requesteduserid) : \stdClass {
public static function create_contact_request(int $userid, int $requesteduserid): \stdClass {
global $DB, $PAGE, $SITE;
$request = new \stdClass();
@ -2309,7 +2309,7 @@ class api {
* @param int $limitnum
* @return array The list of contact requests
*/
public static function get_contact_requests(int $userid, int $limitfrom = 0, int $limitnum = 0) : array {
public static function get_contact_requests(int $userid, int $limitfrom = 0, int $limitnum = 0): array {
global $DB;
$sql = "SELECT mcr.userid
@ -2333,7 +2333,7 @@ class api {
* @param int $userid The ID of the user we want to return the number of received contact requests for
* @return int The count
*/
public static function get_received_contact_requests_count(int $userid) : int {
public static function get_received_contact_requests_count(int $userid): int {
global $DB;
$sql = "SELECT COUNT(mcr.id)
FROM {message_contact_requests} mcr
@ -2452,7 +2452,7 @@ class api {
* @param int $contactid The id of the other user
* @return bool Returns true if they are a contact, false otherwise
*/
public static function is_contact(int $userid, int $contactid) : bool {
public static function is_contact(int $userid, int $contactid): bool {
global $DB;
$sql = "SELECT id
@ -2486,7 +2486,7 @@ class api {
* @param int $blockeduserid
* @return bool Returns true if they are a blocked, false otherwise
*/
public static function is_blocked(int $userid, int $blockeduserid) : bool {
public static function is_blocked(int $userid, int $blockeduserid): bool {
global $DB;
return $DB->record_exists('message_users_blocked', ['userid' => $userid, 'blockeduserid' => $blockeduserid]);
@ -2499,7 +2499,7 @@ class api {
* @param int $requesteduserid The id of the user being requested
* @return \stdClass[]
*/
public static function get_contact_requests_between_users(int $userid, int $requesteduserid) : array {
public static function get_contact_requests_between_users(int $userid, int $requesteduserid): array {
global $DB;
$sql = "SELECT *
@ -2516,7 +2516,7 @@ class api {
* @param int $requesteduserid The id of the user being requested
* @return bool Returns true if a contact request exists, false otherwise
*/
public static function does_contact_request_exist(int $userid, int $requesteduserid) : bool {
public static function does_contact_request_exist(int $userid, int $requesteduserid): bool {
global $DB;
$sql = "SELECT id
@ -2533,7 +2533,7 @@ class api {
* @param int $conversationid The id of the conversation
* @return bool Returns true if a contact request exists, false otherwise
*/
public static function is_user_in_conversation(int $userid, int $conversationid) : bool {
public static function is_user_in_conversation(int $userid, int $conversationid): bool {
global $DB;
return $DB->record_exists('message_conversation_members', ['conversationid' => $conversationid,
@ -2549,7 +2549,7 @@ class api {
* the user is still able to send a message.
* @return bool true if recipient hasn't blocked sender and sender can contact to recipient, false otherwise.
*/
protected static function can_contact_user(int $recipientid, int $senderid, bool $evenifblocked = false) : bool {
protected static function can_contact_user(int $recipientid, int $senderid, bool $evenifblocked = false): bool {
if (has_capability('moodle/site:messageanyuser', \context_system::instance(), $senderid) ||
$recipientid == $senderid) {
// The sender has the ability to contact any user across the entire site or themselves.
@ -2687,7 +2687,7 @@ class api {
* @return int Number of conversation members.
* @throws \dml_exception
*/
public static function count_conversation_members(int $convid) : int {
public static function count_conversation_members(int $convid): int {
global $DB;
return $DB->count_records('message_conversation_members', ['conversationid' => $convid]);
@ -2702,7 +2702,7 @@ class api {
* @param int $contextid The id of the context.
* @return bool Returns if a conversation area exists and is enabled, false otherwise
*/
public static function is_conversation_area_enabled(string $component, string $itemtype, int $itemid, int $contextid) : bool {
public static function is_conversation_area_enabled(string $component, string $itemtype, int $itemid, int $contextid): bool {
global $DB;
return $DB->record_exists('message_conversations',
@ -2802,7 +2802,7 @@ class api {
*/
public static function get_conversation_members(int $userid, int $conversationid, bool $includecontactrequests = false,
bool $includeprivacyinfo = false, int $limitfrom = 0,
int $limitnum = 0) : array {
int $limitnum = 0): array {
global $DB;
if ($members = $DB->get_records('message_conversation_members', ['conversationid' => $conversationid],
@ -2822,7 +2822,7 @@ class api {
* @param int $userid the id of the user whose conversations we'll check.
* @return array the unread counts for each conversation, indexed by type.
*/
public static function get_unread_conversation_counts(int $userid) : array {
public static function get_unread_conversation_counts(int $userid): array {
global $DB;
// Get all conversations the user is in, and check unread.
@ -2877,7 +2877,7 @@ class api {
* @param int $userid The id of the user
* @param int $conversationid The id of the conversation
*/
public static function mute_conversation(int $userid, int $conversationid) : void {
public static function mute_conversation(int $userid, int $conversationid): void {
global $DB;
$mutedconversation = new \stdClass();
@ -2895,7 +2895,7 @@ class api {
* @param int $userid The id of the user
* @param int $conversationid The id of the conversation
*/
public static function unmute_conversation(int $userid, int $conversationid) : void {
public static function unmute_conversation(int $userid, int $conversationid): void {
global $DB;
$DB->delete_records('message_conversation_actions',
@ -2914,7 +2914,7 @@ class api {
* @param int $conversationid The id of the conversation
* @return bool Whether or not the conversation is muted or not
*/
public static function is_conversation_muted(int $userid, int $conversationid) : bool {
public static function is_conversation_muted(int $userid, int $conversationid): bool {
global $DB;
return $DB->record_exists('message_conversation_actions',
@ -2964,7 +2964,7 @@ class api {
* @param int $messageid The message id
* @return bool Returns true if a user can delete the message for all users, false otherwise.
*/
public static function can_delete_message_for_all_users(int $userid, int $messageid) : bool {
public static function can_delete_message_for_all_users(int $userid, int $messageid): bool {
global $DB;
$sql = "SELECT mc.id, mc.contextid
@ -3018,7 +3018,7 @@ class api {
*
* @param int $userid the user to whom the conversation belongs.
*/
protected static function lazy_create_self_conversation(int $userid) : void {
protected static function lazy_create_self_conversation(int $userid): void {
global $DB;
// Check if the self-conversation for this user exists.
// If not, create and star it for the user.

View file

@ -59,7 +59,7 @@ class helper {
*/
public static function get_conversation_messages(int $userid, int $convid, int $timedeleted = 0, int $limitfrom = 0,
int $limitnum = 0, string $sort = 'timecreated ASC', int $timefrom = 0,
int $timeto = 0) : array {
int $timeto = 0): array {
global $DB;
$sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml,
@ -124,7 +124,7 @@ class helper {
* @param array $messages The formated array messages.
* @return array A conversation array with the messages and the involved members.
*/
public static function format_conversation_messages(int $userid, int $convid, array $messages) : array {
public static function format_conversation_messages(int $userid, int $convid, array $messages): array {
global $USER;
// Create the conversation array.
@ -349,7 +349,7 @@ class helper {
* @param int $useridto
* @return array
*/
public static function messageuser_link_params(int $useridto) : array {
public static function messageuser_link_params(int $useridto): array {
global $USER;
return [
@ -422,7 +422,7 @@ class helper {
* @throws \dml_exception
*/
public static function get_member_info(int $referenceuserid, array $userids, bool $includecontactrequests = false,
bool $includeprivacyinfo = false) : array {
bool $includeprivacyinfo = false): array {
global $DB, $PAGE;
// Prevent exception being thrown when array is empty.
@ -666,7 +666,7 @@ class helper {
* subset of user_get_default_fields (optional)
* @return array the array of userdetails, if visible, or an empty array otherwise.
*/
public static function search_get_user_details(\stdClass $user, array $userfields = []) : array {
public static function search_get_user_details(\stdClass $user, array $userfields = []): array {
global $CFG, $USER;
require_once($CFG->dirroot . '/user/lib.php');
@ -697,7 +697,7 @@ class helper {
public static function prevent_unclosed_html_tags(
string $message,
bool $removebody = false
) : string {
): string {
$html = '';
if (!empty($message)) {
$doc = new DOMDocument();

View file

@ -62,7 +62,7 @@ class provider implements
* @param collection $items a reference to the collection to use to store the metadata.
* @return collection the updated collection of metadata items.
*/
public static function get_metadata(collection $items) : collection {
public static function get_metadata(collection $items): collection {
$items->add_database_table(
'messages',
[
@ -207,7 +207,7 @@ class provider implements
* @param int $userid the userid.
* @return contextlist the list of contexts containing user info for the user.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
public static function get_contexts_for_userid(int $userid): contextlist {
global $DB;
$contextlist = new contextlist();

View file

@ -204,7 +204,7 @@ abstract class base_message extends \core_search\base {
*
* @return \core_search\document_icon
*/
public function get_doc_icon(\core_search\document $doc) : \core_search\document_icon {
public function get_doc_icon(\core_search\document $doc): \core_search\document_icon {
return new \core_search\document_icon('t/message');
}

View file

@ -44,7 +44,7 @@ class helper {
* @throws \dml_exception if the conversation doesn't exist.
*/
public static function send_fake_message_to_conversation(\stdClass $userfrom, int $convid, string $message = 'Hello world!',
int $time = null) : int {
int $time = null): int {
global $DB;
$conversationrec = $DB->get_record('message_conversations', ['id' => $convid], 'id', MUST_EXIST);
$conversationid = $conversationrec->id;

View file

@ -51,7 +51,7 @@ class provider implements
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {
$collection->link_subsystem('core_user', 'privacy:metadata:usersubsystem');
$collection->add_database_table('message_airnotifier_devices', [
'userdeviceid' => 'privacy:metadata:userdeviceid',
@ -78,7 +78,7 @@ class provider implements
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
public static function get_contexts_for_userid(int $userid): contextlist {
$sql = "SELECT ctx.id
FROM {message_airnotifier_devices} mad
JOIN {user_devices} ud ON ud.id = mad.userdeviceid
@ -195,7 +195,7 @@ class provider implements
* @param int $userid The user ID
* @return array An array of records.
*/
protected static function get_records(int $userid) : array {
protected static function get_records(int $userid): array {
global $DB;
$sql = "SELECT mad.id, mad.enable, ud.appid, ud.name, ud.model, ud.platform, ud.version, ud.timecreated, ud.timemodified,
ud.pushid

View file

@ -52,7 +52,7 @@ class provider implements
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {
$messageemailmessages = [
'useridto' => 'privacy:metadata:message_email_messages:useridto',
'conversationid' => 'privacy:metadata:message_email_messages:conversationid',
@ -83,7 +83,7 @@ class provider implements
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
public static function get_contexts_for_userid(int $userid): contextlist {
$contextlist = new contextlist();
return $contextlist;
}

View file

@ -108,7 +108,7 @@ class send_email_task extends scheduled_task {
*
* @return moodle_recordset A moodle_recordset instance.
*/
private function get_unique_users() : moodle_recordset {
private function get_unique_users(): moodle_recordset {
global $DB;
$subsql = 'SELECT DISTINCT(useridto) as id
@ -128,7 +128,7 @@ class send_email_task extends scheduled_task {
* @param int $userid The ID of the user we are sending a digest to.
* @return moodle_recordset A moodle_recordset instance.
*/
private function get_conversations_for_user(int $userid) : moodle_recordset {
private function get_conversations_for_user(int $userid): moodle_recordset {
global $DB;
// We shouldn't be joining directly on the group table as group
@ -158,7 +158,7 @@ class send_email_task extends scheduled_task {
* @param int $userid
* @return moodle_recordset A moodle_recordset instance.
*/
protected function get_users_messages_for_conversation(int $conversationid, int $userid) : moodle_recordset {
protected function get_users_messages_for_conversation(int $conversationid, int $userid): moodle_recordset {
global $DB;
$userfieldsapi = \core_user\fields::for_userpic();

View file

@ -36,7 +36,7 @@ abstract class message_output {
* @see message_send()
* @param stdClass $message The event data submitted by the message provider to message_send() plus $eventdata->savedmessageid
*/
public abstract function send_message($message);
abstract public function send_message($message);
/**
* Load the config data from database to put on the config form on the messaging preferences page
@ -44,14 +44,14 @@ abstract class message_output {
* @param array $preferences Array of user preferences
* @param int $userid The user ID
*/
public abstract function load_data(&$preferences, $userid);
abstract public function load_data(&$preferences, $userid);
/**
* Create necessary fields in the config form on the messaging preferences page
*
* @param array $preferences An array of user preferences
*/
public abstract function config_form($preferences);
abstract public function config_form($preferences);
/**
* Parse the submitted form and save data into an array of user preferences
@ -59,7 +59,7 @@ abstract class message_output {
* @param stdClass $form preferences form class
* @param array $preferences preferences array
*/
public abstract function process_form($form, &$preferences);
abstract public function process_form($form, &$preferences);
/**
* Are the message processor's system settings configured?

View file

@ -40,7 +40,7 @@ class provider implements \core_privacy\local\metadata\null_provider {
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}