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

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