-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathNotifications.php
More file actions
130 lines (107 loc) · 3.35 KB
/
Notifications.php
File metadata and controls
130 lines (107 loc) · 3.35 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php namespace RainLab\Notify\Controllers;
use BackendMenu;
use Backend\Classes\Controller;
use RainLab\Notify\Models\NotificationRule;
use System\Classes\SettingsManager;
use RainLab\Notify\Classes\EventBase;
use ApplicationException;
use Exception;
/**
* Notification rules controller
*
* @package rainlab\notify
* @author Alexey Bobkov, Samuel Georges
*/
class Notifications extends Controller
{
public $implement = [
\Backend\Behaviors\FormController::class,
\Backend\Behaviors\ListController::class
];
public $requiredPermissions = ['rainlab.notify.manage_notifications'];
public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public $eventAlias;
protected $eventClass;
public function __construct()
{
parent::__construct();
BackendMenu::setContext('October.System', 'system', 'settings');
SettingsManager::setContext('RainLab.Notify', 'notifications');
}
public function index()
{
NotificationRule::syncAll();
$this->asExtension('ListController')->index();
}
public function create($eventAlias = null)
{
try {
if (!$eventAlias) {
throw new ApplicationException('Missing a rule code');
}
$this->eventAlias = $eventAlias;
$this->bodyClass = 'compact-container breadcrumb-fancy';
$this->asExtension('FormController')->create();
}
catch (Exception $ex) {
$this->handleError($ex);
}
}
public function update($recordId = null, $context = null)
{
$this->bodyClass = 'compact-container breadcrumb-fancy';
$this->asExtension('FormController')->update($recordId, $context);
}
public function formExtendModel($model)
{
if (!$model->exists) {
$model->applyEventClass($this->getEventClass());
$model->name = $model->getEventDescription();
}
return $model;
}
// public function formBeforeSave($model)
// {
// $model->is_custom = 1;
// }
public function index_onLoadRuleGroupForm()
{
try {
$groups = EventBase::findEventGroups();
$this->vars['eventGroups'] = $groups;
}
catch (Exception $ex) {
$this->handleError($ex);
}
return $this->makePartial('add_rule_group_form');
}
/**
* This handler requires the group code passed from `onLoadRuleGroupForm`
*/
public function index_onLoadRuleEventForm()
{
try {
if (!$code = post('code')) {
throw new ApplicationException('Missing event group code');
}
$events = EventBase::findEventsByGroup($code);
$this->vars['events'] = $events;
}
catch (Exception $ex) {
$this->handleError($ex);
}
return $this->makePartial('add_rule_event_form');
}
protected function getEventClass()
{
$alias = post('event_alias', $this->eventAlias);
if ($this->eventClass !== null) {
return $this->eventClass;
}
if (!$event = EventBase::findEventByIdentifier($alias)) {
throw new ApplicationException('Unable to find event with alias: '. $alias);
}
return $this->eventClass = get_class($event);
}
}