PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.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
← All changes | backend/src/Controllers/Entry/UpdateEntryStarredController.php +70 -0 0.6.1 → 1.5.1 View file →
@@ -1,0 +1,70 @@
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\Sanitizer\Sanitizer;
13 +use IvyForms\Controllers\Controller;
14 +use IvyForms\Services\Entry\EntryService;
15 +use IvyForms\Services\Translations\BackendStrings;
16 +use WP_REST_Request;
17 +use WP_REST_Response;
18 +
19 +class UpdateEntryStarredController extends Controller
20 +{
21 + private EntryService $entryService;
22 +
23 + public function __construct(
24 + EntryService $entryService
25 + ) {
26 + $this->entryService = $entryService;
27 + }
28 +
29 + /**
30 + * @param WP_REST_Request $data
31 + *
32 + * @return WP_REST_Response
33 + *
34 + * @throws InvalidArgumentException
35 + * @throws ForbiddenException
36 + */
37 + public function handle(WP_REST_Request $data): WP_REST_Response
38 + {
39 + // Verify the nonce
40 + Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
41 +
42 + // Check if the entry data is provided
43 + if (empty($data->get_params())) {
44 + throw new InvalidArgumentException(
45 + BackendStrings::getExceptionStrings()['invalid_request_data']
46 + );
47 + }
48 +
49 + $entryId = Sanitizer::sanitizeId($data->get_params()['id']);
50 +
51 + if ($entryId <= 0) {
52 + throw new InvalidArgumentException(
53 + BackendStrings::getExceptionStrings()['invalid_entry_id']
54 + );
55 + }
56 +
57 + $value = (bool)($data->get_params()['value']);
58 +
59 + // Update the specific attribute in the database
60 + $this->entryService->getEntryManager()->updateEntryStarred($entryId, $value);
61 +
62 + return new WP_REST_Response([
63 + 'message' => BackendStrings::getCommonStrings()['ok'],
64 + 'data' => [
65 + 'id' => $entryId,
66 + 'value' => $value,
67 + ]
68 + ], 200);
69 + }
70 +}