-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlert.php
executable file
·71 lines (61 loc) · 1.82 KB
/
Alert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace makroxyz\materializecss;
use Yii;
use yii\helpers\ArrayHelper;
/**
* Class Alert
* @package makroxyz\materializecss
*/
class Alert extends Widget
{
private $_defaultAlertLevels = [
'error' => 'error',
'danger' => 'danger',
'success' => 'success',
'info' => 'info',
'warning' => 'warning'
];
public $alertLevels = [];
public $options = [];
/**
* initialize the widget
*/
public function init()
{
parent::init();
$this->alertLevels = ArrayHelper::merge($this->_defaultAlertLevels, $this->alertLevels);
}
/**
* @inheritdoc
*/
public function run()
{
$flashes = Yii::$app->session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $data) {
if (isset($this->alertLevels[$type])) {
$data = (array)$data;
foreach ($data as $i => $message) {
/* initialize css class for each alert box */
$this->options['class'] = 'alert ' . $this->alertLevels[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
echo $this->renderHtml($message, $this->options);
}
Yii::$app->session->removeFlash($type);
}
}
}
/**
* @param $message
* @param array $options
* @return string
*/
private function renderHtml($message, $options = [])
{
return CardPanel::widget([
'content' => $message,
'options' => $this->options
]);
}
}