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

216 lines 7.0 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 DI\Container;
11 use DI\DependencyException;
12 use 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 WP_REST_Server;
25
26 class Form
27 {
28 /**
29 * @throws DependencyException
30 * @throws NotFoundException
31 */
32 public static function registerRoutes(Container $container, string $routeNamespace): void
33 {
34 self::registerFormCrudRoutes($container, $routeNamespace);
35 self::registerFormManagementRoutes($container, $routeNamespace);
36 self::registerFormSubmissionRoutes($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
195 /**
196 * Register form submission routes (public-facing)
197 *
198 * @throws DependencyException
199 * @throws NotFoundException
200 */
201 private static function registerFormSubmissionRoutes(Container $container, string $routeNamespace): void
202 {
203 // Form submission (public route)
204 register_rest_route(
205 $routeNamespace,
206 '/form/submission/',
207 [
208 'methods' => WP_REST_Server::CREATABLE,
209 'callback' => $container->get(FormSubmissionController::class),
210 // TODO - Add IvyForms capability - Public use
211 'permission_callback' => '__return_true'
212 ]
213 );
214 }
215 }
216