|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace helikopterspark\FlashMsg; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class for displaying flash messages |
|
7
|
|
|
*/ |
|
8
|
|
|
class FlashMsg implements \Anax\DI\IInjectionAware { |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
use \Anax\DI\TInjectable; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Add message to session array |
|
14
|
|
|
* |
|
15
|
|
|
* @param $type string with message type |
|
16
|
|
|
* @param $message string with message text |
|
17
|
|
|
* |
|
18
|
|
|
* @return void |
|
19
|
|
|
*/ |
|
20
|
9 |
|
public function setMessage($type, $message) { |
|
21
|
9 |
|
if (!$this->session->has('flashmsgs')) { |
|
|
|
|
|
|
22
|
9 |
|
$this->session->set('flashmsgs', array()); |
|
|
|
|
|
|
23
|
9 |
|
} |
|
24
|
9 |
|
$temp = $this->session->get('flashmsgs'); |
|
|
|
|
|
|
25
|
9 |
|
$temp[] = array('type' => $type, 'content' => $message); |
|
26
|
9 |
|
$this->session->set('flashmsgs', $temp); |
|
|
|
|
|
|
27
|
9 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Add alert message to session array |
|
31
|
|
|
* |
|
32
|
|
|
* @param $message string with message text |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function alert($message) { |
|
37
|
1 |
|
$this->setMessage('alert', $message); |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Add error message to session array |
|
42
|
|
|
* |
|
43
|
|
|
* @param $message string with message text |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function error($message) { |
|
48
|
1 |
|
$this->setMessage('error', $message); |
|
49
|
1 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Add info message to session array |
|
53
|
|
|
* |
|
54
|
|
|
* @param $message string with message text |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function info($message) { |
|
59
|
1 |
|
$this->setMessage('info', $message); |
|
60
|
1 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Add notice message to session array |
|
64
|
|
|
* |
|
65
|
|
|
* @param $message string with message text |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
3 |
|
public function notice($message) { |
|
70
|
3 |
|
$this->setMessage('notice', $message); |
|
71
|
3 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Add success message to session array |
|
75
|
|
|
* |
|
76
|
|
|
* @param $message string with message text |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
3 |
|
public function success($message) { |
|
81
|
3 |
|
$this->setMessage('success', $message); |
|
82
|
3 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Add warning message to session array |
|
86
|
|
|
* |
|
87
|
|
|
* @param $message string with message text |
|
88
|
|
|
* |
|
89
|
|
|
* @return void |
|
90
|
|
|
*/ |
|
91
|
3 |
|
public function warning($message) { |
|
92
|
3 |
|
$this->setMessage('warning', $message); |
|
93
|
3 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Build HTML of messages in session array |
|
97
|
|
|
* |
|
98
|
|
|
* @return $output HTML string with messages |
|
|
|
|
|
|
99
|
|
|
*/ |
|
100
|
1 |
|
public function outputMsgs() { |
|
101
|
1 |
|
$messages = $this->session->get('flashmsgs'); |
|
|
|
|
|
|
102
|
1 |
|
$output = null; |
|
103
|
|
|
|
|
104
|
1 |
|
if ($messages) { |
|
105
|
1 |
|
foreach ($messages as $key => $message) { |
|
106
|
1 |
|
$output .= '<div class="' . $message['type'] . '"><p>' . $message['content'] . '</p></div>'; |
|
107
|
1 |
|
} |
|
108
|
1 |
|
} |
|
109
|
|
|
|
|
110
|
1 |
|
return $output; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Clear session message array |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function clearMessages() { |
|
119
|
1 |
|
$this->session->set('flashmsgs', []); |
|
|
|
|
|
|
120
|
1 |
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|