. /** * Notification renderable component. * * @package core * @copyright 2015 Jetha Chan * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core\output; use stdClass; /** * Data structure representing a notification. * * @copyright 2015 Jetha Chan * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.9 * @package core * @category output */ class notification implements \renderable, \templatable { /** * A generic message. */ const NOTIFY_MESSAGE = 'message'; /** * A message notifying the user of a successful operation. */ const NOTIFY_SUCCESS = 'success'; /** * A message notifying the user that a problem occurred. */ const NOTIFY_PROBLEM = 'problem'; /** * A message to display during a redirect.. */ const NOTIFY_REDIRECT = 'redirect'; /** * @var string Message payload. */ private $message = ''; /** * @var string Message type. */ private $messagetype = self::NOTIFY_PROBLEM; /** * Notification constructor. * * @param string $message the message to print out * @param string $messagetype normally NOTIFY_PROBLEM or NOTIFY_SUCCESS. */ public function __construct($message, $messagetype = self::NOTIFY_PROBLEM) { $this->message = clean_text($message); $this->messagetype = $messagetype; } /** * Export this data so it can be used as the context for a mustache template. * * @param renderer_base $output typically, the renderer that's calling this function * @return stdClass data context for a mustache template */ public function export_for_template(\renderer_base $output) { $data = new stdClass(); $data->type = $this->messagetype; $data->message = $this->message; return $data; } }