From 82e0973c965a7504642906dd4291e8a4cc4367bc Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 2 Nov 2018 16:17:49 +0800 Subject: [PATCH] MDL-63850 core_message: helper now returns privacy information --- message/classes/helper.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/message/classes/helper.php b/message/classes/helper.php index 407c59b807e..36dcdc92acf 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -483,11 +483,14 @@ class helper { * @param int $referenceuserid the id of the user which check contact and blocked status. * @param array $userids * @param bool $includecontactrequests Do we want to include contact requests with this data? + * @param bool $includeprivacyinfo Do we want to include whether the user can message another, and if the user + * requires a contact. * @return array the array of objects containing member info, indexed by userid. * @throws \coding_exception * @throws \dml_exception */ - public static function get_member_info(int $referenceuserid, array $userids, bool $includecontactrequests = false) : array { + public static function get_member_info(int $referenceuserid, array $userids, bool $includecontactrequests = false, + bool $includeprivacyinfo = false) : array { global $DB, $PAGE; // Prevent exception being thrown when array is empty. @@ -531,6 +534,21 @@ class helper { $data->isdeleted = ($member->deleted) ? true : false; + $data->requirescontact = null; + $data->canmessage = null; + if ($includeprivacyinfo) { + $privacysetting = api::get_user_privacy_messaging_preference($member->id); + $data->requirescontact = $privacysetting == api::MESSAGE_PRIVACY_ONLYCONTACTS; + + $recipient = new \stdClass(); + $recipient->id = $member->id; + + $sender = new \stdClass(); + $sender->id = $referenceuserid; + + $data->canmessage = api::can_post_message($recipient, $sender); + } + $members[$data->id] = $data; }