bulk-get-entries.php
3 weeks ago
delete-entry.php
5 months ago
entry-parser.php
3 weeks ago
get-entry.php
3 weeks ago
list-entries.php
3 weeks ago
update-entry-status.php
5 months ago
get-entry.php
131 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Get Entry Ability. |
| 4 | * |
| 5 | * @package sureforms |
| 6 | * @since 2.5.2 |
| 7 | */ |
| 8 | |
| 9 | namespace SRFM\Inc\Abilities\Entries; |
| 10 | |
| 11 | use SRFM\Inc\Abilities\Abstract_Ability; |
| 12 | use SRFM\Inc\Database\Tables\Entries as EntriesTable; |
| 13 | use SRFM\Inc\Helper; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; // Exit if accessed directly. |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Get_Entry ability class. |
| 21 | * |
| 22 | * Retrieves detailed information about a specific form submission entry, |
| 23 | * including parsed form data with decoded labels. |
| 24 | * |
| 25 | * @since 2.5.2 |
| 26 | */ |
| 27 | class Get_Entry extends Abstract_Ability { |
| 28 | use Entry_Parser; |
| 29 | |
| 30 | /** |
| 31 | * Constructor. |
| 32 | * |
| 33 | * @since 2.5.2 |
| 34 | */ |
| 35 | public function __construct() { |
| 36 | $this->id = 'sureforms/get-entry'; |
| 37 | $this->label = __( 'Get Entry Details', 'sureforms' ); |
| 38 | $this->description = __( 'Retrieve detailed information about a specific SureForms form submission entry, including all submitted field data with labels.', 'sureforms' ); |
| 39 | $this->capability = 'manage_options'; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * {@inheritDoc} |
| 44 | * |
| 45 | * @since 2.5.2 |
| 46 | */ |
| 47 | public function get_annotations() { |
| 48 | return [ |
| 49 | 'readonly' => true, |
| 50 | 'destructive' => false, |
| 51 | 'idempotent' => true, |
| 52 | 'priority' => 1.0, |
| 53 | 'openWorldHint' => false, |
| 54 | ]; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritDoc} |
| 59 | * |
| 60 | * @since 2.5.2 |
| 61 | */ |
| 62 | public function get_input_schema() { |
| 63 | return [ |
| 64 | 'type' => 'object', |
| 65 | 'additionalProperties' => false, |
| 66 | 'properties' => [ |
| 67 | 'entry_id' => [ |
| 68 | 'type' => 'integer', |
| 69 | 'description' => __( 'The ID of the entry to retrieve.', 'sureforms' ), |
| 70 | ], |
| 71 | ], |
| 72 | 'required' => [ 'entry_id' ], |
| 73 | ]; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * {@inheritDoc} |
| 78 | * |
| 79 | * @since 2.5.2 |
| 80 | */ |
| 81 | public function get_output_schema() { |
| 82 | return [ |
| 83 | 'type' => 'object', |
| 84 | 'properties' => [ |
| 85 | 'id' => [ 'type' => 'integer' ], |
| 86 | 'form_id' => [ 'type' => 'integer' ], |
| 87 | 'form_name' => [ 'type' => 'string' ], |
| 88 | 'status' => [ 'type' => 'string' ], |
| 89 | 'created_at' => [ 'type' => 'string' ], |
| 90 | 'form_data' => [ |
| 91 | 'type' => 'array', |
| 92 | 'items' => [ |
| 93 | 'type' => 'object', |
| 94 | 'properties' => [ |
| 95 | 'label' => [ 'type' => 'string' ], |
| 96 | 'value' => [], |
| 97 | 'block_name' => [ 'type' => 'string' ], |
| 98 | ], |
| 99 | ], |
| 100 | ], |
| 101 | 'submission_info' => [ 'type' => 'object' ], |
| 102 | 'user' => [ 'type' => [ 'object', 'null' ] ], |
| 103 | ], |
| 104 | ]; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Execute the get-entry ability. |
| 109 | * |
| 110 | * @param array<string,mixed> $input Validated input data. |
| 111 | * @since 2.5.2 |
| 112 | * @return array<string,mixed>|\WP_Error |
| 113 | */ |
| 114 | public function execute( $input ) { |
| 115 | $entry_id = Helper::get_integer_value( $input['entry_id'] ?? 0 ); |
| 116 | $entry = EntriesTable::get( $entry_id ); |
| 117 | |
| 118 | if ( empty( $entry ) ) { |
| 119 | return new \WP_Error( |
| 120 | 'srfm_entry_not_found', |
| 121 | __( 'Entry not found.', 'sureforms' ), |
| 122 | [ 'status' => 404 ] |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | $parsed = $this->parse_entry( $entry ); |
| 127 | |
| 128 | return array_merge( [ 'id' => $entry_id ], $parsed ); |
| 129 | } |
| 130 | } |
| 131 |