See Release Notes
Long Term Support Release
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Contains class used to prepare the messages for display. 19 * 20 * TODO: This file should be removed once the related web services go through final deprecation. 21 * Followup: MDL-63261 22 * 23 * @package core_message 24 * @copyright 2016 Mark Nelson <markn@moodle.com> 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 28 namespace core_message\output\messagearea; 29 30 defined('MOODLE_INTERNAL') || die(); 31 32 use core_message\api; 33 use renderable; 34 use templatable; 35 36 /** 37 * Class to prepare the messages for display. 38 * 39 * @package core_message 40 * @copyright 2016 Mark Nelson <markn@moodle.com> 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 class messages implements templatable, renderable { 44 45 /** 46 * @var array The messages. 47 */ 48 public $messages; 49 50 /** 51 * @var int The current user id. 52 */ 53 public $currentuserid; 54 55 /** 56 * @var int The other user id. 57 */ 58 public $otheruserid; 59 60 /** 61 * @var \stdClass The other user. 62 */ 63 public $otheruser; 64 65 /** 66 * Constructor. 67 * 68 * @param int $currentuserid The current user we are wanting to view messages for 69 * @param int $otheruserid The other user we are wanting to view messages for 70 * @param array $messages 71 */ 72 public function __construct($currentuserid, $otheruserid, $messages) { 73 $ufields = 'id, ' . get_all_user_name_fields(true) . ', lastaccess'; 74 75 $this->currentuserid = $currentuserid; 76 if ($otheruserid) { 77 $this->otheruserid = $otheruserid; 78 $this->otheruser = \core_user::get_user($otheruserid, $ufields, MUST_EXIST); 79 } 80 $this->messages = $messages; 81 } 82 83 public function export_for_template(\renderer_base $output) { 84 global $USER; 85 86 $data = new \stdClass(); 87 $data->iscurrentuser = $USER->id == $this->currentuserid; 88 $data->currentuserid = $this->currentuserid; 89 if ($this->otheruserid) { 90 $data->otheruserid = $this->otheruserid; 91 $data->otheruserfullname = fullname($this->otheruser); 92 } 93 $data->isonline = null; 94 if ($this->otheruserid) { 95 if (\core_message\helper::show_online_status($this->otheruser)) { 96 $data->isonline = \core_message\helper::is_online($this->otheruser->lastaccess); 97 } 98 } 99 $data->showonlinestatus = is_null($data->isonline) ? false : true; 100 101 $data->messages = array(); 102 foreach ($this->messages as $message) { 103 $message = new message($message); 104 $data->messages[] = $message->export_for_template($output); 105 } 106 107 $blockeduserid = $this->otheruserid ?? $USER->id; 108 $data->isblocked = api::is_blocked($this->currentuserid, $blockeduserid); 109 110 return $data; 111 } 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body