diff --git a/message/externallib.php b/message/externallib.php index 84e251a60626b..a2efebbe77780 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -1990,7 +1990,7 @@ public static function get_messages_parameters() { */ public static function get_messages($useridto, $useridfrom = 0, $type = 'both', $read = true, $newestfirst = true, $limitfrom = 0, $limitnum = 0) { - global $CFG, $USER; + global $CFG, $USER, $PAGE; $warnings = array(); @@ -2088,13 +2088,26 @@ public static function get_messages($useridto, $useridfrom = 0, $type = 'both', } foreach ($messages as $mid => $message) { - // Do not return deleted messages. if (!$message->notification) { + // Do not return deleted messages. if (($useridto == $USER->id and $message->timeusertodeleted) or ($useridfrom == $USER->id and $message->timeuserfromdeleted)) { unset($messages[$mid]); continue; } + } else { + // Return iconurl for notifications. + if (!isset($output)) { + $output = $PAGE->get_renderer('core'); + } + + if (!empty($message->component) && substr($message->component, 0, 4) == 'mod_') { + $iconurl = $output->image_url('icon', $message->component); + } else { + $iconurl = $output->image_url('i/marker', 'core'); + } + + $message->iconurl = clean_param($iconurl->out(), PARAM_URL); } // We need to get the user from the query. @@ -2167,6 +2180,7 @@ public static function get_messages_returns() { 'eventtype' => new external_value(PARAM_TEXT, 'The type of notification', VALUE_OPTIONAL), 'customdata' => new external_value(PARAM_RAW, 'Custom data to be passed to the message processor. The data here is serialised using json_encode().', VALUE_OPTIONAL), + 'iconurl' => new external_value(PARAM_URL, 'URL for icon, only for notifications.', VALUE_OPTIONAL), ), 'message' ) ), diff --git a/message/tests/externallib_test.php b/message/tests/externallib_test.php index 087b27679c7d6..f7742365a0861 100644 --- a/message/tests/externallib_test.php +++ b/message/tests/externallib_test.php @@ -1292,7 +1292,7 @@ public function test_search_contacts() { * Test get_messages. */ public function test_get_messages() { - global $CFG, $DB; + global $CFG, $DB, $PAGE; $this->resetAfterTest(true); $this->preventResetByRollback(); @@ -1478,6 +1478,8 @@ public function test_get_messages() { $this->assertObjectHasAttribute('datakey', json_decode($messages['messages'][0]['customdata'])); $this->assertEquals('mod_feedback', $messages['messages'][0]['component']); $this->assertEquals('submission', $messages['messages'][0]['eventtype']); + $feedbackicon = clean_param($PAGE->get_renderer('core')->image_url('icon', 'mod_feedback')->out(), PARAM_URL); + $this->assertEquals($feedbackicon, $messages['messages'][0]['iconurl']); // Test warnings. $CFG->messaging = 0;