/message/classes/output/messagearea/message.php

https://gitlab.com/unofficial-mirrors/moodle · PHP · 115 lines · 42 code · 16 blank · 57 comment · 3 complexity · 9219d7337d6fdceae85f537a6bcfdd1c MD5 · raw file

  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. * Contains class used to prepare a message for display.
  18. *
  19. * @package core_message
  20. * @copyright 2016 Mark Nelson <markn@moodle.com>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. namespace core_message\output\messagearea;
  24. defined('MOODLE_INTERNAL') || die();
  25. use renderable;
  26. use templatable;
  27. /**
  28. * Class to prepare a message for display.
  29. *
  30. * @package core_message
  31. * @copyright 2016 Mark Nelson <markn@moodle.com>
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class message implements templatable, renderable {
  35. /**
  36. * @var int The message id.
  37. */
  38. public $id;
  39. /**
  40. * @var int The current userid.
  41. */
  42. public $currentuserid;
  43. /**
  44. * @var int The userid to.
  45. */
  46. public $useridto;
  47. /**
  48. * @var int The userid from.
  49. */
  50. public $useridfrom;
  51. /**
  52. * @var string The message text.
  53. */
  54. public $text;
  55. /**
  56. * @var bool Are we displaying the time?
  57. */
  58. public $displayblocktime;
  59. /**
  60. * @var int The time created of the message.
  61. */
  62. public $timecreated;
  63. /**
  64. * @var int The time the message was read.
  65. */
  66. public $timeread;
  67. /**
  68. * Constructor.
  69. *
  70. * @param \stdClass $message
  71. */
  72. public function __construct($message) {
  73. $this->id = $message->id;
  74. $this->currentuserid = $message->currentuserid;
  75. $this->useridto = $message->useridto;
  76. $this->useridfrom = $message->useridfrom;
  77. $this->text = $message->text;
  78. $this->displayblocktime = $message->displayblocktime;
  79. $this->timecreated = $message->timecreated;
  80. $this->timeread = $message->timeread;
  81. }
  82. public function export_for_template(\renderer_base $output) {
  83. $message = new \stdClass();
  84. $message->id = $this->id;
  85. $message->useridto = $this->useridto;
  86. $message->useridfrom = $this->useridfrom;
  87. $message->text = $this->text;
  88. $message->displayblocktime = $this->displayblocktime;
  89. $message->blocktime = userdate($this->timecreated, get_string('strftimedaydate'));
  90. $message->position = 'left';
  91. if ($this->currentuserid == $this->useridfrom) {
  92. $message->position = 'right';
  93. }
  94. $message->timesent = userdate($this->timecreated, get_string('strftimetime'));
  95. $message->timecreated = $this->timecreated;
  96. $message->isread = !empty($this->timeread) ? 1 : 0;
  97. return $message;
  98. }
  99. }