Completed
Push — master ( 4cc80e...c361a4 )
by De Cramer
13s
created

Notifications::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 1
eloc 7
nc 1
nop 3
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: php_r
5
 * Date: 25.2.2018
6
 * Time: 21.50
7
 */
8
9
namespace eXpansion\Framework\Notifications\Services;
10
11
12
use eXpansion\Framework\Core\Model\UserGroups\Group;
13
use eXpansion\Framework\Notifications\Plugins\Gui\NotificationUpdater;
14
use Psr\Log\LoggerInterface;
15
16
/**
17
 * Class Notifications
18
 * @package eXpansion\Framework\Notifications\Services
19
 */
20
class Notifications
21
{
22
    /**
23
     * @var NotificationUpdater
24
     */
25
    private $notificationsUpdater;
26
    /** @var Group */
27
    private $group;
28
    /**
29
     * @var LoggerInterface
30
     */
31
    private $logger;
32
33
    /**
34
     * Notifications constructor.
35
     * @param Group               $group
36
     * @param NotificationUpdater $notificationUpdater
37
     * @param LoggerInterface     $logger
38
     */
39
    public function __construct(
40
        $group,
41
        NotificationUpdater $notificationUpdater,
42
        LoggerInterface $logger
43
    ) {
44
        $this->notificationsUpdater = $notificationUpdater;
45
        $this->group = $group;
46
        $this->logger = $logger;
47
    }
48
49
    /**
50
     * Sends notification as info level
51
     * Notifications are automatically logged
52
     *
53
     * @param string     $message Message of notification
54
     * @param array      $params replacements for translation, note: same params are used for title and message replacement
55
     * @param string     $title Title of the notification
56
     * @param int        $duration use 0 for permanent
57
     * @param Group|null $group
58
     */
59
    public function info($message, $params = [], $title = "Info", $duration = 5500, $group = null)
60
    {
61
        $this->sendNotification('$3af ', $title, $message, $params, $duration, $group);
62
    }
63
64
    /**
65
     * Sends notification as info level
66
     * Notifications are automatically logged
67
     *
68
     * @param string     $message Message of notification
69
     * @param array      $params replacements for translation, note: same params are used for title and message replacement
70
     * @param string     $title Title of the notification
71
     * @param int        $duration use 0 for permanent
72
     * @param Group|null $group
73
     */
74
75
    public function notice($message, $params = [], $title = "Notice", $duration = 5500, $group = null)
76
    {
77
        $this->sendNotification("", $title, $message, $params, $duration, $group);
78
    }
79
80
    /**
81
     * Sends notification as info level
82
     * Notifications are automatically logged
83
     *
84
     * @param string     $message Message of notification
85
     * @param array      $params replacements for translation, note: same params are used for title and message replacement
86
     * @param string     $title Title of the notification
87
     * @param int        $duration use 0 for permanent
88
     * @param Group|null $group
89
     */
90
91
    public function warning($message, $params = [], $title = "Warning", $duration = 8500, $group = null)
92
    {
93
94
        $this->sendNotification('$ff0 ', $title, $message, $params, $duration, $group);
95
    }
96
97
    /**
98
     * Sends notification as info level
99
     * Notifications are automatically logged
100
     *
101
     * @param string     $message Message of notification
102
     * @param array      $params replacements for translation, note: same params are used for title and message replacement
103
     * @param string     $title Title of the notification
104
     * @param int        $duration use 0 for permanent
105
     * @param Group|null $group
106
     */
107
108
    public function error($message, $params = [], $title = "Error", $duration = 10500, $group = null)
109
    {
110
        $this->sendNotification('$f00 ', $title, $message, $params, $duration, $group);
111
    }
112
113
114
    /**
115
     * @param      $prefix
116
     * @param      $title
117
     * @param      $message
118
     * @param      $params
119
     * @param      $duration
120
     * @param null $group
121
     */
122
    protected function sendNotification($prefix, $title, $message, $params, $duration, $group = null)
123
    {
124
        if ($group == null) {
125
            $group = $this->group;
126
        }
127
128
        $this->notificationsUpdater->setNotification($prefix, $title, $message, $params, $duration, $group);
129
    }
130
131
132
}