2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
20 * @package mod_attendance
21 * @copyright 2015 Antonio Carlos Mariani <antonio.c.mariani@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
30 * @copyright 2015 Antonio Carlos Mariani <antonio.c.mariani@gmail.com>
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 class mod_attendance_notifyqueue
{
36 * Show (print) the pending messages and clear them
38 public static function show() {
39 global $SESSION, $OUTPUT;
41 if (isset($SESSION->mod_attendance_notifyqueue
)) {
42 foreach ($SESSION->mod_attendance_notifyqueue
as $message) {
43 echo $OUTPUT->notification($message->message
, 'notify'.$message->type
);
45 unset($SESSION->mod_attendance_notifyqueue
);
50 * Queue a text as a problem message to be shown latter by show() method
52 * @param string $message a text with a message
54 public static function notify_problem($message) {
55 self
::queue_message($message, \core\output
\notification
::NOTIFY_PROBLEM
);
59 * Queue a text as a simple message to be shown latter by show() method
61 * @param string $message a text with a message
63 public static function notify_message($message) {
64 self
::queue_message($message, \core\output
\notification
::NOTIFY_MESSAGE
);
68 * queue a text as a suceess message to be shown latter by show() method
70 * @param string $message a text with a message
72 public static function notify_success($message) {
73 self
::queue_message($message, \core\output
\notification
::NOTIFY_SUCCESS
);
77 * queue a text as a message of some type to be shown latter by show() method
79 * @param string $message a text with a message
80 * @param string $messagetype one of the \core\output\notification messages ('message', 'suceess' or 'problem')
82 private static function queue_message($message, $messagetype=\core\output
\notification
::NOTIFY_MESSAGE
) {
85 if (!isset($SESSION->mod_attendance_notifyqueue
)) {
86 $SESSION->mod_attendance_notifyqueue
= array();
89 $m->type
= $messagetype;
90 $m->message
= $message;
91 $SESSION->mod_attendance_notifyqueue
[] = $m;