PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
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 1.2 1.3
ivyforms / backend / src / Controllers / Entry / UpdateEntryStarredController.php

UpdateEntryStarredController.php in The Innovative Form Builder – IvyForms 0.8, at backend/src/Controllers/Entry/UpdateEntryStarredController.php

76 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\ForbiddenException;
16 use IvyForms\Common\Exceptions\InvalidArgumentException;
17 use IvyForms\Common\Sanitizer\Sanitizer;
18 use IvyForms\Controllers\Controller;
19 use IvyForms\Services\Entry\EntryService;
20 use IvyForms\Services\Translations\BackendStrings;
21 use WP_REST_Request;
22 use WP_REST_Response;
23
24 class UpdateEntryStarredController extends Controller
25 {
26 private EntryService $entryService;
27
28 public function __construct(
29 EntryService $entryService
30 ) {
31 $this->entryService = $entryService;
32 }
33
34 /**
35 * @param WP_REST_Request $data
36 *
37 * @return WP_REST_Response
38 *
39 * @throws InvalidArgumentException
40 * @throws ForbiddenException
41 */
42 public function handle(WP_REST_Request $data): WP_REST_Response
43 {
44 // Verify the nonce
45 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
46
47 // Check if the entry data is provided
48 if (empty($data->get_params())) {
49 throw new InvalidArgumentException(
50 BackendStrings::getExceptionStrings()['invalid_request_data']
51 );
52 }
53
54 $entryId = Sanitizer::sanitizeId($data->get_params()['id']);
55
56 if ($entryId <= 0) {
57 throw new InvalidArgumentException(
58 BackendStrings::getExceptionStrings()['invalid_entry_id']
59 );
60 }
61
62 $value = (bool)($data->get_params()['value']);
63
64 // Update the specific attribute in the database
65 $this->entryService->getEntryManager()->updateEntryStarred($entryId, $value);
66
67 return new WP_REST_Response([
68 'message' => BackendStrings::getCommonStrings()['ok'],
69 'data' => [
70 'id' => $entryId,
71 'value' => $value,
72 ]
73 ], 200);
74 }
75 }
76