@@ -14,79 +14,79 @@ |
||
14 | 14 | */ |
15 | 15 | class PriceTypeConnectionResolver extends AbstractConnectionResolver |
16 | 16 | { |
17 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | - public function get_loader_name(): string |
|
19 | - { |
|
20 | - return 'espresso_priceType'; |
|
21 | - } |
|
17 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | + public function get_loader_name(): string |
|
19 | + { |
|
20 | + return 'espresso_priceType'; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return EEM_Price_Type |
|
25 | - * @throws EE_Error |
|
26 | - * @throws InvalidArgumentException |
|
27 | - * @throws InvalidDataTypeException |
|
28 | - * @throws InvalidInterfaceException |
|
29 | - * @throws ReflectionException |
|
30 | - */ |
|
31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | - public function get_query(): EEM_Price_Type |
|
33 | - { |
|
34 | - return EEM_Price_Type::instance(); |
|
35 | - } |
|
23 | + /** |
|
24 | + * @return EEM_Price_Type |
|
25 | + * @throws EE_Error |
|
26 | + * @throws InvalidArgumentException |
|
27 | + * @throws InvalidDataTypeException |
|
28 | + * @throws InvalidInterfaceException |
|
29 | + * @throws ReflectionException |
|
30 | + */ |
|
31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | + public function get_query(): EEM_Price_Type |
|
33 | + { |
|
34 | + return EEM_Price_Type::instance(); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * Return an array of item IDs from the query |
|
40 | - * |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | - public function get_ids(): array |
|
45 | - { |
|
46 | - $results = $this->query->get_col($this->query_args); |
|
38 | + /** |
|
39 | + * Return an array of item IDs from the query |
|
40 | + * |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | + public function get_ids(): array |
|
45 | + { |
|
46 | + $results = $this->query->get_col($this->query_args); |
|
47 | 47 | |
48 | - return ! empty($results) ? $results : []; |
|
49 | - } |
|
48 | + return ! empty($results) ? $results : []; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
54 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
55 | - * handle batch resolution of the posts. |
|
56 | - * |
|
57 | - * @return array |
|
58 | - * @throws InvalidArgumentException |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - * @throws InvalidInterfaceException |
|
61 | - */ |
|
62 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
63 | - public function get_query_args(): array |
|
64 | - { |
|
65 | - $where_params = []; |
|
66 | - $query_args = []; |
|
52 | + /** |
|
53 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
54 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
55 | + * handle batch resolution of the posts. |
|
56 | + * |
|
57 | + * @return array |
|
58 | + * @throws InvalidArgumentException |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + * @throws InvalidInterfaceException |
|
61 | + */ |
|
62 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
63 | + public function get_query_args(): array |
|
64 | + { |
|
65 | + $where_params = []; |
|
66 | + $query_args = []; |
|
67 | 67 | |
68 | - $query_args['limit'] = $this->getLimit(); |
|
68 | + $query_args['limit'] = $this->getLimit(); |
|
69 | 69 | |
70 | - // Avoid multiple entries by join. |
|
71 | - $query_args['group_by'] = 'PRT_ID'; |
|
70 | + // Avoid multiple entries by join. |
|
71 | + $query_args['group_by'] = 'PRT_ID'; |
|
72 | 72 | |
73 | - $where_params = apply_filters( |
|
74 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_where_params', |
|
75 | - $where_params, |
|
76 | - $this->source, |
|
77 | - $this->args |
|
78 | - ); |
|
73 | + $where_params = apply_filters( |
|
74 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_where_params', |
|
75 | + $where_params, |
|
76 | + $this->source, |
|
77 | + $this->args |
|
78 | + ); |
|
79 | 79 | |
80 | - $query_args[] = $where_params; |
|
80 | + $query_args[] = $where_params; |
|
81 | 81 | |
82 | - /** |
|
83 | - * Return the $query_args |
|
84 | - */ |
|
85 | - return apply_filters( |
|
86 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_query_args', |
|
87 | - $query_args, |
|
88 | - $this->source, |
|
89 | - $this->args |
|
90 | - ); |
|
91 | - } |
|
82 | + /** |
|
83 | + * Return the $query_args |
|
84 | + */ |
|
85 | + return apply_filters( |
|
86 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__priceType_query_args', |
|
87 | + $query_args, |
|
88 | + $this->source, |
|
89 | + $this->args |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | } |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function __construct() |
92 | 92 | { |
93 | - if (! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
93 | + if ( ! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
94 | 94 | define('JSON_INVALID_UTF8_IGNORE', 1048576); |
95 | 95 | } |
96 | - if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
96 | + if ( ! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
97 | 97 | define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152); |
98 | 98 | } |
99 | - if (! defined('JSON_THROW_ON_ERROR')) { |
|
99 | + if ( ! defined('JSON_THROW_ON_ERROR')) { |
|
100 | 100 | define('JSON_THROW_ON_ERROR', 4194304); |
101 | 101 | } |
102 | 102 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public function isJson($maybe_json): bool |
333 | 333 | { |
334 | - if (! is_string($maybe_json)) { |
|
334 | + if ( ! is_string($maybe_json)) { |
|
335 | 335 | return false; |
336 | 336 | } |
337 | 337 | $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags); |
@@ -14,331 +14,331 @@ |
||
14 | 14 | */ |
15 | 15 | class JsonDataHandler |
16 | 16 | { |
17 | - const DATA_TYPE_ARRAY = 'array'; |
|
18 | - |
|
19 | - const DATA_TYPE_OBJECT = 'object'; |
|
20 | - |
|
21 | - const DATA_TYPE_USE_FLAGS = 'flags'; |
|
22 | - |
|
23 | - const NO_ERROR_MSG = 'No error'; |
|
24 | - |
|
25 | - private string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array|stdClass|null |
|
29 | - */ |
|
30 | - private $decoded_data = null; |
|
31 | - |
|
32 | - /** |
|
33 | - * JSON_BIGINT_AS_STRING, |
|
34 | - * JSON_INVALID_UTF8_IGNORE, |
|
35 | - * JSON_INVALID_UTF8_SUBSTITUTE, |
|
36 | - * JSON_OBJECT_AS_ARRAY, |
|
37 | - * JSON_THROW_ON_ERROR |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - private int $decode_flags = 0; |
|
42 | - |
|
43 | - private int $depth = 512; |
|
44 | - |
|
45 | - private string $encoded_data = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * JSON_FORCE_OBJECT, |
|
49 | - * JSON_HEX_QUOT, |
|
50 | - * JSON_HEX_TAG, |
|
51 | - * JSON_HEX_AMP, |
|
52 | - * JSON_HEX_APOS, |
|
53 | - * JSON_INVALID_UTF8_IGNORE, |
|
54 | - * JSON_INVALID_UTF8_SUBSTITUTE, |
|
55 | - * JSON_NUMERIC_CHECK, |
|
56 | - * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
57 | - * JSON_PRESERVE_ZERO_FRACTION, |
|
58 | - * JSON_PRETTY_PRINT, |
|
59 | - * JSON_UNESCAPED_LINE_TERMINATORS, |
|
60 | - * JSON_UNESCAPED_SLASHES, |
|
61 | - * JSON_UNESCAPED_UNICODE, |
|
62 | - * JSON_THROW_ON_ERROR. |
|
63 | - * |
|
64 | - * @var int |
|
65 | - */ |
|
66 | - private int $encode_flags = 0; |
|
67 | - |
|
68 | - private int $last_error_code = JSON_ERROR_NONE; |
|
69 | - |
|
70 | - private string $last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * JsonDataHandler constructor. |
|
75 | - */ |
|
76 | - public function __construct() |
|
77 | - { |
|
78 | - if (! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
79 | - define('JSON_INVALID_UTF8_IGNORE', 1048576); |
|
80 | - } |
|
81 | - if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
82 | - define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152); |
|
83 | - } |
|
84 | - if (! defined('JSON_THROW_ON_ERROR')) { |
|
85 | - define('JSON_THROW_ON_ERROR', 4194304); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * set $data_type, $decode_flags, $encode_flags, and depth all in one shot |
|
92 | - * |
|
93 | - * @param string $data_type |
|
94 | - * @param int $decode_flags |
|
95 | - * @param int $encode_flags |
|
96 | - * @param int $depth |
|
97 | - */ |
|
98 | - public function configure( |
|
99 | - string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS, |
|
100 | - int $decode_flags = 0, |
|
101 | - int $encode_flags = 0, |
|
102 | - int $depth = 512 |
|
103 | - ) { |
|
104 | - $this->setDataType($data_type); |
|
105 | - $this->setDecodeFlags($decode_flags); |
|
106 | - $this->setDepth($depth); |
|
107 | - $this->setEncodeFlags($encode_flags); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param string $data_type |
|
113 | - */ |
|
114 | - public function setDataType(string $data_type): void |
|
115 | - { |
|
116 | - $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY |
|
117 | - || $data_type === JsonDataHandler::DATA_TYPE_OBJECT |
|
118 | - || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS |
|
119 | - ? $data_type |
|
120 | - : JsonDataHandler::DATA_TYPE_USE_FLAGS; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * One or more Bitmask values: |
|
126 | - * JSON_BIGINT_AS_STRING, |
|
127 | - * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
128 | - * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
129 | - * JSON_OBJECT_AS_ARRAY, |
|
130 | - * JSON_THROW_ON_ERROR PHP >= 7.3 |
|
131 | - * |
|
132 | - * pass multiple values separated with | |
|
133 | - * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY |
|
134 | - * |
|
135 | - * @param int $decode_flags |
|
136 | - */ |
|
137 | - public function setDecodeFlags(int $decode_flags): void |
|
138 | - { |
|
139 | - $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING |
|
140 | - || $decode_flags === JSON_OBJECT_AS_ARRAY |
|
141 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
142 | - || $decode_flags === JSON_INVALID_UTF8_IGNORE |
|
143 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
144 | - || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
145 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
146 | - || $decode_flags === JSON_THROW_ON_ERROR |
|
147 | - ? $decode_flags |
|
148 | - : 0; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param int $depth |
|
154 | - */ |
|
155 | - public function setDepth(int $depth): void |
|
156 | - { |
|
157 | - $depth = absint($depth); |
|
158 | - $this->depth = $depth ?: 512; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * One or more Bitmask values: |
|
164 | - * JSON_FORCE_OBJECT, |
|
165 | - * JSON_HEX_QUOT, |
|
166 | - * JSON_HEX_TAG, |
|
167 | - * JSON_HEX_AMP, |
|
168 | - * JSON_HEX_APOS, |
|
169 | - * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
170 | - * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
171 | - * JSON_NUMERIC_CHECK, |
|
172 | - * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
173 | - * JSON_PRESERVE_ZERO_FRACTION, |
|
174 | - * JSON_PRETTY_PRINT, |
|
175 | - * JSON_UNESCAPED_LINE_TERMINATORS, |
|
176 | - * JSON_UNESCAPED_SLASHES, |
|
177 | - * JSON_UNESCAPED_UNICODE, |
|
178 | - * JSON_THROW_ON_ERROR. PHP >= 7.3 |
|
179 | - * |
|
180 | - * pass multiple values separated with | |
|
181 | - * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR |
|
182 | - * |
|
183 | - * @param int $encode_flags |
|
184 | - */ |
|
185 | - public function setEncodeFlags(int $encode_flags): void |
|
186 | - { |
|
187 | - $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT |
|
188 | - || $encode_flags === JSON_HEX_QUOT |
|
189 | - || $encode_flags === JSON_HEX_TAG |
|
190 | - || $encode_flags === JSON_HEX_AMP |
|
191 | - || $encode_flags === JSON_HEX_APOS |
|
192 | - || $encode_flags === JSON_NUMERIC_CHECK |
|
193 | - || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR |
|
194 | - || $encode_flags === JSON_PRESERVE_ZERO_FRACTION |
|
195 | - || $encode_flags === JSON_PRETTY_PRINT |
|
196 | - || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS |
|
197 | - || $encode_flags === JSON_UNESCAPED_SLASHES |
|
198 | - || $encode_flags === JSON_UNESCAPED_UNICODE |
|
199 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
200 | - || $encode_flags === JSON_INVALID_UTF8_IGNORE |
|
201 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
202 | - || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
203 | - // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
204 | - || $encode_flags === JSON_THROW_ON_ERROR |
|
205 | - ? $encode_flags |
|
206 | - : 0; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @return string|null |
|
212 | - */ |
|
213 | - public function dataType(): ?string |
|
214 | - { |
|
215 | - return $this->data_type; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * @return bool|null |
|
221 | - */ |
|
222 | - private function asAssociative(): ?bool |
|
223 | - { |
|
224 | - switch ($this->data_type) { |
|
225 | - case JsonDataHandler::DATA_TYPE_ARRAY: |
|
226 | - return true; |
|
227 | - case JsonDataHandler::DATA_TYPE_OBJECT: |
|
228 | - return false; |
|
229 | - case JsonDataHandler::DATA_TYPE_USE_FLAGS: |
|
230 | - return null; |
|
231 | - } |
|
232 | - return null; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @param array|string $json |
|
238 | - * @return array|mixed|stdClass |
|
239 | - */ |
|
240 | - public function decodeJson($json) |
|
241 | - { |
|
242 | - $this->resetErrors(); |
|
243 | - if ($this->isJson($json)) { |
|
244 | - $this->decoded_data = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
245 | - $this->last_error_code = json_last_error(); |
|
246 | - $this->last_error_msg = json_last_error_msg(); |
|
247 | - } else { |
|
248 | - $this->decoded_data = $json; |
|
249 | - $this->last_error_code = JSON_ERROR_NONE; |
|
250 | - $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
251 | - } |
|
252 | - return $this->decoded_data; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @param $data |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function encodeData($data): string |
|
261 | - { |
|
262 | - $this->resetErrors(); |
|
263 | - if ($this->isJson($data)) { |
|
264 | - $this->encoded_data = $data; |
|
265 | - $this->last_error_code = JSON_ERROR_NONE; |
|
266 | - $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
267 | - } else { |
|
268 | - $this->encoded_data = json_encode($data, $this->encode_flags, $this->depth); |
|
269 | - $this->last_error_code = json_last_error(); |
|
270 | - $this->last_error_msg = json_last_error_msg(); |
|
271 | - } |
|
272 | - return $this->encoded_data ?: '{}'; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * @return array|stdClass |
|
278 | - */ |
|
279 | - public function getDecodedData() |
|
280 | - { |
|
281 | - return $this->decoded_data; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function getEncodedData(): string |
|
289 | - { |
|
290 | - return $this->encoded_data; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param bool $reset |
|
296 | - * @return int |
|
297 | - */ |
|
298 | - public function getLastErrorCode(bool $reset = false): int |
|
299 | - { |
|
300 | - $last_error = $this->last_error_code; |
|
301 | - if ($reset) { |
|
302 | - $this->resetErrors(); |
|
303 | - } |
|
304 | - return $last_error; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @param bool $reset |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function getLastErrorMessage(bool $reset = false): string |
|
313 | - { |
|
314 | - $last_error = $this->last_error_msg; |
|
315 | - if ($reset) { |
|
316 | - $this->resetErrors(); |
|
317 | - } |
|
318 | - return $last_error; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @param array|string $maybe_json |
|
324 | - * @return bool |
|
325 | - */ |
|
326 | - public function isJson($maybe_json): bool |
|
327 | - { |
|
328 | - if (! is_string($maybe_json)) { |
|
329 | - return false; |
|
330 | - } |
|
331 | - $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
332 | - return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json)); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @since 5.0.0.p |
|
338 | - */ |
|
339 | - public function resetErrors() |
|
340 | - { |
|
341 | - $this->last_error_code = JSON_ERROR_NONE; |
|
342 | - $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
343 | - } |
|
17 | + const DATA_TYPE_ARRAY = 'array'; |
|
18 | + |
|
19 | + const DATA_TYPE_OBJECT = 'object'; |
|
20 | + |
|
21 | + const DATA_TYPE_USE_FLAGS = 'flags'; |
|
22 | + |
|
23 | + const NO_ERROR_MSG = 'No error'; |
|
24 | + |
|
25 | + private string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array|stdClass|null |
|
29 | + */ |
|
30 | + private $decoded_data = null; |
|
31 | + |
|
32 | + /** |
|
33 | + * JSON_BIGINT_AS_STRING, |
|
34 | + * JSON_INVALID_UTF8_IGNORE, |
|
35 | + * JSON_INVALID_UTF8_SUBSTITUTE, |
|
36 | + * JSON_OBJECT_AS_ARRAY, |
|
37 | + * JSON_THROW_ON_ERROR |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + private int $decode_flags = 0; |
|
42 | + |
|
43 | + private int $depth = 512; |
|
44 | + |
|
45 | + private string $encoded_data = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * JSON_FORCE_OBJECT, |
|
49 | + * JSON_HEX_QUOT, |
|
50 | + * JSON_HEX_TAG, |
|
51 | + * JSON_HEX_AMP, |
|
52 | + * JSON_HEX_APOS, |
|
53 | + * JSON_INVALID_UTF8_IGNORE, |
|
54 | + * JSON_INVALID_UTF8_SUBSTITUTE, |
|
55 | + * JSON_NUMERIC_CHECK, |
|
56 | + * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
57 | + * JSON_PRESERVE_ZERO_FRACTION, |
|
58 | + * JSON_PRETTY_PRINT, |
|
59 | + * JSON_UNESCAPED_LINE_TERMINATORS, |
|
60 | + * JSON_UNESCAPED_SLASHES, |
|
61 | + * JSON_UNESCAPED_UNICODE, |
|
62 | + * JSON_THROW_ON_ERROR. |
|
63 | + * |
|
64 | + * @var int |
|
65 | + */ |
|
66 | + private int $encode_flags = 0; |
|
67 | + |
|
68 | + private int $last_error_code = JSON_ERROR_NONE; |
|
69 | + |
|
70 | + private string $last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * JsonDataHandler constructor. |
|
75 | + */ |
|
76 | + public function __construct() |
|
77 | + { |
|
78 | + if (! defined('JSON_INVALID_UTF8_IGNORE')) { |
|
79 | + define('JSON_INVALID_UTF8_IGNORE', 1048576); |
|
80 | + } |
|
81 | + if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) { |
|
82 | + define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152); |
|
83 | + } |
|
84 | + if (! defined('JSON_THROW_ON_ERROR')) { |
|
85 | + define('JSON_THROW_ON_ERROR', 4194304); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * set $data_type, $decode_flags, $encode_flags, and depth all in one shot |
|
92 | + * |
|
93 | + * @param string $data_type |
|
94 | + * @param int $decode_flags |
|
95 | + * @param int $encode_flags |
|
96 | + * @param int $depth |
|
97 | + */ |
|
98 | + public function configure( |
|
99 | + string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS, |
|
100 | + int $decode_flags = 0, |
|
101 | + int $encode_flags = 0, |
|
102 | + int $depth = 512 |
|
103 | + ) { |
|
104 | + $this->setDataType($data_type); |
|
105 | + $this->setDecodeFlags($decode_flags); |
|
106 | + $this->setDepth($depth); |
|
107 | + $this->setEncodeFlags($encode_flags); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param string $data_type |
|
113 | + */ |
|
114 | + public function setDataType(string $data_type): void |
|
115 | + { |
|
116 | + $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY |
|
117 | + || $data_type === JsonDataHandler::DATA_TYPE_OBJECT |
|
118 | + || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS |
|
119 | + ? $data_type |
|
120 | + : JsonDataHandler::DATA_TYPE_USE_FLAGS; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * One or more Bitmask values: |
|
126 | + * JSON_BIGINT_AS_STRING, |
|
127 | + * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
128 | + * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
129 | + * JSON_OBJECT_AS_ARRAY, |
|
130 | + * JSON_THROW_ON_ERROR PHP >= 7.3 |
|
131 | + * |
|
132 | + * pass multiple values separated with | |
|
133 | + * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY |
|
134 | + * |
|
135 | + * @param int $decode_flags |
|
136 | + */ |
|
137 | + public function setDecodeFlags(int $decode_flags): void |
|
138 | + { |
|
139 | + $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING |
|
140 | + || $decode_flags === JSON_OBJECT_AS_ARRAY |
|
141 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
142 | + || $decode_flags === JSON_INVALID_UTF8_IGNORE |
|
143 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
144 | + || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
145 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
146 | + || $decode_flags === JSON_THROW_ON_ERROR |
|
147 | + ? $decode_flags |
|
148 | + : 0; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param int $depth |
|
154 | + */ |
|
155 | + public function setDepth(int $depth): void |
|
156 | + { |
|
157 | + $depth = absint($depth); |
|
158 | + $this->depth = $depth ?: 512; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * One or more Bitmask values: |
|
164 | + * JSON_FORCE_OBJECT, |
|
165 | + * JSON_HEX_QUOT, |
|
166 | + * JSON_HEX_TAG, |
|
167 | + * JSON_HEX_AMP, |
|
168 | + * JSON_HEX_APOS, |
|
169 | + * JSON_INVALID_UTF8_IGNORE, PHP >= 7.2 |
|
170 | + * JSON_INVALID_UTF8_SUBSTITUTE, PHP >= 7.2 |
|
171 | + * JSON_NUMERIC_CHECK, |
|
172 | + * JSON_PARTIAL_OUTPUT_ON_ERROR, |
|
173 | + * JSON_PRESERVE_ZERO_FRACTION, |
|
174 | + * JSON_PRETTY_PRINT, |
|
175 | + * JSON_UNESCAPED_LINE_TERMINATORS, |
|
176 | + * JSON_UNESCAPED_SLASHES, |
|
177 | + * JSON_UNESCAPED_UNICODE, |
|
178 | + * JSON_THROW_ON_ERROR. PHP >= 7.3 |
|
179 | + * |
|
180 | + * pass multiple values separated with | |
|
181 | + * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR |
|
182 | + * |
|
183 | + * @param int $encode_flags |
|
184 | + */ |
|
185 | + public function setEncodeFlags(int $encode_flags): void |
|
186 | + { |
|
187 | + $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT |
|
188 | + || $encode_flags === JSON_HEX_QUOT |
|
189 | + || $encode_flags === JSON_HEX_TAG |
|
190 | + || $encode_flags === JSON_HEX_AMP |
|
191 | + || $encode_flags === JSON_HEX_APOS |
|
192 | + || $encode_flags === JSON_NUMERIC_CHECK |
|
193 | + || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR |
|
194 | + || $encode_flags === JSON_PRESERVE_ZERO_FRACTION |
|
195 | + || $encode_flags === JSON_PRETTY_PRINT |
|
196 | + || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS |
|
197 | + || $encode_flags === JSON_UNESCAPED_SLASHES |
|
198 | + || $encode_flags === JSON_UNESCAPED_UNICODE |
|
199 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound |
|
200 | + || $encode_flags === JSON_INVALID_UTF8_IGNORE |
|
201 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound |
|
202 | + || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE |
|
203 | + // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound |
|
204 | + || $encode_flags === JSON_THROW_ON_ERROR |
|
205 | + ? $encode_flags |
|
206 | + : 0; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @return string|null |
|
212 | + */ |
|
213 | + public function dataType(): ?string |
|
214 | + { |
|
215 | + return $this->data_type; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * @return bool|null |
|
221 | + */ |
|
222 | + private function asAssociative(): ?bool |
|
223 | + { |
|
224 | + switch ($this->data_type) { |
|
225 | + case JsonDataHandler::DATA_TYPE_ARRAY: |
|
226 | + return true; |
|
227 | + case JsonDataHandler::DATA_TYPE_OBJECT: |
|
228 | + return false; |
|
229 | + case JsonDataHandler::DATA_TYPE_USE_FLAGS: |
|
230 | + return null; |
|
231 | + } |
|
232 | + return null; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @param array|string $json |
|
238 | + * @return array|mixed|stdClass |
|
239 | + */ |
|
240 | + public function decodeJson($json) |
|
241 | + { |
|
242 | + $this->resetErrors(); |
|
243 | + if ($this->isJson($json)) { |
|
244 | + $this->decoded_data = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
245 | + $this->last_error_code = json_last_error(); |
|
246 | + $this->last_error_msg = json_last_error_msg(); |
|
247 | + } else { |
|
248 | + $this->decoded_data = $json; |
|
249 | + $this->last_error_code = JSON_ERROR_NONE; |
|
250 | + $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
251 | + } |
|
252 | + return $this->decoded_data; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @param $data |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function encodeData($data): string |
|
261 | + { |
|
262 | + $this->resetErrors(); |
|
263 | + if ($this->isJson($data)) { |
|
264 | + $this->encoded_data = $data; |
|
265 | + $this->last_error_code = JSON_ERROR_NONE; |
|
266 | + $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
267 | + } else { |
|
268 | + $this->encoded_data = json_encode($data, $this->encode_flags, $this->depth); |
|
269 | + $this->last_error_code = json_last_error(); |
|
270 | + $this->last_error_msg = json_last_error_msg(); |
|
271 | + } |
|
272 | + return $this->encoded_data ?: '{}'; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * @return array|stdClass |
|
278 | + */ |
|
279 | + public function getDecodedData() |
|
280 | + { |
|
281 | + return $this->decoded_data; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function getEncodedData(): string |
|
289 | + { |
|
290 | + return $this->encoded_data; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param bool $reset |
|
296 | + * @return int |
|
297 | + */ |
|
298 | + public function getLastErrorCode(bool $reset = false): int |
|
299 | + { |
|
300 | + $last_error = $this->last_error_code; |
|
301 | + if ($reset) { |
|
302 | + $this->resetErrors(); |
|
303 | + } |
|
304 | + return $last_error; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @param bool $reset |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function getLastErrorMessage(bool $reset = false): string |
|
313 | + { |
|
314 | + $last_error = $this->last_error_msg; |
|
315 | + if ($reset) { |
|
316 | + $this->resetErrors(); |
|
317 | + } |
|
318 | + return $last_error; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @param array|string $maybe_json |
|
324 | + * @return bool |
|
325 | + */ |
|
326 | + public function isJson($maybe_json): bool |
|
327 | + { |
|
328 | + if (! is_string($maybe_json)) { |
|
329 | + return false; |
|
330 | + } |
|
331 | + $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags); |
|
332 | + return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json)); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @since 5.0.0.p |
|
338 | + */ |
|
339 | + public function resetErrors() |
|
340 | + { |
|
341 | + $this->last_error_code = JSON_ERROR_NONE; |
|
342 | + $this->last_error_msg = JsonDataHandler::NO_ERROR_MSG; |
|
343 | + } |
|
344 | 344 | } |
@@ -5,152 +5,152 @@ |
||
5 | 5 | class EE_Form_Submission extends EE_Base_Class |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @param array $props_n_values |
|
10 | - * @return EE_Form_Submission |
|
11 | - * @throws EE_Error |
|
12 | - * @throws ReflectionException |
|
13 | - */ |
|
14 | - public static function new_instance(array $props_n_values = []): EE_Form_Submission |
|
15 | - { |
|
16 | - $props_n_values['FSB_submitted'] = new DateTime(); |
|
17 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
18 | - return $has_object ?: new self($props_n_values); |
|
19 | - } |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param array $props_n_values |
|
24 | - * @return EE_Form_Submission |
|
25 | - * @throws EE_Error |
|
26 | - * @throws ReflectionException |
|
27 | - */ |
|
28 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Submission |
|
29 | - { |
|
30 | - return new self($props_n_values, true); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Form Section UUID (universally unique identifier) |
|
36 | - * |
|
37 | - * @return string |
|
38 | - * @throws EE_Error |
|
39 | - * @throws ReflectionException |
|
40 | - */ |
|
41 | - public function UUID(): string |
|
42 | - { |
|
43 | - return $this->get('FSB_UUID'); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param string $UUID |
|
49 | - * @throws EE_Error |
|
50 | - * @throws ReflectionException |
|
51 | - */ |
|
52 | - public function setUUID(string $UUID) |
|
53 | - { |
|
54 | - $this->set('FSB_UUID', $UUID); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * UUID or ID of related entity this form submission belongs to. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - * @throws EE_Error |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - public function formSection(): string |
|
66 | - { |
|
67 | - return $this->get('FSC_UUID'); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $form_section_UUID |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - public function setFormSection(string $form_section_UUID) |
|
77 | - { |
|
78 | - $this->set('FSC_UUID', $form_section_UUID); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns the related EE_Transaction this form submission belongs to. |
|
84 | - * |
|
85 | - * @return EE_Transaction |
|
86 | - * @throws EE_Error |
|
87 | - * @throws EntityNotFoundException |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - public function transaction(): EE_Transaction |
|
91 | - { |
|
92 | - $transaction = $this->get_first_related('Transaction'); |
|
93 | - if (! $transaction instanceof EE_Transaction) { |
|
94 | - throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
|
95 | - } |
|
96 | - return $transaction; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return int |
|
102 | - * @throws EE_Error |
|
103 | - * @throws ReflectionException |
|
104 | - */ |
|
105 | - public function transactionID(): int |
|
106 | - { |
|
107 | - return $this->get('TXN_ID'); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param int $TXN_ID |
|
113 | - * @throws EE_Error |
|
114 | - * @throws ReflectionException |
|
115 | - */ |
|
116 | - public function setTransactionID(int $TXN_ID = 0) |
|
117 | - { |
|
118 | - $this->set('TXN_ID', $TXN_ID); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return mixed |
|
124 | - * @throws EE_Error |
|
125 | - * @throws ReflectionException |
|
126 | - */ |
|
127 | - public function data() |
|
128 | - { |
|
129 | - return $this->get('FSB_data'); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param array|string $data |
|
135 | - * @throws EE_Error |
|
136 | - * @throws ReflectionException |
|
137 | - */ |
|
138 | - public function setData($data) |
|
139 | - { |
|
140 | - $this->set('FSB_data', $data); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param bool $raw |
|
146 | - * @return int |
|
147 | - * @throws EE_Error |
|
148 | - * @throws ReflectionException |
|
149 | - */ |
|
150 | - public function submitted(bool $raw = false): int |
|
151 | - { |
|
152 | - return $raw |
|
153 | - ? $this->get_raw('FSB_submitted') |
|
154 | - : $this->get('FSB_submitted'); |
|
155 | - } |
|
8 | + /** |
|
9 | + * @param array $props_n_values |
|
10 | + * @return EE_Form_Submission |
|
11 | + * @throws EE_Error |
|
12 | + * @throws ReflectionException |
|
13 | + */ |
|
14 | + public static function new_instance(array $props_n_values = []): EE_Form_Submission |
|
15 | + { |
|
16 | + $props_n_values['FSB_submitted'] = new DateTime(); |
|
17 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
18 | + return $has_object ?: new self($props_n_values); |
|
19 | + } |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param array $props_n_values |
|
24 | + * @return EE_Form_Submission |
|
25 | + * @throws EE_Error |
|
26 | + * @throws ReflectionException |
|
27 | + */ |
|
28 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Submission |
|
29 | + { |
|
30 | + return new self($props_n_values, true); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Form Section UUID (universally unique identifier) |
|
36 | + * |
|
37 | + * @return string |
|
38 | + * @throws EE_Error |
|
39 | + * @throws ReflectionException |
|
40 | + */ |
|
41 | + public function UUID(): string |
|
42 | + { |
|
43 | + return $this->get('FSB_UUID'); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param string $UUID |
|
49 | + * @throws EE_Error |
|
50 | + * @throws ReflectionException |
|
51 | + */ |
|
52 | + public function setUUID(string $UUID) |
|
53 | + { |
|
54 | + $this->set('FSB_UUID', $UUID); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * UUID or ID of related entity this form submission belongs to. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + * @throws EE_Error |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + public function formSection(): string |
|
66 | + { |
|
67 | + return $this->get('FSC_UUID'); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $form_section_UUID |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + public function setFormSection(string $form_section_UUID) |
|
77 | + { |
|
78 | + $this->set('FSC_UUID', $form_section_UUID); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns the related EE_Transaction this form submission belongs to. |
|
84 | + * |
|
85 | + * @return EE_Transaction |
|
86 | + * @throws EE_Error |
|
87 | + * @throws EntityNotFoundException |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + public function transaction(): EE_Transaction |
|
91 | + { |
|
92 | + $transaction = $this->get_first_related('Transaction'); |
|
93 | + if (! $transaction instanceof EE_Transaction) { |
|
94 | + throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
|
95 | + } |
|
96 | + return $transaction; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return int |
|
102 | + * @throws EE_Error |
|
103 | + * @throws ReflectionException |
|
104 | + */ |
|
105 | + public function transactionID(): int |
|
106 | + { |
|
107 | + return $this->get('TXN_ID'); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param int $TXN_ID |
|
113 | + * @throws EE_Error |
|
114 | + * @throws ReflectionException |
|
115 | + */ |
|
116 | + public function setTransactionID(int $TXN_ID = 0) |
|
117 | + { |
|
118 | + $this->set('TXN_ID', $TXN_ID); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return mixed |
|
124 | + * @throws EE_Error |
|
125 | + * @throws ReflectionException |
|
126 | + */ |
|
127 | + public function data() |
|
128 | + { |
|
129 | + return $this->get('FSB_data'); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param array|string $data |
|
135 | + * @throws EE_Error |
|
136 | + * @throws ReflectionException |
|
137 | + */ |
|
138 | + public function setData($data) |
|
139 | + { |
|
140 | + $this->set('FSB_data', $data); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param bool $raw |
|
146 | + * @return int |
|
147 | + * @throws EE_Error |
|
148 | + * @throws ReflectionException |
|
149 | + */ |
|
150 | + public function submitted(bool $raw = false): int |
|
151 | + { |
|
152 | + return $raw |
|
153 | + ? $this->get_raw('FSB_submitted') |
|
154 | + : $this->get('FSB_submitted'); |
|
155 | + } |
|
156 | 156 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | public function transaction(): EE_Transaction |
91 | 91 | { |
92 | 92 | $transaction = $this->get_first_related('Transaction'); |
93 | - if (! $transaction instanceof EE_Transaction) { |
|
93 | + if ( ! $transaction instanceof EE_Transaction) { |
|
94 | 94 | throw new EntityNotFoundException('Transaction ID', $this->transactionID()); |
95 | 95 | } |
96 | 96 | return $transaction; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public function addHtmlClass(string $htmlClass): void |
132 | 132 | { |
133 | 133 | $htmlClass = sanitize_key($htmlClass); |
134 | - if (! in_array($htmlClass, $this->htmlClasses, true)) { |
|
134 | + if ( ! in_array($htmlClass, $this->htmlClasses, true)) { |
|
135 | 135 | $this->htmlClasses[] = $htmlClass; |
136 | 136 | } |
137 | 137 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function removeHtmlClass(string $htmlClass): void |
144 | 144 | { |
145 | 145 | $htmlClass = sanitize_key($htmlClass); |
146 | - unset($this->htmlClasses[ $htmlClass ]); |
|
146 | + unset($this->htmlClasses[$htmlClass]); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 |
@@ -14,141 +14,141 @@ |
||
14 | 14 | */ |
15 | 15 | class HelpText implements JsonableInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * @var JsonDataHandler |
|
19 | - */ |
|
20 | - private $json_data_handler; |
|
21 | - |
|
22 | - /** |
|
23 | - * Additional text displayed alongside a form input to assist users with completing the form. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - private $helpText; |
|
28 | - |
|
29 | - /** |
|
30 | - * Custom HTML classes to be applied to this form input's help text. |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - private $htmlClasses; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * HelpText constructor. |
|
39 | - * |
|
40 | - * @param JsonDataHandler $json_data_handler |
|
41 | - * @param array $htmlClass |
|
42 | - * @param string $helpText |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - JsonDataHandler $json_data_handler, |
|
46 | - array $htmlClass, |
|
47 | - string $helpText |
|
48 | - ) { |
|
49 | - $this->json_data_handler = $json_data_handler; |
|
50 | - $this->setHtmlClasses($htmlClass); |
|
51 | - $this->setHelpText($helpText); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $json |
|
57 | - * @return HelpText |
|
58 | - */ |
|
59 | - public static function fromJson(string $json): HelpText |
|
60 | - { |
|
61 | - $json_data_handler = new JsonDataHandler(); |
|
62 | - $json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT); |
|
63 | - $data = $json_data_handler->decodeJson($json); |
|
64 | - $htmlClass = (array) ($data->htmlClass ?? []); |
|
65 | - $helpText = $data->helpText ?? ''; |
|
66 | - return new HelpText($json_data_handler, $htmlClass, $helpText); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function toArray(): array |
|
74 | - { |
|
75 | - return [ |
|
76 | - 'helpText' => $this->helpText, |
|
77 | - 'htmlClass' => $this->htmlClasses(), |
|
78 | - ]; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function toJson(): string |
|
86 | - { |
|
87 | - return $this->json_data_handler->encodeData($this->toArray()); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Input label displayed on public forms, ie: the actual question text. |
|
93 | - * |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function helpText(): string |
|
97 | - { |
|
98 | - return $this->helpText; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @param string $helpText |
|
104 | - */ |
|
105 | - public function setHelpText(string $helpText): void |
|
106 | - { |
|
107 | - $this->helpText = sanitize_text_field($helpText); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Custom HTML classes to be applied to this form input's help text. |
|
113 | - * returns a concatenated string unless $as_array is set to true |
|
114 | - * |
|
115 | - * @return array|string |
|
116 | - */ |
|
117 | - public function htmlClasses($as_array = false) |
|
118 | - { |
|
119 | - return $as_array |
|
120 | - ? $this->htmlClasses |
|
121 | - : implode(' ', $this->htmlClasses); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $htmlClass |
|
127 | - */ |
|
128 | - public function addHtmlClass(string $htmlClass): void |
|
129 | - { |
|
130 | - $htmlClass = sanitize_key($htmlClass); |
|
131 | - if (! in_array($htmlClass, $this->htmlClasses, true)) { |
|
132 | - $this->htmlClasses[] = $htmlClass; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $htmlClass |
|
139 | - */ |
|
140 | - public function removeHtmlClass(string $htmlClass): void |
|
141 | - { |
|
142 | - $htmlClass = sanitize_key($htmlClass); |
|
143 | - unset($this->htmlClasses[ $htmlClass ]); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @param array $htmlClasses |
|
149 | - */ |
|
150 | - public function setHtmlClasses(array $htmlClasses): void |
|
151 | - { |
|
152 | - $this->htmlClasses = array_map('sanitize_key', $htmlClasses); |
|
153 | - } |
|
17 | + /** |
|
18 | + * @var JsonDataHandler |
|
19 | + */ |
|
20 | + private $json_data_handler; |
|
21 | + |
|
22 | + /** |
|
23 | + * Additional text displayed alongside a form input to assist users with completing the form. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + private $helpText; |
|
28 | + |
|
29 | + /** |
|
30 | + * Custom HTML classes to be applied to this form input's help text. |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + private $htmlClasses; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * HelpText constructor. |
|
39 | + * |
|
40 | + * @param JsonDataHandler $json_data_handler |
|
41 | + * @param array $htmlClass |
|
42 | + * @param string $helpText |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + JsonDataHandler $json_data_handler, |
|
46 | + array $htmlClass, |
|
47 | + string $helpText |
|
48 | + ) { |
|
49 | + $this->json_data_handler = $json_data_handler; |
|
50 | + $this->setHtmlClasses($htmlClass); |
|
51 | + $this->setHelpText($helpText); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $json |
|
57 | + * @return HelpText |
|
58 | + */ |
|
59 | + public static function fromJson(string $json): HelpText |
|
60 | + { |
|
61 | + $json_data_handler = new JsonDataHandler(); |
|
62 | + $json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT); |
|
63 | + $data = $json_data_handler->decodeJson($json); |
|
64 | + $htmlClass = (array) ($data->htmlClass ?? []); |
|
65 | + $helpText = $data->helpText ?? ''; |
|
66 | + return new HelpText($json_data_handler, $htmlClass, $helpText); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function toArray(): array |
|
74 | + { |
|
75 | + return [ |
|
76 | + 'helpText' => $this->helpText, |
|
77 | + 'htmlClass' => $this->htmlClasses(), |
|
78 | + ]; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function toJson(): string |
|
86 | + { |
|
87 | + return $this->json_data_handler->encodeData($this->toArray()); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Input label displayed on public forms, ie: the actual question text. |
|
93 | + * |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function helpText(): string |
|
97 | + { |
|
98 | + return $this->helpText; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @param string $helpText |
|
104 | + */ |
|
105 | + public function setHelpText(string $helpText): void |
|
106 | + { |
|
107 | + $this->helpText = sanitize_text_field($helpText); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Custom HTML classes to be applied to this form input's help text. |
|
113 | + * returns a concatenated string unless $as_array is set to true |
|
114 | + * |
|
115 | + * @return array|string |
|
116 | + */ |
|
117 | + public function htmlClasses($as_array = false) |
|
118 | + { |
|
119 | + return $as_array |
|
120 | + ? $this->htmlClasses |
|
121 | + : implode(' ', $this->htmlClasses); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $htmlClass |
|
127 | + */ |
|
128 | + public function addHtmlClass(string $htmlClass): void |
|
129 | + { |
|
130 | + $htmlClass = sanitize_key($htmlClass); |
|
131 | + if (! in_array($htmlClass, $this->htmlClasses, true)) { |
|
132 | + $this->htmlClasses[] = $htmlClass; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $htmlClass |
|
139 | + */ |
|
140 | + public function removeHtmlClass(string $htmlClass): void |
|
141 | + { |
|
142 | + $htmlClass = sanitize_key($htmlClass); |
|
143 | + unset($this->htmlClasses[ $htmlClass ]); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @param array $htmlClasses |
|
149 | + */ |
|
150 | + public function setHtmlClasses(array $htmlClasses): void |
|
151 | + { |
|
152 | + $this->htmlClasses = array_map('sanitize_key', $htmlClasses); |
|
153 | + } |
|
154 | 154 | } |
@@ -152,10 +152,10 @@ |
||
152 | 152 | ]; |
153 | 153 | // this model is generally available for reading |
154 | 154 | $restrictions = []; |
155 | - $restrictions[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
156 | - $restrictions[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
157 | - $restrictions[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
158 | - $restrictions[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
155 | + $restrictions[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
156 | + $restrictions[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
157 | + $restrictions[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
158 | + $restrictions[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
159 | 159 | $this->_cap_restriction_generators = $restrictions; |
160 | 160 | parent::__construct($timezone); |
161 | 161 | $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
@@ -20,235 +20,235 @@ |
||
20 | 20 | */ |
21 | 21 | class EEM_Form_Section extends EEM_Base |
22 | 22 | { |
23 | - public const APPLIES_TO_ALL = 'all'; |
|
24 | - |
|
25 | - public const APPLIES_TO_PRIMARY = 'primary'; |
|
26 | - |
|
27 | - public const APPLIES_TO_PURCHASER = 'purchaser'; |
|
28 | - |
|
29 | - public const APPLIES_TO_REGISTRANTS = 'registrants'; |
|
30 | - |
|
31 | - protected static ?EEM_Form_Section $_instance = null; |
|
32 | - |
|
33 | - private RequestInterface $request; |
|
34 | - |
|
35 | - private array $valid_applies_to_options; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * EEM_Form_Section constructor. |
|
40 | - * |
|
41 | - * @param FormStatus $form_status |
|
42 | - * @param string|null $timezone |
|
43 | - * @throws EE_Error |
|
44 | - */ |
|
45 | - protected function __construct(FormStatus $form_status, ?string $timezone = '') |
|
46 | - { |
|
47 | - $this->valid_applies_to_options = apply_filters( |
|
48 | - 'FHEE__EEM_Form_Section__valid_applies_to_options', |
|
49 | - [ |
|
50 | - EEM_Form_Section::APPLIES_TO_ALL => esc_html__('All Registrants', 'event_espresso'), |
|
51 | - EEM_Form_Section::APPLIES_TO_PRIMARY => esc_html__('Primary Registrant Only', 'event_espresso'), |
|
52 | - EEM_Form_Section::APPLIES_TO_PURCHASER => esc_html__('Purchasing Agent', 'event_espresso'), |
|
53 | - EEM_Form_Section::APPLIES_TO_REGISTRANTS => esc_html__('Additional Registrants', 'event_espresso'), |
|
54 | - ] |
|
55 | - ); |
|
56 | - |
|
57 | - $this->singular_item = esc_html__('Form Section', 'event_espresso'); |
|
58 | - $this->plural_item = esc_html__('Form Sections', 'event_espresso'); |
|
59 | - |
|
60 | - $this->_tables = [ |
|
61 | - 'Form_Section' => new EE_Primary_Table('esp_form_section', 'FSC_UUID'), |
|
62 | - ]; |
|
63 | - $this->_fields = [ |
|
64 | - 'Form_Section' => [ |
|
65 | - 'FSC_UUID' => new EE_Primary_Key_String_Field( |
|
66 | - 'FSC_UUID', |
|
67 | - esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso') |
|
68 | - ), |
|
69 | - 'FSC_appliesTo' => new EE_Enum_Text_Field( |
|
70 | - 'FSC_appliesTo', |
|
71 | - esc_html( |
|
72 | - sprintf( |
|
73 | - /* translators: 1 class name */ |
|
74 | - __( |
|
75 | - 'Form user type that this form section should be presented to. Values correspond to the %s constants.', |
|
76 | - 'event_espresso' |
|
77 | - ), |
|
78 | - 'EEM_Form_Section::APPLIES_TO_*' |
|
79 | - ) |
|
80 | - ), |
|
81 | - false, |
|
82 | - EEM_Form_Section::APPLIES_TO_ALL, |
|
83 | - $this->valid_applies_to_options |
|
84 | - ), |
|
85 | - 'FSC_attributes' => new EE_JSON_Field( |
|
86 | - 'FSC_attributes', |
|
87 | - esc_html__( |
|
88 | - 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - false, |
|
92 | - '{}' |
|
93 | - ), |
|
94 | - 'FSC_belongsTo' => new EE_Plain_Text_Field( |
|
95 | - 'FSC_belongsTo', |
|
96 | - esc_html__('UUID of parent form section that this one belongs to.', 'event_espresso'), |
|
97 | - false, |
|
98 | - '' |
|
99 | - ), |
|
100 | - 'FSC_label' => new EE_JSON_Field( |
|
101 | - 'FSC_label', |
|
102 | - esc_html__( |
|
103 | - 'JSON string of properties pertaining to a form section\'s label.', |
|
104 | - 'event_espresso' |
|
105 | - ), |
|
106 | - false, |
|
107 | - '{}' |
|
108 | - ), |
|
109 | - 'FSC_order' => new EE_Integer_Field( |
|
110 | - 'FSC_order', |
|
111 | - esc_html__('Order in which form section appears in a form.', 'event_espresso'), |
|
112 | - false, |
|
113 | - 0 |
|
114 | - ), |
|
115 | - 'FSC_status' => new EE_Enum_Text_Field( |
|
116 | - 'FSC_status', |
|
117 | - esc_html( |
|
118 | - sprintf( |
|
119 | - /* translators: 1 class name */ |
|
120 | - __( |
|
121 | - 'Whether form section is active, archived, shared, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.', |
|
122 | - 'event_espresso' |
|
123 | - ), |
|
124 | - 'EventEspresso\core\services\form\meta\FormStatus' |
|
125 | - ) |
|
126 | - ), |
|
127 | - false, |
|
128 | - FormStatus::ACTIVE, |
|
129 | - $form_status->validStatusOptions() |
|
130 | - ), |
|
131 | - 'FSC_wpUser' => new EE_WP_User_Field( |
|
132 | - 'FSC_wpUser', |
|
133 | - esc_html__('ID of the WP User that created this form section.', 'event_espresso'), |
|
134 | - false |
|
135 | - ), |
|
136 | - ], |
|
137 | - ]; |
|
138 | - $this->_model_relations = [ |
|
139 | - 'Form_Element' => new EE_Has_Many_Relation(), |
|
140 | - 'Form_Submission' => new EE_Has_Many_Relation(), |
|
141 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
142 | - ]; |
|
143 | - // this model is generally available for reading |
|
144 | - $restrictions = []; |
|
145 | - $restrictions[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
146 | - $restrictions[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
147 | - $restrictions[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
148 | - $restrictions[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
149 | - $this->_cap_restriction_generators = $restrictions; |
|
150 | - parent::__construct($timezone); |
|
151 | - $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param array $query_params |
|
157 | - * @return array |
|
158 | - */ |
|
159 | - private function addDefaultWhereConditions(array $query_params): array |
|
160 | - { |
|
161 | - // might need to add a way to identify GQL requests for admin domains |
|
162 | - $admin_request = $this->request->isAdmin() || $this->request->isAdminAjax(); |
|
163 | - $query_params['default_where_conditions'] = $admin_request |
|
164 | - ? EEM_Base::default_where_conditions_none |
|
165 | - : EEM_Base::default_where_conditions_all; |
|
166 | - return $query_params; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * form sections should always be sorted in ascending order via the FSC_order field |
|
172 | - * |
|
173 | - * @param array $query_params |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - private function addOrderByQueryParams(array $query_params): array |
|
177 | - { |
|
178 | - $query_params['order_by'] = ['FSC_order' => 'ASC']; |
|
179 | - return $query_params; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * returns an array of Form Sections that should be added by default to new Events |
|
185 | - * |
|
186 | - * @return EE_Form_Section[] |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - public function getDefaultFormSections(): array |
|
190 | - { |
|
191 | - return $this->getFormSections(['FSC_status' => FormStatus::DEFAULT]); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * returns an array of Form Sections for the specified parent Form Section |
|
197 | - * |
|
198 | - * @param string $FSC_UUID |
|
199 | - * @return EE_Form_Section[] |
|
200 | - * @throws EE_Error |
|
201 | - */ |
|
202 | - public function getChildFormSections(string $FSC_UUID): array |
|
203 | - { |
|
204 | - return $this->getFormSections(['FSC_belongsTo' => $FSC_UUID]); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * @return EE_Form_Section[] |
|
210 | - * @throws EE_Error |
|
211 | - */ |
|
212 | - public function getFormSections(array $where_params): array |
|
213 | - { |
|
214 | - $query_params = $this->addDefaultWhereConditions([$where_params]); |
|
215 | - $query_params = $this->addOrderByQueryParams($query_params); |
|
216 | - return $this->get_all($query_params); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * returns an array of Form Sections for the specified Event |
|
222 | - * |
|
223 | - * @param EE_Event $event |
|
224 | - * @return EE_Form_Section[] |
|
225 | - * @throws EE_Error |
|
226 | - * @throws ReflectionException |
|
227 | - */ |
|
228 | - public function getFormSectionsForEvent(EE_Event $event): array |
|
229 | - { |
|
230 | - $FSC_UUID = $event->registrationFormUuid(); |
|
231 | - return ! empty($FSC_UUID) |
|
232 | - ? $this->getFormSections( |
|
233 | - [ |
|
234 | - 'OR' => [ |
|
235 | - 'FSC_UUID' => $FSC_UUID, // top level form |
|
236 | - 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
237 | - ], |
|
238 | - ] |
|
239 | - ) |
|
240 | - : []; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * @param bool $constants_only |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - public function validAppliesToOptions(bool $constants_only = false): array |
|
249 | - { |
|
250 | - return $constants_only |
|
251 | - ? array_keys($this->valid_applies_to_options) |
|
252 | - : $this->valid_applies_to_options; |
|
253 | - } |
|
23 | + public const APPLIES_TO_ALL = 'all'; |
|
24 | + |
|
25 | + public const APPLIES_TO_PRIMARY = 'primary'; |
|
26 | + |
|
27 | + public const APPLIES_TO_PURCHASER = 'purchaser'; |
|
28 | + |
|
29 | + public const APPLIES_TO_REGISTRANTS = 'registrants'; |
|
30 | + |
|
31 | + protected static ?EEM_Form_Section $_instance = null; |
|
32 | + |
|
33 | + private RequestInterface $request; |
|
34 | + |
|
35 | + private array $valid_applies_to_options; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * EEM_Form_Section constructor. |
|
40 | + * |
|
41 | + * @param FormStatus $form_status |
|
42 | + * @param string|null $timezone |
|
43 | + * @throws EE_Error |
|
44 | + */ |
|
45 | + protected function __construct(FormStatus $form_status, ?string $timezone = '') |
|
46 | + { |
|
47 | + $this->valid_applies_to_options = apply_filters( |
|
48 | + 'FHEE__EEM_Form_Section__valid_applies_to_options', |
|
49 | + [ |
|
50 | + EEM_Form_Section::APPLIES_TO_ALL => esc_html__('All Registrants', 'event_espresso'), |
|
51 | + EEM_Form_Section::APPLIES_TO_PRIMARY => esc_html__('Primary Registrant Only', 'event_espresso'), |
|
52 | + EEM_Form_Section::APPLIES_TO_PURCHASER => esc_html__('Purchasing Agent', 'event_espresso'), |
|
53 | + EEM_Form_Section::APPLIES_TO_REGISTRANTS => esc_html__('Additional Registrants', 'event_espresso'), |
|
54 | + ] |
|
55 | + ); |
|
56 | + |
|
57 | + $this->singular_item = esc_html__('Form Section', 'event_espresso'); |
|
58 | + $this->plural_item = esc_html__('Form Sections', 'event_espresso'); |
|
59 | + |
|
60 | + $this->_tables = [ |
|
61 | + 'Form_Section' => new EE_Primary_Table('esp_form_section', 'FSC_UUID'), |
|
62 | + ]; |
|
63 | + $this->_fields = [ |
|
64 | + 'Form_Section' => [ |
|
65 | + 'FSC_UUID' => new EE_Primary_Key_String_Field( |
|
66 | + 'FSC_UUID', |
|
67 | + esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso') |
|
68 | + ), |
|
69 | + 'FSC_appliesTo' => new EE_Enum_Text_Field( |
|
70 | + 'FSC_appliesTo', |
|
71 | + esc_html( |
|
72 | + sprintf( |
|
73 | + /* translators: 1 class name */ |
|
74 | + __( |
|
75 | + 'Form user type that this form section should be presented to. Values correspond to the %s constants.', |
|
76 | + 'event_espresso' |
|
77 | + ), |
|
78 | + 'EEM_Form_Section::APPLIES_TO_*' |
|
79 | + ) |
|
80 | + ), |
|
81 | + false, |
|
82 | + EEM_Form_Section::APPLIES_TO_ALL, |
|
83 | + $this->valid_applies_to_options |
|
84 | + ), |
|
85 | + 'FSC_attributes' => new EE_JSON_Field( |
|
86 | + 'FSC_attributes', |
|
87 | + esc_html__( |
|
88 | + 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + false, |
|
92 | + '{}' |
|
93 | + ), |
|
94 | + 'FSC_belongsTo' => new EE_Plain_Text_Field( |
|
95 | + 'FSC_belongsTo', |
|
96 | + esc_html__('UUID of parent form section that this one belongs to.', 'event_espresso'), |
|
97 | + false, |
|
98 | + '' |
|
99 | + ), |
|
100 | + 'FSC_label' => new EE_JSON_Field( |
|
101 | + 'FSC_label', |
|
102 | + esc_html__( |
|
103 | + 'JSON string of properties pertaining to a form section\'s label.', |
|
104 | + 'event_espresso' |
|
105 | + ), |
|
106 | + false, |
|
107 | + '{}' |
|
108 | + ), |
|
109 | + 'FSC_order' => new EE_Integer_Field( |
|
110 | + 'FSC_order', |
|
111 | + esc_html__('Order in which form section appears in a form.', 'event_espresso'), |
|
112 | + false, |
|
113 | + 0 |
|
114 | + ), |
|
115 | + 'FSC_status' => new EE_Enum_Text_Field( |
|
116 | + 'FSC_status', |
|
117 | + esc_html( |
|
118 | + sprintf( |
|
119 | + /* translators: 1 class name */ |
|
120 | + __( |
|
121 | + 'Whether form section is active, archived, shared, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.', |
|
122 | + 'event_espresso' |
|
123 | + ), |
|
124 | + 'EventEspresso\core\services\form\meta\FormStatus' |
|
125 | + ) |
|
126 | + ), |
|
127 | + false, |
|
128 | + FormStatus::ACTIVE, |
|
129 | + $form_status->validStatusOptions() |
|
130 | + ), |
|
131 | + 'FSC_wpUser' => new EE_WP_User_Field( |
|
132 | + 'FSC_wpUser', |
|
133 | + esc_html__('ID of the WP User that created this form section.', 'event_espresso'), |
|
134 | + false |
|
135 | + ), |
|
136 | + ], |
|
137 | + ]; |
|
138 | + $this->_model_relations = [ |
|
139 | + 'Form_Element' => new EE_Has_Many_Relation(), |
|
140 | + 'Form_Submission' => new EE_Has_Many_Relation(), |
|
141 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
142 | + ]; |
|
143 | + // this model is generally available for reading |
|
144 | + $restrictions = []; |
|
145 | + $restrictions[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
146 | + $restrictions[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
147 | + $restrictions[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
148 | + $restrictions[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
149 | + $this->_cap_restriction_generators = $restrictions; |
|
150 | + parent::__construct($timezone); |
|
151 | + $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param array $query_params |
|
157 | + * @return array |
|
158 | + */ |
|
159 | + private function addDefaultWhereConditions(array $query_params): array |
|
160 | + { |
|
161 | + // might need to add a way to identify GQL requests for admin domains |
|
162 | + $admin_request = $this->request->isAdmin() || $this->request->isAdminAjax(); |
|
163 | + $query_params['default_where_conditions'] = $admin_request |
|
164 | + ? EEM_Base::default_where_conditions_none |
|
165 | + : EEM_Base::default_where_conditions_all; |
|
166 | + return $query_params; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * form sections should always be sorted in ascending order via the FSC_order field |
|
172 | + * |
|
173 | + * @param array $query_params |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + private function addOrderByQueryParams(array $query_params): array |
|
177 | + { |
|
178 | + $query_params['order_by'] = ['FSC_order' => 'ASC']; |
|
179 | + return $query_params; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * returns an array of Form Sections that should be added by default to new Events |
|
185 | + * |
|
186 | + * @return EE_Form_Section[] |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + public function getDefaultFormSections(): array |
|
190 | + { |
|
191 | + return $this->getFormSections(['FSC_status' => FormStatus::DEFAULT]); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * returns an array of Form Sections for the specified parent Form Section |
|
197 | + * |
|
198 | + * @param string $FSC_UUID |
|
199 | + * @return EE_Form_Section[] |
|
200 | + * @throws EE_Error |
|
201 | + */ |
|
202 | + public function getChildFormSections(string $FSC_UUID): array |
|
203 | + { |
|
204 | + return $this->getFormSections(['FSC_belongsTo' => $FSC_UUID]); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * @return EE_Form_Section[] |
|
210 | + * @throws EE_Error |
|
211 | + */ |
|
212 | + public function getFormSections(array $where_params): array |
|
213 | + { |
|
214 | + $query_params = $this->addDefaultWhereConditions([$where_params]); |
|
215 | + $query_params = $this->addOrderByQueryParams($query_params); |
|
216 | + return $this->get_all($query_params); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * returns an array of Form Sections for the specified Event |
|
222 | + * |
|
223 | + * @param EE_Event $event |
|
224 | + * @return EE_Form_Section[] |
|
225 | + * @throws EE_Error |
|
226 | + * @throws ReflectionException |
|
227 | + */ |
|
228 | + public function getFormSectionsForEvent(EE_Event $event): array |
|
229 | + { |
|
230 | + $FSC_UUID = $event->registrationFormUuid(); |
|
231 | + return ! empty($FSC_UUID) |
|
232 | + ? $this->getFormSections( |
|
233 | + [ |
|
234 | + 'OR' => [ |
|
235 | + 'FSC_UUID' => $FSC_UUID, // top level form |
|
236 | + 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
237 | + ], |
|
238 | + ] |
|
239 | + ) |
|
240 | + : []; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * @param bool $constants_only |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + public function validAppliesToOptions(bool $constants_only = false): array |
|
249 | + { |
|
250 | + return $constants_only |
|
251 | + ? array_keys($this->valid_applies_to_options) |
|
252 | + : $this->valid_applies_to_options; |
|
253 | + } |
|
254 | 254 | } |
@@ -14,122 +14,122 @@ |
||
14 | 14 | */ |
15 | 15 | class FormElementConnectionResolver extends AbstractConnectionResolver |
16 | 16 | { |
17 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | - public function get_loader_name(): string |
|
19 | - { |
|
20 | - return 'espresso_formElement'; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * @return EEM_Form_Element |
|
25 | - * @throws EE_Error |
|
26 | - * @throws InvalidArgumentException |
|
27 | - * @throws InvalidDataTypeException |
|
28 | - * @throws InvalidInterfaceException |
|
29 | - * @throws ReflectionException |
|
30 | - */ |
|
31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | - public function get_query(): EEM_Form_Element |
|
33 | - { |
|
34 | - return EEM_Form_Element::instance(); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Return an array of item IDs from the query |
|
40 | - * |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | - public function get_ids(): array |
|
45 | - { |
|
46 | - $results = $this->query->get_col($this->query_args); |
|
47 | - return ! empty($results) ? $results : []; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
53 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
54 | - * handle batch resolution of the posts. |
|
55 | - * |
|
56 | - * @return array |
|
57 | - * @throws InvalidArgumentException |
|
58 | - * @throws InvalidDataTypeException |
|
59 | - * @throws InvalidInterfaceException |
|
60 | - */ |
|
61 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
62 | - public function get_query_args(): array |
|
63 | - { |
|
64 | - $where_params = []; |
|
65 | - $query_args = []; |
|
66 | - |
|
67 | - $query_args['limit'] = $this->getLimit(); |
|
68 | - |
|
69 | - // Avoid multiple entries by join. |
|
70 | - $query_args['group_by'] = 'FIN_UUID'; |
|
71 | - |
|
72 | - /** |
|
73 | - * Collect the input fields and sanitize them to prepare them for sending to the Query |
|
74 | - */ |
|
75 | - $input_fields = []; |
|
76 | - if (! empty($this->args['where'])) { |
|
77 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
78 | - |
|
79 | - // Use the proper operator. |
|
80 | - if (! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
81 | - $input_fields['FSC_UUID'] = ['IN', $input_fields['FSC_UUID']]; |
|
82 | - } |
|
83 | - if (! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
84 | - $input_fields['FIN_status'] = ['IN', $input_fields['FIN_status']]; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Merge the input_fields with the default query_args |
|
90 | - */ |
|
91 | - if (! empty($input_fields)) { |
|
92 | - $where_params = array_merge($where_params, $input_fields); |
|
93 | - } |
|
94 | - |
|
95 | - $where_params = apply_filters( |
|
96 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_where_params', |
|
97 | - $where_params, |
|
98 | - $this->source, |
|
99 | - $this->args |
|
100 | - ); |
|
101 | - |
|
102 | - if (! empty($where_params)) { |
|
103 | - $query_args[] = $where_params; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Return the $query_args |
|
109 | - */ |
|
110 | - return apply_filters( |
|
111 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_query_args', |
|
112 | - $query_args, |
|
113 | - $this->source, |
|
114 | - $this->args |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
120 | - * friendly keys. |
|
121 | - * |
|
122 | - * @param array $where_args |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function sanitizeInputFields(array $where_args): array |
|
126 | - { |
|
127 | - return $this->sanitizeWhereArgsForInputFields( |
|
128 | - $where_args, |
|
129 | - [ |
|
130 | - 'belongsTo' => 'FSC_UUID', |
|
131 | - 'status' => 'FIN_status', |
|
132 | - ] |
|
133 | - ); |
|
134 | - } |
|
17 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | + public function get_loader_name(): string |
|
19 | + { |
|
20 | + return 'espresso_formElement'; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * @return EEM_Form_Element |
|
25 | + * @throws EE_Error |
|
26 | + * @throws InvalidArgumentException |
|
27 | + * @throws InvalidDataTypeException |
|
28 | + * @throws InvalidInterfaceException |
|
29 | + * @throws ReflectionException |
|
30 | + */ |
|
31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | + public function get_query(): EEM_Form_Element |
|
33 | + { |
|
34 | + return EEM_Form_Element::instance(); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Return an array of item IDs from the query |
|
40 | + * |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | + public function get_ids(): array |
|
45 | + { |
|
46 | + $results = $this->query->get_col($this->query_args); |
|
47 | + return ! empty($results) ? $results : []; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
53 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
54 | + * handle batch resolution of the posts. |
|
55 | + * |
|
56 | + * @return array |
|
57 | + * @throws InvalidArgumentException |
|
58 | + * @throws InvalidDataTypeException |
|
59 | + * @throws InvalidInterfaceException |
|
60 | + */ |
|
61 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
62 | + public function get_query_args(): array |
|
63 | + { |
|
64 | + $where_params = []; |
|
65 | + $query_args = []; |
|
66 | + |
|
67 | + $query_args['limit'] = $this->getLimit(); |
|
68 | + |
|
69 | + // Avoid multiple entries by join. |
|
70 | + $query_args['group_by'] = 'FIN_UUID'; |
|
71 | + |
|
72 | + /** |
|
73 | + * Collect the input fields and sanitize them to prepare them for sending to the Query |
|
74 | + */ |
|
75 | + $input_fields = []; |
|
76 | + if (! empty($this->args['where'])) { |
|
77 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
78 | + |
|
79 | + // Use the proper operator. |
|
80 | + if (! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
81 | + $input_fields['FSC_UUID'] = ['IN', $input_fields['FSC_UUID']]; |
|
82 | + } |
|
83 | + if (! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
84 | + $input_fields['FIN_status'] = ['IN', $input_fields['FIN_status']]; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Merge the input_fields with the default query_args |
|
90 | + */ |
|
91 | + if (! empty($input_fields)) { |
|
92 | + $where_params = array_merge($where_params, $input_fields); |
|
93 | + } |
|
94 | + |
|
95 | + $where_params = apply_filters( |
|
96 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_where_params', |
|
97 | + $where_params, |
|
98 | + $this->source, |
|
99 | + $this->args |
|
100 | + ); |
|
101 | + |
|
102 | + if (! empty($where_params)) { |
|
103 | + $query_args[] = $where_params; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Return the $query_args |
|
109 | + */ |
|
110 | + return apply_filters( |
|
111 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_query_args', |
|
112 | + $query_args, |
|
113 | + $this->source, |
|
114 | + $this->args |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
120 | + * friendly keys. |
|
121 | + * |
|
122 | + * @param array $where_args |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function sanitizeInputFields(array $where_args): array |
|
126 | + { |
|
127 | + return $this->sanitizeWhereArgsForInputFields( |
|
128 | + $where_args, |
|
129 | + [ |
|
130 | + 'belongsTo' => 'FSC_UUID', |
|
131 | + 'status' => 'FIN_status', |
|
132 | + ] |
|
133 | + ); |
|
134 | + } |
|
135 | 135 | } |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | * Collect the input fields and sanitize them to prepare them for sending to the Query |
74 | 74 | */ |
75 | 75 | $input_fields = []; |
76 | - if (! empty($this->args['where'])) { |
|
76 | + if ( ! empty($this->args['where'])) { |
|
77 | 77 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
78 | 78 | |
79 | 79 | // Use the proper operator. |
80 | - if (! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
80 | + if ( ! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
81 | 81 | $input_fields['FSC_UUID'] = ['IN', $input_fields['FSC_UUID']]; |
82 | 82 | } |
83 | - if (! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
83 | + if ( ! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
84 | 84 | $input_fields['FIN_status'] = ['IN', $input_fields['FIN_status']]; |
85 | 85 | } |
86 | 86 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * Merge the input_fields with the default query_args |
90 | 90 | */ |
91 | - if (! empty($input_fields)) { |
|
91 | + if ( ! empty($input_fields)) { |
|
92 | 92 | $where_params = array_merge($where_params, $input_fields); |
93 | 93 | } |
94 | 94 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $this->args |
100 | 100 | ); |
101 | 101 | |
102 | - if (! empty($where_params)) { |
|
102 | + if ( ! empty($where_params)) { |
|
103 | 103 | $query_args[] = $where_params; |
104 | 104 | } |
105 | 105 |
@@ -11,48 +11,48 @@ |
||
11 | 11 | class FormElementDelete extends EntityMutator |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Defines the mutation data modification closure. |
|
16 | - * |
|
17 | - * @param EEM_Form_Element $model |
|
18 | - * @return callable |
|
19 | - */ |
|
20 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | - { |
|
22 | - /** |
|
23 | - * Deletes an entity. |
|
24 | - * |
|
25 | - * @param array $input The input for the mutation |
|
26 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | - try { |
|
32 | - /** @var EE_Form_Element $entity */ |
|
33 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
14 | + /** |
|
15 | + * Defines the mutation data modification closure. |
|
16 | + * |
|
17 | + * @param EEM_Form_Element $model |
|
18 | + * @return callable |
|
19 | + */ |
|
20 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | + { |
|
22 | + /** |
|
23 | + * Deletes an entity. |
|
24 | + * |
|
25 | + * @param array $input The input for the mutation |
|
26 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | + try { |
|
32 | + /** @var EE_Form_Element $entity */ |
|
33 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
34 | 34 | |
35 | - $result = $entity->delete(); |
|
36 | - EntityMutator::validateResults($result); |
|
35 | + $result = $entity->delete(); |
|
36 | + EntityMutator::validateResults($result); |
|
37 | 37 | |
38 | - do_action( |
|
39 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_delete', |
|
40 | - $entity, |
|
41 | - $input |
|
42 | - ); |
|
43 | - } catch (Exception $exception) { |
|
44 | - EntityMutator::handleExceptions( |
|
45 | - $exception, |
|
46 | - esc_html__( |
|
47 | - 'The form element could not be deleted because of the following error(s)', |
|
48 | - 'event_espresso' |
|
49 | - ) |
|
50 | - ); |
|
51 | - } |
|
38 | + do_action( |
|
39 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_delete', |
|
40 | + $entity, |
|
41 | + $input |
|
42 | + ); |
|
43 | + } catch (Exception $exception) { |
|
44 | + EntityMutator::handleExceptions( |
|
45 | + $exception, |
|
46 | + esc_html__( |
|
47 | + 'The form element could not be deleted because of the following error(s)', |
|
48 | + 'event_espresso' |
|
49 | + ) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - return [ |
|
54 | - 'deleted' => $entity, |
|
55 | - ]; |
|
56 | - }; |
|
57 | - } |
|
53 | + return [ |
|
54 | + 'deleted' => $entity, |
|
55 | + ]; |
|
56 | + }; |
|
57 | + } |
|
58 | 58 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
30 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | 31 | try { |
32 | 32 | /** @var EE_Form_Element $entity */ |
33 | 33 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
33 | 33 | $id = null; |
34 | 34 | try { |
35 | 35 | EntityMutator::checkPermissions($model); |
@@ -11,51 +11,51 @@ |
||
11 | 11 | |
12 | 12 | class FormElementCreate extends EntityMutator |
13 | 13 | { |
14 | - /** |
|
15 | - * Defines the mutation data modification closure. |
|
16 | - * |
|
17 | - * @param EEM_Form_Element $model |
|
18 | - * @return callable |
|
19 | - */ |
|
20 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | - { |
|
22 | - /** |
|
23 | - * Creates an entity. |
|
24 | - * |
|
25 | - * @param array $input The input for the mutation |
|
26 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | - $id = null; |
|
32 | - try { |
|
33 | - EntityMutator::checkPermissions($model); |
|
14 | + /** |
|
15 | + * Defines the mutation data modification closure. |
|
16 | + * |
|
17 | + * @param EEM_Form_Element $model |
|
18 | + * @return callable |
|
19 | + */ |
|
20 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | + { |
|
22 | + /** |
|
23 | + * Creates an entity. |
|
24 | + * |
|
25 | + * @param array $input The input for the mutation |
|
26 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | + $id = null; |
|
32 | + try { |
|
33 | + EntityMutator::checkPermissions($model); |
|
34 | 34 | |
35 | - $args = FormElementMutation::prepareFields($input); |
|
35 | + $args = FormElementMutation::prepareFields($input); |
|
36 | 36 | |
37 | - $entity = EE_Form_Element::new_instance($args); |
|
38 | - $id = $entity->save(); |
|
39 | - EntityMutator::validateResults($id); |
|
37 | + $entity = EE_Form_Element::new_instance($args); |
|
38 | + $id = $entity->save(); |
|
39 | + EntityMutator::validateResults($id); |
|
40 | 40 | |
41 | - do_action( |
|
42 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_create', |
|
43 | - $entity, |
|
44 | - $input |
|
45 | - ); |
|
46 | - } catch (Exception $exception) { |
|
47 | - EntityMutator::handleExceptions( |
|
48 | - $exception, |
|
49 | - esc_html__( |
|
50 | - 'The form element could not be created because of the following error(s)', |
|
51 | - 'event_espresso' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
41 | + do_action( |
|
42 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_create', |
|
43 | + $entity, |
|
44 | + $input |
|
45 | + ); |
|
46 | + } catch (Exception $exception) { |
|
47 | + EntityMutator::handleExceptions( |
|
48 | + $exception, |
|
49 | + esc_html__( |
|
50 | + 'The form element could not be created because of the following error(s)', |
|
51 | + 'event_espresso' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - return [ |
|
57 | - 'id' => $id, |
|
58 | - ]; |
|
59 | - }; |
|
60 | - } |
|
56 | + return [ |
|
57 | + 'id' => $id, |
|
58 | + ]; |
|
59 | + }; |
|
60 | + } |
|
61 | 61 | } |
@@ -14,52 +14,52 @@ |
||
14 | 14 | class FormElementUpdate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Form_Element $model |
|
21 | - * @return callable |
|
22 | - */ |
|
23 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
24 | - { |
|
25 | - /** |
|
26 | - * Updates an entity. |
|
27 | - * |
|
28 | - * @param array $input The input for the mutation |
|
29 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | - * @return array |
|
32 | - * @throws EE_Error |
|
33 | - * @throws ReflectionException |
|
34 | - */ |
|
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | - try { |
|
37 | - /** @var EE_Form_Element $entity */ |
|
38 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Form_Element $model |
|
21 | + * @return callable |
|
22 | + */ |
|
23 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
24 | + { |
|
25 | + /** |
|
26 | + * Updates an entity. |
|
27 | + * |
|
28 | + * @param array $input The input for the mutation |
|
29 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | + * @return array |
|
32 | + * @throws EE_Error |
|
33 | + * @throws ReflectionException |
|
34 | + */ |
|
35 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | + try { |
|
37 | + /** @var EE_Form_Element $entity */ |
|
38 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
39 | 39 | |
40 | - $args = FormElementMutation::prepareFields($input); |
|
40 | + $args = FormElementMutation::prepareFields($input); |
|
41 | 41 | |
42 | - // Update the entity |
|
43 | - $entity->save($args); |
|
42 | + // Update the entity |
|
43 | + $entity->save($args); |
|
44 | 44 | |
45 | - do_action( |
|
46 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_update', |
|
47 | - $entity, |
|
48 | - $input |
|
49 | - ); |
|
50 | - } catch (Exception $exception) { |
|
51 | - EntityMutator::handleExceptions( |
|
52 | - $exception, |
|
53 | - esc_html__( |
|
54 | - 'The form element could not be updated because of the following error(s)', |
|
55 | - 'event_espresso' |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
45 | + do_action( |
|
46 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_update', |
|
47 | + $entity, |
|
48 | + $input |
|
49 | + ); |
|
50 | + } catch (Exception $exception) { |
|
51 | + EntityMutator::handleExceptions( |
|
52 | + $exception, |
|
53 | + esc_html__( |
|
54 | + 'The form element could not be updated because of the following error(s)', |
|
55 | + 'event_espresso' |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - return [ |
|
61 | - 'id' => $entity->UUID(), |
|
62 | - ]; |
|
63 | - }; |
|
64 | - } |
|
60 | + return [ |
|
61 | + 'id' => $entity->UUID(), |
|
62 | + ]; |
|
63 | + }; |
|
64 | + } |
|
65 | 65 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @throws EE_Error |
33 | 33 | * @throws ReflectionException |
34 | 34 | */ |
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
35 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | 36 | try { |
37 | 37 | /** @var EE_Form_Element $entity */ |
38 | 38 | $entity = EntityMutator::getEntityFromInputData($model, $input); |