Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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 a message 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 renderable;
  33  use templatable;
  34  
  35  /**
  36   * Class to prepare a message for display.
  37   *
  38   * @package   core_message
  39   * @copyright 2016 Mark Nelson <markn@moodle.com>
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class message implements templatable, renderable {
  43  
  44      /**
  45       * @var int The message id.
  46       */
  47      public $id;
  48  
  49      /**
  50       * @var int The current userid.
  51       */
  52      public $currentuserid;
  53  
  54      /**
  55       * @var int The userid to.
  56       */
  57      public $useridto;
  58  
  59      /**
  60       * @var int The userid from.
  61       */
  62      public $useridfrom;
  63  
  64      /**
  65       * @var string The message text.
  66       */
  67      public $text;
  68  
  69      /**
  70       * @var bool Are we displaying the time?
  71       */
  72      public $displayblocktime;
  73  
  74      /**
  75       * @var int The time created of the message.
  76       */
  77      public $timecreated;
  78  
  79      /**
  80       * @var int The time the message was read.
  81       */
  82      public $timeread;
  83  
  84      /**
  85       * Constructor.
  86       *
  87       * @param \stdClass $message
  88       */
  89      public function __construct($message) {
  90          $this->id = $message->id;
  91          $this->currentuserid = $message->currentuserid;
  92          $this->useridto = $message->useridto;
  93          $this->useridfrom = $message->useridfrom;
  94          $this->text = $message->text;
  95          $this->displayblocktime = $message->displayblocktime;
  96          $this->timecreated = $message->timecreated;
  97          $this->timeread = $message->timeread;
  98      }
  99  
 100      public function export_for_template(\renderer_base $output) {
 101          $message = new \stdClass();
 102          $message->id = $this->id;
 103          $message->useridto = $this->useridto;
 104          $message->useridfrom = $this->useridfrom;
 105          $message->text = $this->text;
 106          $message->displayblocktime = $this->displayblocktime;
 107          $message->blocktime = userdate($this->timecreated, get_string('strftimedaydate'));
 108          $message->position = 'left';
 109          if ($this->currentuserid == $this->useridfrom) {
 110              $message->position = 'right';
 111          }
 112          $message->timesent = userdate($this->timecreated, get_string('strftimetime'));
 113          $message->timecreated = $this->timecreated;
 114          $message->isread = !empty($this->timeread) ? 1 : 0;
 115  
 116          return $message;
 117      }
 118  }