PluginProbe
The Innovative Form Builder – IvyForms / 1.1
The Innovative Form Builder – IvyForms v1.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Routes / Form / Form.php

Form.php in The Innovative Form Builder – IvyForms 1.1, at backend/src/Routes/Form/Form.php

274 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Routes\Form;
4
5 use IvyForms\Vendor\DI\Container;
6 use IvyForms\Vendor\DI\DependencyException;
7 use IvyForms\Vendor\DI\NotFoundException;
8 use IvyForms\Controllers\Form\AddFormController;
9 use IvyForms\Controllers\Form\BulkUpdateFormController;
10 use IvyForms\Controllers\Form\DeleteFormController;
11 use IvyForms\Controllers\Form\FormSubmissionController;
12 use IvyForms\Controllers\Form\DuplicateFormController;
13 use IvyForms\Controllers\Form\GetFormController;
14 use IvyForms\Controllers\Form\GetFormsController;
15 use IvyForms\Controllers\Form\SearchFormsController;
16 use IvyForms\Controllers\Form\UpdateFormController;
17 use IvyForms\Controllers\Form\DeleteFormsController;
18 use IvyForms\Controllers\Form\UpdateFormStarredController;
19 use IvyForms\Controllers\Form\UpdateFormStatusController;
20 use IvyForms\Controllers\Form\ValidateBeforeSubmitController;
21 use IvyForms\Controllers\Form\ExportFormController;
22 use IvyForms\Controllers\Form\ImportFormController;
23 use WP_REST_Server;
24
25 class Form
26 {
27 /**
28 * @throws DependencyException
29 * @throws NotFoundException
30 */
31 public static function registerRoutes(Container $container, string $routeNamespace): void
32 {
33 self::registerFormCrudRoutes($container, $routeNamespace);
34 self::registerFormManagementRoutes($container, $routeNamespace);
35 self::registerFormSubmissionRoutes($container, $routeNamespace);
36 self::registerFormImportExportRoutes($container, $routeNamespace);
37 }
38
39 /**
40 * Register CRUD routes for forms (Create, Read, Update, Delete)
41 *
42 * @throws DependencyException
43 * @throws NotFoundException
44 */
45 private static function registerFormCrudRoutes(Container $container, string $routeNamespace): void
46 {
47 // Get single form
48 register_rest_route(
49 $routeNamespace,
50 '/form/(?P<id>\d+)',
51 [
52 'methods' => WP_REST_Server::READABLE,
53 'callback' => $container->get(GetFormController::class),
54 'permission_callback' => function () {
55 return current_user_can('manage_options');
56 }
57 ]
58 );
59
60 // Get all forms
61 register_rest_route(
62 $routeNamespace,
63 '/form',
64 [
65 'methods' => WP_REST_Server::READABLE,
66 'callback' => $container->get(GetFormsController::class),
67 'permission_callback' => function () {
68 return current_user_can('manage_options');
69 }
70 ]
71 );
72
73 // Add new form
74 register_rest_route(
75 $routeNamespace,
76 '/form/add/',
77 [
78 'methods' => WP_REST_Server::CREATABLE,
79 'callback' => $container->get(AddFormController::class),
80 'permission_callback' => function () {
81 return current_user_can('manage_options');
82 }
83 ]
84 );
85
86 // Update form
87 register_rest_route(
88 $routeNamespace,
89 '/form/update/(?P<id>\d+)',
90 [
91 'methods' => WP_REST_Server::CREATABLE,
92 'callback' => $container->get(UpdateFormController::class),
93 'permission_callback' => function () {
94 return current_user_can('manage_options');
95 }
96 ]
97 );
98
99 // Delete single form
100 register_rest_route(
101 $routeNamespace,
102 '/form/delete/(?P<id>\d+)',
103 [
104 'methods' => WP_REST_Server::CREATABLE,
105 'callback' => $container->get(DeleteFormController::class),
106 'permission_callback' => function () {
107 return current_user_can('manage_options');
108 }
109 ]
110 );
111
112 // Delete multiple forms
113 register_rest_route(
114 $routeNamespace,
115 '/forms/delete',
116 [
117 'methods' => WP_REST_Server::CREATABLE,
118 'callback' => $container->get(DeleteFormsController::class),
119 'permission_callback' => function () {
120 return current_user_can('manage_options');
121 }
122 ]
123 );
124 }
125
126 /**
127 * Register form management routes (search, status updates, etc.)
128 *
129 * @throws DependencyException
130 * @throws NotFoundException
131 */
132 private static function registerFormManagementRoutes(Container $container, string $routeNamespace): void
133 {
134 // Search forms
135 register_rest_route(
136 $routeNamespace,
137 '/forms/search',
138 [
139 'methods' => WP_REST_Server::READABLE,
140 'callback' => $container->get(SearchFormsController::class),
141 'args' => [
142 'page' => ['type' => 'integer'],
143 'perPage' => ['type' => 'integer'],
144 'search' => ['type' => 'string'],
145 'orderBy' => ['type' => 'string'],
146 'order' => ['type' => 'string'],
147 'shouldGetCount' => ['type' => 'boolean'],
148 ],
149 'permission_callback' => function () {
150 return current_user_can('manage_options');
151 }
152 ]
153 );
154
155 // Update form starred status
156 register_rest_route(
157 $routeNamespace,
158 '/form/update/starred/(?P<id>\d+)',
159 [
160 'methods' => WP_REST_Server::CREATABLE,
161 'callback' => $container->get(UpdateFormStarredController::class),
162 'permission_callback' => function () {
163 return current_user_can('manage_options');
164 }
165 ]
166 );
167
168 // Update form status
169 register_rest_route(
170 $routeNamespace,
171 '/form/update/status/(?P<id>\d+)',
172 [
173 'methods' => WP_REST_Server::CREATABLE,
174 'callback' => $container->get(UpdateFormStatusController::class),
175 'permission_callback' => function () {
176 return current_user_can('manage_options');
177 }
178 ]
179 );
180
181 // Duplicate form
182 register_rest_route(
183 $routeNamespace,
184 '/form/duplicate/(?P<id>\d+)',
185 [
186 'methods' => WP_REST_Server::CREATABLE,
187 'callback' => $container->get(DuplicateFormController::class),
188 'permission_callback' => function () {
189 return current_user_can('manage_options');
190 }
191 ]
192 );
193
194 // Bulk update forms
195 register_rest_route(
196 $routeNamespace,
197 '/forms/batch-actions',
198 [
199 'methods' => WP_REST_Server::CREATABLE,
200 'callback' => [$container->get(BulkUpdateFormController::class), 'handle'],
201 'permission_callback' => function () {
202 return current_user_can('manage_options');
203 }
204 ]
205 );
206 }
207
208 /**
209 * Register form submission routes (public-facing)
210 *
211 * @throws DependencyException
212 * @throws NotFoundException
213 */
214 private static function registerFormSubmissionRoutes(Container $container, string $routeNamespace): void
215 {
216 // Form submission (public route)
217 register_rest_route(
218 $routeNamespace,
219 '/form/submission/',
220 [
221 'methods' => WP_REST_Server::CREATABLE,
222 'callback' => $container->get(FormSubmissionController::class),
223 // TODO - Add IvyForms capability - Public use
224 'permission_callback' => '__return_true'
225 ]
226 );
227
228 register_rest_route(
229 $routeNamespace,
230 '/form/validate_before_submit/',
231 [
232 'methods' => WP_REST_Server::CREATABLE,
233 'callback' => $container->get(ValidateBeforeSubmitController::class),
234 'permission_callback' => '__return_true',
235 ]
236 );
237 }
238
239 /**
240 * Register form import/export routes
241 *
242 * @throws DependencyException
243 * @throws NotFoundException
244 */
245 private static function registerFormImportExportRoutes(Container $container, string $routeNamespace): void
246 {
247 // Export forms
248 register_rest_route(
249 $routeNamespace,
250 '/forms/export',
251 [
252 'methods' => WP_REST_Server::CREATABLE,
253 'callback' => $container->get(ExportFormController::class),
254 'permission_callback' => function () {
255 return current_user_can('manage_options');
256 }
257 ]
258 );
259
260 // Import forms
261 register_rest_route(
262 $routeNamespace,
263 '/forms/import',
264 [
265 'methods' => WP_REST_Server::CREATABLE,
266 'callback' => $container->get(ImportFormController::class),
267 'permission_callback' => function () {
268 return current_user_can('manage_options');
269 }
270 ]
271 );
272 }
273 }
274