|
1
|
|
|
<?php namespace Arcanesoft\Core\Helpers; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Session\Store as Session; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Notification |
|
7
|
|
|
* |
|
8
|
|
|
* @package Arcanesoft\Foundation\Helpers |
|
9
|
|
|
* @author ARCANEDEV <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class Notification |
|
12
|
|
|
{ |
|
13
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
14
|
|
|
| Properties |
|
15
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* The session store instance. |
|
19
|
|
|
* |
|
20
|
|
|
* @var \Illuminate\Session\Store |
|
21
|
|
|
*/ |
|
22
|
|
|
private $session; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Session name. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $name = 'notification'; |
|
30
|
|
|
|
|
31
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
32
|
|
|
| Constructor |
|
33
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
34
|
|
|
*/ |
|
35
|
|
|
/** |
|
36
|
|
|
* Notification constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param \Illuminate\Session\Store $session |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(Session $session) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->session = $session; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
46
|
|
|
| Getters & Setters |
|
47
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
48
|
|
|
*/ |
|
49
|
|
|
/** |
|
50
|
|
|
* Get the session name. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getName() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->name; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Set the session name. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $name |
|
63
|
|
|
* |
|
64
|
|
|
* @return self |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setName($name) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->name = $name; |
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
74
|
|
|
| Main Functions |
|
75
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
76
|
|
|
*/ |
|
77
|
|
|
/** |
|
78
|
|
|
* Notify a success alert. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $title |
|
81
|
|
|
* @param string $message |
|
82
|
|
|
*/ |
|
83
|
|
|
public function success($title, $message = '') |
|
84
|
|
|
{ |
|
85
|
|
|
$this->notify('success', $title, $message); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Notify a danger alert. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $title |
|
92
|
|
|
* @param string $message |
|
93
|
|
|
*/ |
|
94
|
|
|
public function danger($title, $message = '') |
|
95
|
|
|
{ |
|
96
|
|
|
$this->notify('danger', $title, $message); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Notify an warning alert. |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $title |
|
103
|
|
|
* @param string $message |
|
104
|
|
|
*/ |
|
105
|
|
|
public function warning($title, $message = '') |
|
106
|
|
|
{ |
|
107
|
|
|
$this->notify('warning', $title, $message); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Notify an info alert. |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $title |
|
114
|
|
|
* @param string $message |
|
115
|
|
|
*/ |
|
116
|
|
|
public function info($title, $message = '') |
|
117
|
|
|
{ |
|
118
|
|
|
$this->notify('info', $title, $message); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Notify an alert. |
|
123
|
|
|
* |
|
124
|
|
|
* @param string $status |
|
125
|
|
|
* @param string $title |
|
126
|
|
|
* @param string $message |
|
127
|
|
|
*/ |
|
128
|
|
|
public function notify($status, $title, $message = '') |
|
129
|
|
|
{ |
|
130
|
|
|
$this->session->flash($this->name, compact('status', 'title', 'message')); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|