PluginProbe
The Innovative Form Builder – IvyForms / 0.9
The Innovative Form Builder – IvyForms v0.9
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 0.9, at backend/src/Routes/Form/Form.php

231 lines 7.6 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 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Vendor\DI\Container;
11 use IvyForms\Vendor\DI\DependencyException;
12 use IvyForms\Vendor\DI\NotFoundException;
13 use IvyForms\Controllers\Form\AddFormController;
14 use IvyForms\Controllers\Form\BulkUpdateFormController;
15 use IvyForms\Controllers\Form\DeleteFormController;
16 use IvyForms\Controllers\Form\FormSubmissionController;
17 use IvyForms\Controllers\Form\DuplicateFormController;
18 use IvyForms\Controllers\Form\GetFormController;
19 use IvyForms\Controllers\Form\GetFormsController;
20 use IvyForms\Controllers\Form\SearchFormsController;
21 use IvyForms\Controllers\Form\UpdateFormController;
22 use IvyForms\Controllers\Form\DeleteFormsController;
23 use IvyForms\Controllers\Form\UpdateFormStarredController;
24 use IvyForms\Controllers\Form\UpdateFormStatusController;
25 use IvyForms\Controllers\Form\CheckDuplicateController;
26 use WP_REST_Server;
27
28 class Form
29 {
30 /**
31 * @throws DependencyException
32 * @throws NotFoundException
33 */
34 public static function registerRoutes(Container $container, string $routeNamespace): void
35 {
36 self::registerFormCrudRoutes($container, $routeNamespace);
37 self::registerFormManagementRoutes($container, $routeNamespace);
38 self::registerFormSubmissionRoutes($container, $routeNamespace);
39 }
40
41 /**
42 * Register CRUD routes for forms (Create, Read, Update, Delete)
43 *
44 * @throws DependencyException
45 * @throws NotFoundException
46 */
47 private static function registerFormCrudRoutes(Container $container, string $routeNamespace): void
48 {
49 // Get single form
50 register_rest_route(
51 $routeNamespace,
52 '/form/(?P<id>\d+)',
53 [
54 'methods' => WP_REST_Server::READABLE,
55 'callback' => $container->get(GetFormController::class),
56 'permission_callback' => function () {
57 return current_user_can('manage_options');
58 }
59 ]
60 );
61
62 // Get all forms
63 register_rest_route(
64 $routeNamespace,
65 '/form',
66 [
67 'methods' => WP_REST_Server::READABLE,
68 'callback' => $container->get(GetFormsController::class),
69 'permission_callback' => function () {
70 return current_user_can('manage_options');
71 }
72 ]
73 );
74
75 // Add new form
76 register_rest_route(
77 $routeNamespace,
78 '/form/add/',
79 [
80 'methods' => WP_REST_Server::CREATABLE,
81 'callback' => $container->get(AddFormController::class),
82 'permission_callback' => function () {
83 return current_user_can('manage_options');
84 }
85 ]
86 );
87
88 // Update form
89 register_rest_route(
90 $routeNamespace,
91 '/form/update/(?P<id>\d+)',
92 [
93 'methods' => WP_REST_Server::CREATABLE,
94 'callback' => $container->get(UpdateFormController::class),
95 'permission_callback' => function () {
96 return current_user_can('manage_options');
97 }
98 ]
99 );
100
101 // Delete single form
102 register_rest_route(
103 $routeNamespace,
104 '/form/delete/(?P<id>\d+)',
105 [
106 'methods' => WP_REST_Server::CREATABLE,
107 'callback' => $container->get(DeleteFormController::class),
108 'permission_callback' => function () {
109 return current_user_can('manage_options');
110 }
111 ]
112 );
113
114 // Delete multiple forms
115 register_rest_route(
116 $routeNamespace,
117 '/forms/delete',
118 [
119 'methods' => WP_REST_Server::CREATABLE,
120 'callback' => $container->get(DeleteFormsController::class),
121 'permission_callback' => function () {
122 return current_user_can('manage_options');
123 }
124 ]
125 );
126 }
127
128 /**
129 * Register form management routes (search, status updates, etc.)
130 *
131 * @throws DependencyException
132 * @throws NotFoundException
133 */
134 private static function registerFormManagementRoutes(Container $container, string $routeNamespace): void
135 {
136 // Search forms
137 register_rest_route(
138 $routeNamespace,
139 '/forms/search',
140 [
141 'methods' => WP_REST_Server::READABLE,
142 'callback' => $container->get(SearchFormsController::class),
143 'args' => [
144 'page' => ['type' => 'integer'],
145 'perPage' => ['type' => 'integer'],
146 'search' => ['type' => 'string'],
147 'orderBy' => ['type' => 'string'],
148 'order' => ['type' => 'string'],
149 'shouldGetCount' => ['type' => 'boolean'],
150 ],
151 'permission_callback' => function () {
152 return current_user_can('manage_options');
153 }
154 ]
155 );
156
157 // Update form starred status
158 register_rest_route(
159 $routeNamespace,
160 '/form/update/starred/(?P<id>\d+)',
161 [
162 'methods' => WP_REST_Server::CREATABLE,
163 'callback' => $container->get(UpdateFormStarredController::class),
164 'permission_callback' => function () {
165 return current_user_can('manage_options');
166 }
167 ]
168 );
169
170 // Update form status
171 register_rest_route(
172 $routeNamespace,
173 '/form/update/status/(?P<id>\d+)',
174 [
175 'methods' => WP_REST_Server::CREATABLE,
176 'callback' => $container->get(UpdateFormStatusController::class),
177 'permission_callback' => function () {
178 return current_user_can('manage_options');
179 }
180 ]
181 );
182
183 // Duplicate form
184 register_rest_route(
185 $routeNamespace,
186 '/form/duplicate/(?P<id>\d+)',
187 [
188 'methods' => WP_REST_Server::CREATABLE,
189 'callback' => $container->get(DuplicateFormController::class),
190 'permission_callback' => function () {
191 return current_user_can('manage_options');
192 }
193 ]
194 );
195
196 // Bulk update forms
197 register_rest_route(
198 $routeNamespace,
199 '/forms/batch-actions',
200 [
201 'methods' => WP_REST_Server::CREATABLE,
202 'callback' => [$container->get(BulkUpdateFormController::class), 'handle'],
203 'permission_callback' => function () {
204 return current_user_can('manage_options');
205 }
206 ]
207 );
208 }
209
210 /**
211 * Register form submission routes (public-facing)
212 *
213 * @throws DependencyException
214 * @throws NotFoundException
215 */
216 private static function registerFormSubmissionRoutes(Container $container, string $routeNamespace): void
217 {
218 // Form submission (public route)
219 register_rest_route(
220 $routeNamespace,
221 '/form/submission/',
222 [
223 'methods' => WP_REST_Server::CREATABLE,
224 'callback' => $container->get(FormSubmissionController::class),
225 // TODO - Add IvyForms capability - Public use
226 'permission_callback' => '__return_true'
227 ]
228 );
229 }
230 }
231