63eee58244dd2d64417d4519ac7b3b48b5d2b586
[moodle-mod_attendance.git] / classes / notifyqueue.php
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 * Notify queue
19 *
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
23 */
24
25 defined('MOODLE_INTERNAL') || die();
26
27 /**
28 * Notify Queue class
29 *
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
32 */
33 class mod_attendance_notifyqueue {
34
35 /**
36 * Show (print) the pending messages and clear them
37 */
38 public static function show() {
39 global $SESSION, $OUTPUT;
40
41 if (isset($SESSION->mod_attendance_notifyqueue)) {
42 foreach ($SESSION->mod_attendance_notifyqueue as $message) {
43 echo $OUTPUT->notification($message->message, 'notify'.$message->type);
44 }
45 unset($SESSION->mod_attendance_notifyqueue);
46 }
47 }
48
49 /**
50 * Queue a text as a problem message to be shown latter by show() method
51 *
52 * @param string $message a text with a message
53 */
54 public static function notify_problem($message) {
55 self::queue_message($message, \core\output\notification::NOTIFY_PROBLEM);
56 }
57
58 /**
59 * Queue a text as a simple message to be shown latter by show() method
60 *
61 * @param string $message a text with a message
62 */
63 public static function notify_message($message) {
64 self::queue_message($message, \core\output\notification::NOTIFY_MESSAGE);
65 }
66
67 /**
68 * queue a text as a suceess message to be shown latter by show() method
69 *
70 * @param string $message a text with a message
71 */
72 public static function notify_success($message) {
73 self::queue_message($message, \core\output\notification::NOTIFY_SUCCESS);
74 }
75
76 /**
77 * queue a text as a message of some type to be shown latter by show() method
78 *
79 * @param string $message a text with a message
80 * @param string $messagetype one of the \core\output\notification messages ('message', 'suceess' or 'problem')
81 */
82 private static function queue_message($message, $messagetype=\core\output\notification::NOTIFY_MESSAGE) {
83 global $SESSION;
84
85 if (!isset($SESSION->mod_attendance_notifyqueue)) {
86 $SESSION->mod_attendance_notifyqueue = array();
87 }
88 $m = new stdclass();
89 $m->type = $messagetype;
90 $m->message = $message;
91 $SESSION->mod_attendance_notifyqueue[] = $m;
92 }
93 }