PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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
← All changes | backend/src/Controllers/Entry/UpdateEntryStatusController.php +72 -0 0.6.1 → 1.5 View file →
@@ -1,0 +1,72 @@
1 +<?php
2 +
3 +/**
4 + * @copyright © Melograno Venture Studio. All rights reserved.
5 + * @licence See COPYING.md for license details.
6 + */
7 +
8 +namespace IvyForms\Controllers\Entry;
9 +
10 +use IvyForms\Common\Exceptions\ForbiddenException;
11 +use IvyForms\Common\Exceptions\InvalidArgumentException;
12 +use IvyForms\Common\Exceptions\QueryExecutionException;
13 +use IvyForms\Common\Sanitizer\Sanitizer;
14 +use IvyForms\Controllers\Controller;
15 +use IvyForms\Services\Entry\EntryService;
16 +use IvyForms\Services\Translations\BackendStrings;
17 +use WP_REST_Request;
18 +use WP_REST_Response;
19 +
20 +class UpdateEntryStatusController extends Controller
21 +{
22 + private EntryService $entryService;
23 +
24 + public function __construct(
25 + EntryService $entryService
26 + ) {
27 + $this->entryService = $entryService;
28 + }
29 +
30 + /**
31 + * @param WP_REST_Request $data
32 + *
33 + * @return WP_REST_Response
34 + *
35 + * @throws InvalidArgumentException
36 + * @throws ForbiddenException
37 + * @throws QueryExecutionException
38 + */
39 + public function handle(WP_REST_Request $data): WP_REST_Response
40 + {
41 + // Verify the nonce
42 + Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
43 +
44 + // Check if the entry data is provided
45 + if (empty($data->get_params())) {
46 + throw new InvalidArgumentException(
47 + BackendStrings::getExceptionStrings()['invalid_request_data']
48 + );
49 + }
50 +
51 + $entryId = Sanitizer::sanitizeId($data->get_params()['id']);
52 +
53 + if ($entryId <= 0) {
54 + throw new InvalidArgumentException(
55 + BackendStrings::getExceptionStrings()['invalid_entry_id']
56 + );
57 + }
58 +
59 + $status = sanitize_text_field($data->get_params()['value'] ?? '');
60 +
61 + // Update the status in the database
62 + $this->entryService->getEntryManager()->updateEntryStatus($entryId, $status);
63 +
64 + return new WP_REST_Response([
65 + 'message' => BackendStrings::getCommonStrings()['ok'],
66 + 'data' => [
67 + 'id' => $entryId,
68 + 'status' => $status,
69 + ]
70 + ], 200);
71 + }
72 +}