|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LIN3S\WPSymfonyForm\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use LIN3S\WPSymfonyForm\Admin\Storage\InMemoryStorage; |
|
6
|
|
|
use LIN3S\WPSymfonyForm\Admin\Storage\YamlStorage; |
|
7
|
|
|
use LIN3S\WPSymfonyForm\Admin\Views\FormsTable; |
|
8
|
|
|
use LIN3S\WPSymfonyForm\Admin\Views\LogsTable; |
|
9
|
|
|
use LIN3S\WPSymfonyForm\Registry\FormWrapperRegistry; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Main admin class. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Beñat Espiña <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class Admin |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* The forms table. |
|
20
|
|
|
* |
|
21
|
|
|
* @var FormsTable |
|
22
|
|
|
*/ |
|
23
|
|
|
private $formsTable; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The logs table. |
|
27
|
|
|
* |
|
28
|
|
|
* @var LogsTable |
|
29
|
|
|
*/ |
|
30
|
|
|
public $logsTable; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The form wrapper registry. |
|
34
|
|
|
* |
|
35
|
|
|
* @var FormWrapperRegistry |
|
36
|
|
|
*/ |
|
37
|
|
|
private $formWrapperRegistry; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Array which contains the forms. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
private $forms; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @param FormWrapperRegistry $formWrapperRegistry The form wrapper registry |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(FormWrapperRegistry $formWrapperRegistry) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->formWrapperRegistry = $formWrapperRegistry; |
|
54
|
|
|
$this->forms = []; |
|
55
|
|
|
add_filter('set-screen-option', function ($status, $option, $value) { |
|
|
|
|
|
|
56
|
|
|
return $value; |
|
57
|
|
|
}, 10, 3); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
add_action('admin_menu', [$this, 'menu']); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Loads the menu inside WordPress admin sidebar. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function menu() |
|
66
|
|
|
{ |
|
67
|
|
|
$menu = add_menu_page( |
|
68
|
|
|
'Symfony Forms', |
|
69
|
|
|
'Symfony Forms', |
|
70
|
|
|
'manage_options', |
|
71
|
|
|
'symfony-form', |
|
72
|
|
|
[$this, 'generalPage'] |
|
73
|
|
|
); |
|
74
|
|
|
add_action("load-$menu", [$this, 'generalPageScreenOptions']); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
foreach ($this->formWrapperRegistry->get() as $key => $formWrapper) { |
|
|
|
|
|
|
77
|
|
|
$name = ucfirst($formWrapper->getName()); |
|
78
|
|
|
$slug = 'wp-symfony-form-' . preg_replace('/\s+/', '', strtolower($formWrapper->getName())); |
|
79
|
|
|
|
|
80
|
|
|
$subMenu = add_submenu_page( |
|
|
|
|
|
|
81
|
|
|
'symfony-form', |
|
82
|
|
|
$name, |
|
83
|
|
|
$name, |
|
84
|
|
|
'manage_options', |
|
85
|
|
|
$slug, |
|
86
|
|
|
[$this, 'logArchivePage'] |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$this->forms[] = [ |
|
90
|
|
|
'name' => $name, |
|
91
|
|
|
'link' => '<a href="?page=' . $slug . '">/wp-admin/admin.php?page=' . $slug . '</a>', |
|
92
|
|
|
]; |
|
93
|
|
|
|
|
94
|
|
|
// do_action('wp-symfony-form-load-'. $subMenu, ['name' => $name]); |
|
|
|
|
|
|
95
|
|
|
// add_action('wp-symfony-form-load-'. $subMenu, [$this, 'logArchivePageScreenOptions']); |
|
96
|
|
|
|
|
97
|
|
|
// add_action('wp-symfony-form-load-' . $subMenu, function () use ($name) { |
|
|
|
|
|
|
98
|
|
|
// add_screen_option('per_page', [ |
|
99
|
|
|
// 'label' => 'Logs', |
|
100
|
|
|
// 'default' => 10, |
|
101
|
|
|
// 'option' => 'logs_per_page', |
|
102
|
|
|
// ]); |
|
103
|
|
|
// |
|
104
|
|
|
// $this->logsTable = new LogsTable( |
|
105
|
|
|
// $name, |
|
106
|
|
|
// new YamlStorage() |
|
107
|
|
|
// ); |
|
108
|
|
|
// }); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Adds main form archive page screen options. |
|
114
|
|
|
*/ |
|
115
|
|
|
public function generalPageScreenOptions() |
|
116
|
|
|
{ |
|
117
|
|
|
add_screen_option('per_page', [ |
|
118
|
|
|
'label' => 'Forms', |
|
119
|
|
|
'default' => 10, |
|
120
|
|
|
'option' => 'forms_per_page', |
|
121
|
|
|
]); |
|
122
|
|
|
|
|
123
|
|
|
$this->formsTable = new FormsTable( |
|
124
|
|
|
new InMemoryStorage( |
|
125
|
|
|
$this->forms |
|
126
|
|
|
) |
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
// /** |
|
131
|
|
|
// * Adds email log archive page screen options. |
|
132
|
|
|
// */ |
|
133
|
|
|
// public function logArchivePageScreenOptions() |
|
134
|
|
|
// { |
|
135
|
|
|
// add_screen_option('per_page', [ |
|
136
|
|
|
// 'label' => 'Logs', |
|
137
|
|
|
// 'default' => 10, |
|
138
|
|
|
// 'option' => 'logs_per_page', |
|
139
|
|
|
// ]); |
|
140
|
|
|
// |
|
141
|
|
|
// $this->logsTable = new LogsTable( |
|
142
|
|
|
// $ |
|
143
|
|
|
// new YamlStorage() |
|
144
|
|
|
// ); |
|
145
|
|
|
// } |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Renders main form archive page. |
|
149
|
|
|
*/ |
|
150
|
|
|
public function generalPage() |
|
151
|
|
|
{ |
|
152
|
|
|
?> |
|
153
|
|
|
<div class="wrap"> |
|
154
|
|
|
<h2><?php _e('General', \WPSymfonyForm::TRANSLATION_DOMAIN); ?></h2> |
|
155
|
|
|
<div id="poststuff"> |
|
156
|
|
|
<div id="post-body" class="metabox-holder"> |
|
157
|
|
|
<div id="post-body-content"> |
|
158
|
|
|
<div class="meta-box-sortables ui-sortable"> |
|
159
|
|
|
<form method="post"> |
|
160
|
|
|
<?php |
|
161
|
|
|
$this->formsTable->prepare_items(); |
|
162
|
|
|
$this->formsTable->display(); ?> |
|
163
|
|
|
</form> |
|
164
|
|
|
</div> |
|
165
|
|
|
</div> |
|
166
|
|
|
</div> |
|
167
|
|
|
<br class="clear"> |
|
168
|
|
|
</div> |
|
169
|
|
|
</div> |
|
170
|
|
|
<?php |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Renders log archive page. |
|
175
|
|
|
*/ |
|
176
|
|
|
public function logArchivePage() |
|
177
|
|
|
{ |
|
178
|
|
|
?> |
|
179
|
|
|
<div class="wrap"> |
|
180
|
|
|
<h2><?php _e('Sent emails logs', \WPSymfonyForm::TRANSLATION_DOMAIN); ?></h2> |
|
181
|
|
|
<div id="poststuff"> |
|
182
|
|
|
<div id="post-body" class="metabox-holder"> |
|
183
|
|
|
<div id="post-body-content"> |
|
184
|
|
|
<div class="meta-box-sortables ui-sortable"> |
|
185
|
|
|
<form method="post"> |
|
186
|
|
|
<?php |
|
187
|
|
|
$this->logsTable->prepare_items(); |
|
188
|
|
|
$this->logsTable->display(); ?> |
|
189
|
|
|
</form> |
|
190
|
|
|
</div> |
|
191
|
|
|
</div> |
|
192
|
|
|
</div> |
|
193
|
|
|
<br class="clear"> |
|
194
|
|
|
</div> |
|
195
|
|
|
</div> |
|
196
|
|
|
<?php |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|