1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* Copyright (C) |
6
|
|
|
* Nathan Boiron <[email protected]> |
7
|
|
|
* Romain Canon <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
11
|
|
|
* under the terms of the GNU General Public License, either |
12
|
|
|
* version 3 of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, see: |
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Controller\Backend\Manager; |
19
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Controller\Backend\Menu; |
21
|
|
|
use CuyZ\Notiz\Core\Notification\Activable; |
22
|
|
|
|
23
|
|
|
class NotificationActivationController extends ManagerController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $notificationType |
27
|
|
|
* @param string $notificationIdentifier |
28
|
|
|
* @param string|null $filterEvent |
29
|
|
|
*/ |
30
|
|
|
public function processAction(string $notificationType, string $notificationIdentifier, string $filterEvent = null) |
31
|
|
|
{ |
32
|
|
|
$definition = $this->getDefinition(); |
33
|
|
|
|
34
|
|
|
if (!$definition->hasNotification($notificationType)) { |
35
|
|
|
$this->addErrorMessage( |
36
|
|
|
'Backend/Module/Manager:notification_type_not_found', |
37
|
|
|
$notificationType |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$this->returnToList($notificationType, $filterEvent); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$notificationDefinition = $definition->getNotification($notificationType); |
44
|
|
|
$processor = $notificationDefinition->getProcessor(); |
45
|
|
|
|
46
|
|
|
$notification = $processor->getNotificationFromIdentifier($notificationIdentifier); |
47
|
|
|
|
48
|
|
|
if (!$notification instanceof Activable) { |
49
|
|
|
$this->returnToList($notificationType, $filterEvent); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($notification->isActive()) { |
|
|
|
|
53
|
|
|
$processor->disable($notification); |
54
|
|
|
|
55
|
|
|
$this->returnToList($notificationType, $filterEvent); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$processor->enable($notification); |
59
|
|
|
|
60
|
|
|
$this->returnToList($notificationType, $filterEvent); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $notificationType |
65
|
|
|
* @param string|null $filterEvent [PHP 7.1] |
66
|
|
|
*/ |
67
|
|
|
private function returnToList(string $notificationType, $filterEvent) |
68
|
|
|
{ |
69
|
|
|
$this->forward( |
70
|
|
|
'process', |
71
|
|
|
'Backend\\Manager\\ListNotifications', |
72
|
|
|
null, |
73
|
|
|
[ |
74
|
|
|
'notificationIdentifier' => $notificationType, |
75
|
|
|
'filterEvent' => $filterEvent, |
76
|
|
|
] |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
protected function getMenu(): string |
84
|
|
|
{ |
85
|
|
|
return Menu::MANAGER_NOTIFICATIONS; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|