-
Notifications
You must be signed in to change notification settings - Fork 5
/
Plugin.php
124 lines (107 loc) · 4.27 KB
/
Plugin.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
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
<?php
namespace Publipresse\Forms;
use Lang;
use Validator;
use Publipresse\Forms\Classes\BackendHelpers;
use Publipresse\Forms\Models\Settings;
use Publipresse\Forms\Models\Record;
use Backend\Facades\Backend;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
class Plugin extends PluginBase
{
public function pluginDetails() {
return [
'name' => __('Magic forms'),
'description' => __('Create easy ajax forms'),
'author' => 'Publipresse',
'icon' => 'icon-bolt',
'homepage' => 'https://github.com/publipresse/oc-forms-plugin'
];
}
public function register()
{
$this->registerConsoleCommand('import.martinforms', \Publipresse\Forms\Console\ImportMartinForms::class);
}
public function registerNavigation() {
// Add menu item for all records
$menu = [
'forms' => [
'label' => __('Forms'),
'icon' => 'icon-bolt',
'url' => BackendHelpers::getBackendURL(['publipresse.forms.access_records' => 'publipresse/forms/records', 'publipresse.forms.access_exports' => 'publipresse/forms/exports'], 'publipresse.forms.access_records'),
'permissions' => ['publipresse.forms.*'],
'counter' => Record::getUnread(),
'counterLabel' => __('Unread messages'),
'sideMenu' => [
'records' => [
'label' => __('All records'),
'icon' => 'icon-database',
'url' => Backend::url('publipresse/forms/records'),
'permissions' => ['publipresse.forms.access_records'],
'counter' => Record::getUnread(),
'counterLabel' => __('Unread messages'),
],
]
]
];
// Add menu item for each groups
$groups = Record::all()->pluck('group')->unique();
foreach($groups as $group) {
$slug = str_slug($group);
$menu['forms']['sideMenu'][$slug] = [
'label' => $group,
'icon' => 'icon-database',
'url' => Backend::url('publipresse/forms/records?group='.$group),
'permissions' => ['publipresse.forms.access_records'],
'counter' => Record::getUnread($group),
'counterLabel' => __('Unread messages'),
];
}
// Add menu item to export datas
$menu['forms']['sideMenu']['exports'] = [
'label' => __('Export'),
'icon' => 'icon-download',
'url' => Backend::url('publipresse/forms/exports'),
'permissions' => ['publipresse.forms.access_exports']
];
return $menu;
}
public function registerSettings() {
return [
'config' => [
'label' => __('Magic forms'),
'description' => __('Configure magic forms parameters'),
'category' => SettingsManager::CATEGORY_CMS,
'icon' => 'icon-bolt',
'class' => 'Publipresse\Forms\Models\Settings',
'permissions' => ['publipresse.forms.access_settings'],
'order' => 500
]
];
}
public function registerPermissions() {
return [
'publipresse.forms.access_settings' => ['tab' => __('Magic forms'), 'label' => __('Access settings')],
'publipresse.forms.access_records' => ['tab' => __('Magic forms'), 'label' => __('Access records')],
'publipresse.forms.access_exports' => ['tab' => __('Magic forms'), 'label' => __('Can export records')],
'publipresse.forms.gdpr_cleanup' => ['tab' => __('Magic forms'), 'label' => __('Gdpr cleanup')],
];
}
public function registerComponents() {
return [
'Publipresse\Forms\Components\UploadForm' => 'uploadForm',
];
}
public function registerMailTemplates() {
return [
'publipresse.forms::mail.notification',
'publipresse.forms::mail.autoresponse',
];
}
public function registerSchedule($schedule) {
$schedule->call(function () {
MagicForm::gdprClean();
})->daily();
}
}