MDL-63915 core_message: remove use of renderable so we can nuke it

The other renderables in the same namespace are still used by
deprecated web services. Once we do the final deprecation of
those web services they will be removed - see MDL-63261.
This commit is contained in:
Mark Nelson 2018-12-05 15:10:18 +08:00
parent b1bba555be
commit ee45ecc014
2 changed files with 32 additions and 69 deletions

View file

@ -1,65 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains class used to display message search results.
*
* @package core_message
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_message\output\messagearea;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
/**
* Class used to display message search results.
*
* @package core_message
* @copyright 2016 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class message_search_results implements templatable, renderable {
/**
* @var array The list of contacts.
*/
public $contacts;
/**
* Constructor.
*
* @param array $contacts
*/
public function __construct($contacts) {
$this->contacts = $contacts;
}
public function export_for_template(\renderer_base $output) {
$data = new \stdClass();
$data->contacts = array();
foreach ($this->contacts as $contact) {
$contact = new contact($contact);
$data->contacts[] = $contact->export_for_template($output);
}
return $data;
}
}

View file

@ -1538,7 +1538,7 @@ class core_message_external extends external_api {
* @since 3.2 * @since 3.2
*/ */
public static function data_for_messagearea_search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) { public static function data_for_messagearea_search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) {
global $CFG, $PAGE, $USER; global $CFG, $USER;
// Check if messaging is enabled. // Check if messaging is enabled.
if (empty($CFG->messaging)) { if (empty($CFG->messaging)) {
@ -1567,10 +1567,38 @@ class core_message_external extends external_api {
$params['limitfrom'], $params['limitfrom'],
$params['limitnum'] $params['limitnum']
); );
$results = new \core_message\output\messagearea\message_search_results($messages);
$renderer = $PAGE->get_renderer('core_message'); $data = new \stdClass();
return $results->export_for_template($renderer); $data->contacts = [];
foreach ($messages as $message) {
$contact = new \stdClass();
$contact->userid = $message->userid;
$contact->fullname = $message->fullname;
$contact->profileimageurl = $message->profileimageurl;
$contact->profileimageurlsmall = $message->profileimageurlsmall;
$contact->messageid = $message->messageid;
$contact->ismessaging = $message->ismessaging;
$contact->sentfromcurrentuser = false;
if ($message->lastmessage) {
if ($message->userid !== $message->useridfrom) {
$contact->sentfromcurrentuser = true;
}
$contact->lastmessage = shorten_text($message->lastmessage, 60);
} else {
$contact->lastmessage = null;
}
$contact->lastmessagedate = $message->lastmessagedate;
$contact->showonlinestatus = is_null($message->isonline) ? false : true;
$contact->isonline = $message->isonline;
$contact->isblocked = $message->isblocked;
$contact->isread = $message->isread;
$contact->unreadcount = $message->unreadcount;
$contact->conversationid = $message->conversationid;
$data->contacts[] = $contact;
}
return $data;
} }
/** /**