Completed
Branch FET/reg-form-builder/main (0f11d8)
by
unknown
02:56 queued 17s
created
core/services/graphql/connections/ConnectionBase.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
15 15
 abstract class ConnectionBase implements ConnectionInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var EEM_Base $model
20
-     */
21
-    protected $model;
18
+	/**
19
+	 * @var EEM_Base $model
20
+	 */
21
+	protected $model;
22 22
 
23
-    /**
24
-     * @var string $namespace The graphql namespace/prefix.
25
-     */
26
-    protected $namespace = 'Espresso';
23
+	/**
24
+	 * @var string $namespace The graphql namespace/prefix.
25
+	 */
26
+	protected $namespace = 'Espresso';
27 27
 
28 28
 
29
-    /**
30
-     * @param EEM_Base $model
31
-     */
32
-    public function __construct(EEM_Base $model)
33
-    {
34
-        $this->model = $model;
35
-    }
29
+	/**
30
+	 * @param EEM_Base $model
31
+	 */
32
+	public function __construct(EEM_Base $model)
33
+	{
34
+		$this->model = $model;
35
+	}
36 36
 }
Please login to merge, or discard this patch.
core/services/graphql/loaders/GQLDataDomainInterface.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
 interface GQLDataDomainInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @param array      $loaders The loaders accessible in the AppContext
20
-     * @param AppContext $context The AppContext
21
-     * @return array
22
-     * @return array
23
-     * @since $VID:$
24
-     */
25
-    public function registerLoaders(array $loaders, AppContext $context): array;
18
+	/**
19
+	 * @param array      $loaders The loaders accessible in the AppContext
20
+	 * @param AppContext $context The AppContext
21
+	 * @return array
22
+	 * @return array
23
+	 * @since $VID:$
24
+	 */
25
+	public function registerLoaders(array $loaders, AppContext $context): array;
26 26
 }
Please login to merge, or discard this patch.
core/services/graphql/types/TypeInterface.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -24,79 +24,79 @@
 block discarded – undo
24 24
 interface TypeInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @return string
29
-     */
30
-    public function name(): string;
31
-
32
-
33
-    /**
34
-     * @return string
35
-     */
36
-    public function description(): string;
37
-
38
-
39
-    /**
40
-     * @return GraphQLFieldInterface[]
41
-     * @since $VID:$
42
-     */
43
-    public function fields(): array;
44
-
45
-
46
-    /**
47
-     * Creates a key map for internal resolver.
48
-     *
49
-     * @return array
50
-     * @since $VID:$
51
-     */
52
-    public function getFieldsForResolver(): array;
53
-
54
-
55
-    /**
56
-     * @return bool
57
-     */
58
-    public function isCustomPostType(): bool;
59
-
60
-
61
-    /**
62
-     * @param int|float $value
63
-     * @return int
64
-     * @since $VID:$
65
-     */
66
-    public function parseInfiniteValue($value): int;
67
-
68
-
69
-    /**
70
-     * @param mixed       $source  The source that's passed down the GraphQL queries
71
-     * @param array       $args    The inputArgs on the field
72
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
73
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
74
-     * @return mixed
75
-     * @throws EE_Error
76
-     * @throws InvalidDataTypeException
77
-     * @throws InvalidInterfaceException
78
-     * @throws UnexpectedEntityException
79
-     * @throws UserError
80
-     * @throws InvalidArgumentException
81
-     * @throws ReflectionException
82
-     * @since $VID:$
83
-     */
84
-    public function resolveField($source, array $args, AppContext $context, ResolveInfo $info);
85
-
86
-
87
-    /**
88
-     * @param mixed      $payload The payload returned after mutation
89
-     * @param array      $args    The inputArgs on the field
90
-     * @param AppContext $context The AppContext passed down the GraphQL tree
91
-     * @return string|null
92
-     * @throws EE_Error
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws UnexpectedEntityException
96
-     * @throws UserError
97
-     * @throws InvalidArgumentException
98
-     * @throws ReflectionException
99
-     * @since $VID:$
100
-     */
101
-    public function resolveFromPayload($payload, array $args, AppContext $context);
27
+	/**
28
+	 * @return string
29
+	 */
30
+	public function name(): string;
31
+
32
+
33
+	/**
34
+	 * @return string
35
+	 */
36
+	public function description(): string;
37
+
38
+
39
+	/**
40
+	 * @return GraphQLFieldInterface[]
41
+	 * @since $VID:$
42
+	 */
43
+	public function fields(): array;
44
+
45
+
46
+	/**
47
+	 * Creates a key map for internal resolver.
48
+	 *
49
+	 * @return array
50
+	 * @since $VID:$
51
+	 */
52
+	public function getFieldsForResolver(): array;
53
+
54
+
55
+	/**
56
+	 * @return bool
57
+	 */
58
+	public function isCustomPostType(): bool;
59
+
60
+
61
+	/**
62
+	 * @param int|float $value
63
+	 * @return int
64
+	 * @since $VID:$
65
+	 */
66
+	public function parseInfiniteValue($value): int;
67
+
68
+
69
+	/**
70
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
71
+	 * @param array       $args    The inputArgs on the field
72
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
73
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
74
+	 * @return mixed
75
+	 * @throws EE_Error
76
+	 * @throws InvalidDataTypeException
77
+	 * @throws InvalidInterfaceException
78
+	 * @throws UnexpectedEntityException
79
+	 * @throws UserError
80
+	 * @throws InvalidArgumentException
81
+	 * @throws ReflectionException
82
+	 * @since $VID:$
83
+	 */
84
+	public function resolveField($source, array $args, AppContext $context, ResolveInfo $info);
85
+
86
+
87
+	/**
88
+	 * @param mixed      $payload The payload returned after mutation
89
+	 * @param array      $args    The inputArgs on the field
90
+	 * @param AppContext $context The AppContext passed down the GraphQL tree
91
+	 * @return string|null
92
+	 * @throws EE_Error
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws UnexpectedEntityException
96
+	 * @throws UserError
97
+	 * @throws InvalidArgumentException
98
+	 * @throws ReflectionException
99
+	 * @since $VID:$
100
+	 */
101
+	public function resolveFromPayload($payload, array $args, AppContext $context);
102 102
 }
Please login to merge, or discard this patch.
core/services/json/JsonDataHandler.php 2 patches
Indentation   +333 added lines, -333 removed lines patch added patch discarded remove patch
@@ -14,337 +14,337 @@
 block discarded – undo
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
-    /**
26
-     * @var string
27
-     */
28
-    private $data_type;
29
-
30
-    /**
31
-     * @var array|stdClass
32
-     */
33
-    private $decoded_data;
34
-
35
-    /**
36
-     * JSON_BIGINT_AS_STRING,
37
-     * JSON_INVALID_UTF8_IGNORE,
38
-     * JSON_INVALID_UTF8_SUBSTITUTE,
39
-     * JSON_OBJECT_AS_ARRAY,
40
-     * JSON_THROW_ON_ERROR
41
-     *
42
-     * @var int
43
-     */
44
-    private $decode_flags;
45
-
46
-    /**
47
-     * @var int
48
-     */
49
-    private $depth;
50
-
51
-    /**
52
-     * @var string
53
-     */
54
-    private $encoded_data;
55
-
56
-    /**
57
-     * JSON_FORCE_OBJECT,
58
-     * JSON_HEX_QUOT,
59
-     * JSON_HEX_TAG,
60
-     * JSON_HEX_AMP,
61
-     * JSON_HEX_APOS,
62
-     * JSON_INVALID_UTF8_IGNORE,
63
-     * JSON_INVALID_UTF8_SUBSTITUTE,
64
-     * JSON_NUMERIC_CHECK,
65
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
66
-     * JSON_PRESERVE_ZERO_FRACTION,
67
-     * JSON_PRETTY_PRINT,
68
-     * JSON_UNESCAPED_LINE_TERMINATORS,
69
-     * JSON_UNESCAPED_SLASHES,
70
-     * JSON_UNESCAPED_UNICODE,
71
-     * JSON_THROW_ON_ERROR.
72
-     *
73
-     * @var int
74
-     */
75
-    private $encode_flags;
76
-
77
-    /**
78
-     * @var int
79
-     */
80
-    private $last_error_code = JSON_ERROR_NONE;
81
-
82
-    /**
83
-     * @var string
84
-     */
85
-    private $last_error_msg = JsonDataHandler::NO_ERROR_MSG;
86
-
87
-
88
-    /**
89
-     * JsonDataHandler constructor.
90
-     */
91
-    public function __construct()
92
-    {
93
-        if (! defined('JSON_INVALID_UTF8_IGNORE')) {
94
-            define('JSON_INVALID_UTF8_IGNORE', 1048576);
95
-        }
96
-        if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
97
-            define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
98
-        }
99
-        if (! defined('JSON_THROW_ON_ERROR')) {
100
-            define('JSON_THROW_ON_ERROR', 4194304);
101
-        }
102
-    }
103
-
104
-
105
-    /**
106
-     * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
107
-     *
108
-     * @param string $data_type
109
-     * @param int    $decode_flags
110
-     * @param int    $encode_flags
111
-     * @param int    $depth
112
-     */
113
-    public function configure(
114
-        string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
115
-        int $decode_flags = 0,
116
-        int $encode_flags = 0,
117
-        int $depth = 512
118
-    ) {
119
-        $this->setDataType($data_type);
120
-        $this->setDecodeFlags($decode_flags);
121
-        $this->setDepth($depth);
122
-        $this->setEncodeFlags($encode_flags);
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $data_type
128
-     */
129
-    public function setDataType(string $data_type): void
130
-    {
131
-        $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
132
-                           || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
133
-                           || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
134
-            ? $data_type
135
-            : JsonDataHandler::DATA_TYPE_USE_FLAGS;
136
-    }
137
-
138
-
139
-    /**
140
-     * One or more Bitmask values:
141
-     * JSON_BIGINT_AS_STRING,
142
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
143
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
144
-     * JSON_OBJECT_AS_ARRAY,
145
-     * JSON_THROW_ON_ERROR              PHP >= 7.3
146
-     *
147
-     * pass multiple values separated with |
148
-     * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
149
-     *
150
-     * @param int $decode_flags
151
-     */
152
-    public function setDecodeFlags(int $decode_flags): void
153
-    {
154
-        $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
155
-                              || $decode_flags === JSON_OBJECT_AS_ARRAY
156
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
157
-                              || $decode_flags === JSON_INVALID_UTF8_IGNORE
158
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
159
-                              || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
160
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
161
-                              || $decode_flags === JSON_THROW_ON_ERROR
162
-            ? $decode_flags
163
-            : 0;
164
-    }
165
-
166
-
167
-    /**
168
-     * @param int $depth
169
-     */
170
-    public function setDepth(int $depth): void
171
-    {
172
-        $depth       = absint($depth);
173
-        $this->depth = $depth ?: 512;
174
-    }
175
-
176
-
177
-    /**
178
-     * One or more Bitmask values:
179
-     * JSON_FORCE_OBJECT,
180
-     * JSON_HEX_QUOT,
181
-     * JSON_HEX_TAG,
182
-     * JSON_HEX_AMP,
183
-     * JSON_HEX_APOS,
184
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
185
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
186
-     * JSON_NUMERIC_CHECK,
187
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
188
-     * JSON_PRESERVE_ZERO_FRACTION,
189
-     * JSON_PRETTY_PRINT,
190
-     * JSON_UNESCAPED_LINE_TERMINATORS,
191
-     * JSON_UNESCAPED_SLASHES,
192
-     * JSON_UNESCAPED_UNICODE,
193
-     * JSON_THROW_ON_ERROR.             PHP >= 7.3
194
-     *
195
-     * pass multiple values separated with |
196
-     * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
197
-     *
198
-     * @param int $encode_flags
199
-     */
200
-    public function setEncodeFlags(int $encode_flags): void
201
-    {
202
-        $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
203
-                              || $encode_flags === JSON_HEX_QUOT
204
-                              || $encode_flags === JSON_HEX_TAG
205
-                              || $encode_flags === JSON_HEX_AMP
206
-                              || $encode_flags === JSON_HEX_APOS
207
-                              || $encode_flags === JSON_NUMERIC_CHECK
208
-                              || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
209
-                              || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
210
-                              || $encode_flags === JSON_PRETTY_PRINT
211
-                              || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
212
-                              || $encode_flags === JSON_UNESCAPED_SLASHES
213
-                              || $encode_flags === JSON_UNESCAPED_UNICODE
214
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
215
-                              || $encode_flags === JSON_INVALID_UTF8_IGNORE
216
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
217
-                              || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
218
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
219
-                              || $encode_flags === JSON_THROW_ON_ERROR
220
-            ? $encode_flags
221
-            : 0;
222
-    }
223
-
224
-
225
-    /**
226
-     * @return bool|null
227
-     */
228
-    private function asAssociative(): ?bool
229
-    {
230
-        switch ($this->data_type) {
231
-            case JsonDataHandler::DATA_TYPE_ARRAY:
232
-                return true;
233
-            case JsonDataHandler::DATA_TYPE_OBJECT:
234
-                return false;
235
-            case JsonDataHandler::DATA_TYPE_USE_FLAGS:
236
-                return null;
237
-        }
238
-        return null;
239
-    }
240
-
241
-
242
-    /**
243
-     * @param array|string $json
244
-     * @return array|mixed|stdClass
245
-     */
246
-    public function decodeJson($json)
247
-    {
248
-        $this->resetErrors();
249
-        if ($this->isJson($json)) {
250
-            $this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
251
-            $this->last_error_code = json_last_error();
252
-            $this->last_error_msg  = json_last_error_msg();
253
-        } else {
254
-            $this->decoded_data    = $json;
255
-            $this->last_error_code = JSON_ERROR_NONE;
256
-            $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
257
-        }
258
-        return $this->decoded_data;
259
-    }
260
-
261
-
262
-    /**
263
-     * @param $data
264
-     * @return string
265
-     */
266
-    public function encodeData($data): string
267
-    {
268
-        $this->resetErrors();
269
-        if ($this->isJson($data)) {
270
-            $this->encoded_data = $data;
271
-            $this->last_error_code = JSON_ERROR_NONE;
272
-            $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
273
-        } else {
274
-            $this->encoded_data = json_encode($data, $this->encode_flags, $this->depth);
275
-            $this->last_error_code = json_last_error();
276
-            $this->last_error_msg  = json_last_error_msg();
277
-        }
278
-        return $this->encoded_data ?: '{}';
279
-    }
280
-
281
-
282
-    /**
283
-     * @return array|stdClass
284
-     */
285
-    public function getDecodedData()
286
-    {
287
-        return $this->decoded_data;
288
-    }
289
-
290
-
291
-    /**
292
-     * @return string
293
-     */
294
-    public function getEncodedData(): string
295
-    {
296
-        return $this->encoded_data;
297
-    }
298
-
299
-
300
-    /**
301
-     * @param bool $reset
302
-     * @return int
303
-     */
304
-    public function getLastErrorCode(bool $reset = false): int
305
-    {
306
-        $last_error = $this->last_error_code;
307
-        if ($reset) {
308
-            $this->resetErrors();
309
-        }
310
-        return $last_error;
311
-    }
312
-
313
-
314
-    /**
315
-     * @param bool $reset
316
-     * @return string
317
-     */
318
-    public function getLastErrorMessage(bool $reset = false): string
319
-    {
320
-        $last_error = $this->last_error_msg;
321
-        if ($reset) {
322
-            $this->resetErrors();
323
-        }
324
-        return $last_error;
325
-    }
326
-
327
-
328
-    /**
329
-     * @param array|string $maybe_json
330
-     * @return bool
331
-     */
332
-    public function isJson($maybe_json): bool
333
-    {
334
-        if (! is_string($maybe_json)) {
335
-            return false;
336
-        }
337
-        $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags);
338
-        return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json));
339
-    }
340
-
341
-
342
-    /**
343
-     * @since $VID:$
344
-     */
345
-    public function resetErrors()
346
-    {
347
-        $this->last_error_code = JSON_ERROR_NONE;
348
-        $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
349
-    }
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
+	/**
26
+	 * @var string
27
+	 */
28
+	private $data_type;
29
+
30
+	/**
31
+	 * @var array|stdClass
32
+	 */
33
+	private $decoded_data;
34
+
35
+	/**
36
+	 * JSON_BIGINT_AS_STRING,
37
+	 * JSON_INVALID_UTF8_IGNORE,
38
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
39
+	 * JSON_OBJECT_AS_ARRAY,
40
+	 * JSON_THROW_ON_ERROR
41
+	 *
42
+	 * @var int
43
+	 */
44
+	private $decode_flags;
45
+
46
+	/**
47
+	 * @var int
48
+	 */
49
+	private $depth;
50
+
51
+	/**
52
+	 * @var string
53
+	 */
54
+	private $encoded_data;
55
+
56
+	/**
57
+	 * JSON_FORCE_OBJECT,
58
+	 * JSON_HEX_QUOT,
59
+	 * JSON_HEX_TAG,
60
+	 * JSON_HEX_AMP,
61
+	 * JSON_HEX_APOS,
62
+	 * JSON_INVALID_UTF8_IGNORE,
63
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
64
+	 * JSON_NUMERIC_CHECK,
65
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
66
+	 * JSON_PRESERVE_ZERO_FRACTION,
67
+	 * JSON_PRETTY_PRINT,
68
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
69
+	 * JSON_UNESCAPED_SLASHES,
70
+	 * JSON_UNESCAPED_UNICODE,
71
+	 * JSON_THROW_ON_ERROR.
72
+	 *
73
+	 * @var int
74
+	 */
75
+	private $encode_flags;
76
+
77
+	/**
78
+	 * @var int
79
+	 */
80
+	private $last_error_code = JSON_ERROR_NONE;
81
+
82
+	/**
83
+	 * @var string
84
+	 */
85
+	private $last_error_msg = JsonDataHandler::NO_ERROR_MSG;
86
+
87
+
88
+	/**
89
+	 * JsonDataHandler constructor.
90
+	 */
91
+	public function __construct()
92
+	{
93
+		if (! defined('JSON_INVALID_UTF8_IGNORE')) {
94
+			define('JSON_INVALID_UTF8_IGNORE', 1048576);
95
+		}
96
+		if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
97
+			define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
98
+		}
99
+		if (! defined('JSON_THROW_ON_ERROR')) {
100
+			define('JSON_THROW_ON_ERROR', 4194304);
101
+		}
102
+	}
103
+
104
+
105
+	/**
106
+	 * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
107
+	 *
108
+	 * @param string $data_type
109
+	 * @param int    $decode_flags
110
+	 * @param int    $encode_flags
111
+	 * @param int    $depth
112
+	 */
113
+	public function configure(
114
+		string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
115
+		int $decode_flags = 0,
116
+		int $encode_flags = 0,
117
+		int $depth = 512
118
+	) {
119
+		$this->setDataType($data_type);
120
+		$this->setDecodeFlags($decode_flags);
121
+		$this->setDepth($depth);
122
+		$this->setEncodeFlags($encode_flags);
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $data_type
128
+	 */
129
+	public function setDataType(string $data_type): void
130
+	{
131
+		$this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
132
+						   || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
133
+						   || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
134
+			? $data_type
135
+			: JsonDataHandler::DATA_TYPE_USE_FLAGS;
136
+	}
137
+
138
+
139
+	/**
140
+	 * One or more Bitmask values:
141
+	 * JSON_BIGINT_AS_STRING,
142
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
143
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
144
+	 * JSON_OBJECT_AS_ARRAY,
145
+	 * JSON_THROW_ON_ERROR              PHP >= 7.3
146
+	 *
147
+	 * pass multiple values separated with |
148
+	 * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
149
+	 *
150
+	 * @param int $decode_flags
151
+	 */
152
+	public function setDecodeFlags(int $decode_flags): void
153
+	{
154
+		$this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
155
+							  || $decode_flags === JSON_OBJECT_AS_ARRAY
156
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
157
+							  || $decode_flags === JSON_INVALID_UTF8_IGNORE
158
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
159
+							  || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
160
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
161
+							  || $decode_flags === JSON_THROW_ON_ERROR
162
+			? $decode_flags
163
+			: 0;
164
+	}
165
+
166
+
167
+	/**
168
+	 * @param int $depth
169
+	 */
170
+	public function setDepth(int $depth): void
171
+	{
172
+		$depth       = absint($depth);
173
+		$this->depth = $depth ?: 512;
174
+	}
175
+
176
+
177
+	/**
178
+	 * One or more Bitmask values:
179
+	 * JSON_FORCE_OBJECT,
180
+	 * JSON_HEX_QUOT,
181
+	 * JSON_HEX_TAG,
182
+	 * JSON_HEX_AMP,
183
+	 * JSON_HEX_APOS,
184
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
185
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
186
+	 * JSON_NUMERIC_CHECK,
187
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
188
+	 * JSON_PRESERVE_ZERO_FRACTION,
189
+	 * JSON_PRETTY_PRINT,
190
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
191
+	 * JSON_UNESCAPED_SLASHES,
192
+	 * JSON_UNESCAPED_UNICODE,
193
+	 * JSON_THROW_ON_ERROR.             PHP >= 7.3
194
+	 *
195
+	 * pass multiple values separated with |
196
+	 * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
197
+	 *
198
+	 * @param int $encode_flags
199
+	 */
200
+	public function setEncodeFlags(int $encode_flags): void
201
+	{
202
+		$this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
203
+							  || $encode_flags === JSON_HEX_QUOT
204
+							  || $encode_flags === JSON_HEX_TAG
205
+							  || $encode_flags === JSON_HEX_AMP
206
+							  || $encode_flags === JSON_HEX_APOS
207
+							  || $encode_flags === JSON_NUMERIC_CHECK
208
+							  || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
209
+							  || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
210
+							  || $encode_flags === JSON_PRETTY_PRINT
211
+							  || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
212
+							  || $encode_flags === JSON_UNESCAPED_SLASHES
213
+							  || $encode_flags === JSON_UNESCAPED_UNICODE
214
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
215
+							  || $encode_flags === JSON_INVALID_UTF8_IGNORE
216
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
217
+							  || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
218
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
219
+							  || $encode_flags === JSON_THROW_ON_ERROR
220
+			? $encode_flags
221
+			: 0;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return bool|null
227
+	 */
228
+	private function asAssociative(): ?bool
229
+	{
230
+		switch ($this->data_type) {
231
+			case JsonDataHandler::DATA_TYPE_ARRAY:
232
+				return true;
233
+			case JsonDataHandler::DATA_TYPE_OBJECT:
234
+				return false;
235
+			case JsonDataHandler::DATA_TYPE_USE_FLAGS:
236
+				return null;
237
+		}
238
+		return null;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @param array|string $json
244
+	 * @return array|mixed|stdClass
245
+	 */
246
+	public function decodeJson($json)
247
+	{
248
+		$this->resetErrors();
249
+		if ($this->isJson($json)) {
250
+			$this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
251
+			$this->last_error_code = json_last_error();
252
+			$this->last_error_msg  = json_last_error_msg();
253
+		} else {
254
+			$this->decoded_data    = $json;
255
+			$this->last_error_code = JSON_ERROR_NONE;
256
+			$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
257
+		}
258
+		return $this->decoded_data;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @param $data
264
+	 * @return string
265
+	 */
266
+	public function encodeData($data): string
267
+	{
268
+		$this->resetErrors();
269
+		if ($this->isJson($data)) {
270
+			$this->encoded_data = $data;
271
+			$this->last_error_code = JSON_ERROR_NONE;
272
+			$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
273
+		} else {
274
+			$this->encoded_data = json_encode($data, $this->encode_flags, $this->depth);
275
+			$this->last_error_code = json_last_error();
276
+			$this->last_error_msg  = json_last_error_msg();
277
+		}
278
+		return $this->encoded_data ?: '{}';
279
+	}
280
+
281
+
282
+	/**
283
+	 * @return array|stdClass
284
+	 */
285
+	public function getDecodedData()
286
+	{
287
+		return $this->decoded_data;
288
+	}
289
+
290
+
291
+	/**
292
+	 * @return string
293
+	 */
294
+	public function getEncodedData(): string
295
+	{
296
+		return $this->encoded_data;
297
+	}
298
+
299
+
300
+	/**
301
+	 * @param bool $reset
302
+	 * @return int
303
+	 */
304
+	public function getLastErrorCode(bool $reset = false): int
305
+	{
306
+		$last_error = $this->last_error_code;
307
+		if ($reset) {
308
+			$this->resetErrors();
309
+		}
310
+		return $last_error;
311
+	}
312
+
313
+
314
+	/**
315
+	 * @param bool $reset
316
+	 * @return string
317
+	 */
318
+	public function getLastErrorMessage(bool $reset = false): string
319
+	{
320
+		$last_error = $this->last_error_msg;
321
+		if ($reset) {
322
+			$this->resetErrors();
323
+		}
324
+		return $last_error;
325
+	}
326
+
327
+
328
+	/**
329
+	 * @param array|string $maybe_json
330
+	 * @return bool
331
+	 */
332
+	public function isJson($maybe_json): bool
333
+	{
334
+		if (! is_string($maybe_json)) {
335
+			return false;
336
+		}
337
+		$decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags);
338
+		return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json));
339
+	}
340
+
341
+
342
+	/**
343
+	 * @since $VID:$
344
+	 */
345
+	public function resetErrors()
346
+	{
347
+		$this->last_error_code = JSON_ERROR_NONE;
348
+		$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
349
+	}
350 350
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
core/db_classes/EE_Form_Submission.class.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -5,152 +5,152 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
core/services/form/meta/HelpText.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -15,141 +15,141 @@
 block discarded – undo
15 15
 class HelpText implements JsonableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var JsonDataHandler
20
-     */
21
-    private $json_data_handler;
22
-
23
-    /**
24
-     * Additional text displayed alongside a form input to assist users with completing the form.
25
-     *
26
-     * @var string
27
-     */
28
-    private $helpText;
29
-
30
-    /**
31
-     * Custom HTML classes to be applied to this form input's help text.
32
-     *
33
-     * @var array
34
-     */
35
-    private $htmlClasses;
36
-
37
-
38
-    /**
39
-     * HelpText constructor.
40
-     *
41
-     * @param JsonDataHandler $json_data_handler
42
-     * @param array           $htmlClass
43
-     * @param string          $helpText
44
-     */
45
-    public function __construct(
46
-        JsonDataHandler $json_data_handler,
47
-        array $htmlClass,
48
-        string $helpText
49
-    ) {
50
-        $this->json_data_handler = $json_data_handler;
51
-        $this->setHtmlClasses($htmlClass);
52
-        $this->setHelpText($helpText);
53
-    }
54
-
55
-
56
-    /**
57
-     * @param string $json
58
-     * @return HelpText
59
-     */
60
-    public static function fromJson(string $json): HelpText
61
-    {
62
-        $json_data_handler = new JsonDataHandler();
63
-        $json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
64
-        $data      = $json_data_handler->decodeJson($json);
65
-        $htmlClass = (array) ($data->htmlClass ?? []);
66
-        $helpText  = $data->helpText ?? '';
67
-        return new HelpText($json_data_handler, $htmlClass, $helpText);
68
-    }
69
-
70
-
71
-    /**
72
-     * @return array
73
-     */
74
-    public function toArray(): array
75
-    {
76
-        return [
77
-            'helpText'  => $this->helpText,
78
-            'htmlClass' => $this->htmlClasses(),
79
-        ];
80
-    }
81
-
82
-
83
-    /**
84
-     * @return string
85
-     */
86
-    public function toJson(): string
87
-    {
88
-        return $this->json_data_handler->encodeData($this->toArray());
89
-    }
90
-
91
-
92
-    /**
93
-     * Input label displayed on public forms, ie: the actual question text.
94
-     *
95
-     * @return string
96
-     */
97
-    public function helpText(): string
98
-    {
99
-        return $this->helpText;
100
-    }
101
-
102
-
103
-    /**
104
-     * @param string $helpText
105
-     */
106
-    public function setHelpText(string $helpText): void
107
-    {
108
-        $this->helpText = sanitize_text_field($helpText);
109
-    }
110
-
111
-
112
-    /**
113
-     * Custom HTML classes to be applied to this form input's help text.
114
-     * returns a concatenated string unless $as_array is set to true
115
-     *
116
-     * @return array|string
117
-     */
118
-    public function htmlClasses($as_array = false)
119
-    {
120
-        return $as_array
121
-            ? $this->htmlClasses
122
-            : implode(' ', $this->htmlClasses);
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $htmlClass
128
-     */
129
-    public function addHtmlClass(string $htmlClass): void
130
-    {
131
-        $htmlClass = sanitize_key($htmlClass);
132
-        if (! in_array($htmlClass, $this->htmlClasses, true)) {
133
-            $this->htmlClasses[] = $htmlClass;
134
-        }
135
-    }
136
-
137
-
138
-    /**
139
-     * @param string $htmlClass
140
-     */
141
-    public function removeHtmlClass(string $htmlClass): void
142
-    {
143
-        $htmlClass = sanitize_key($htmlClass);
144
-        unset($this->htmlClasses[ $htmlClass ]);
145
-    }
146
-
147
-
148
-    /**
149
-     * @param array $htmlClasses
150
-     */
151
-    public function setHtmlClasses(array $htmlClasses): void
152
-    {
153
-        $this->htmlClasses = array_map('sanitize_key', $htmlClasses);
154
-    }
18
+	/**
19
+	 * @var JsonDataHandler
20
+	 */
21
+	private $json_data_handler;
22
+
23
+	/**
24
+	 * Additional text displayed alongside a form input to assist users with completing the form.
25
+	 *
26
+	 * @var string
27
+	 */
28
+	private $helpText;
29
+
30
+	/**
31
+	 * Custom HTML classes to be applied to this form input's help text.
32
+	 *
33
+	 * @var array
34
+	 */
35
+	private $htmlClasses;
36
+
37
+
38
+	/**
39
+	 * HelpText constructor.
40
+	 *
41
+	 * @param JsonDataHandler $json_data_handler
42
+	 * @param array           $htmlClass
43
+	 * @param string          $helpText
44
+	 */
45
+	public function __construct(
46
+		JsonDataHandler $json_data_handler,
47
+		array $htmlClass,
48
+		string $helpText
49
+	) {
50
+		$this->json_data_handler = $json_data_handler;
51
+		$this->setHtmlClasses($htmlClass);
52
+		$this->setHelpText($helpText);
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param string $json
58
+	 * @return HelpText
59
+	 */
60
+	public static function fromJson(string $json): HelpText
61
+	{
62
+		$json_data_handler = new JsonDataHandler();
63
+		$json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
64
+		$data      = $json_data_handler->decodeJson($json);
65
+		$htmlClass = (array) ($data->htmlClass ?? []);
66
+		$helpText  = $data->helpText ?? '';
67
+		return new HelpText($json_data_handler, $htmlClass, $helpText);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return array
73
+	 */
74
+	public function toArray(): array
75
+	{
76
+		return [
77
+			'helpText'  => $this->helpText,
78
+			'htmlClass' => $this->htmlClasses(),
79
+		];
80
+	}
81
+
82
+
83
+	/**
84
+	 * @return string
85
+	 */
86
+	public function toJson(): string
87
+	{
88
+		return $this->json_data_handler->encodeData($this->toArray());
89
+	}
90
+
91
+
92
+	/**
93
+	 * Input label displayed on public forms, ie: the actual question text.
94
+	 *
95
+	 * @return string
96
+	 */
97
+	public function helpText(): string
98
+	{
99
+		return $this->helpText;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param string $helpText
105
+	 */
106
+	public function setHelpText(string $helpText): void
107
+	{
108
+		$this->helpText = sanitize_text_field($helpText);
109
+	}
110
+
111
+
112
+	/**
113
+	 * Custom HTML classes to be applied to this form input's help text.
114
+	 * returns a concatenated string unless $as_array is set to true
115
+	 *
116
+	 * @return array|string
117
+	 */
118
+	public function htmlClasses($as_array = false)
119
+	{
120
+		return $as_array
121
+			? $this->htmlClasses
122
+			: implode(' ', $this->htmlClasses);
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $htmlClass
128
+	 */
129
+	public function addHtmlClass(string $htmlClass): void
130
+	{
131
+		$htmlClass = sanitize_key($htmlClass);
132
+		if (! in_array($htmlClass, $this->htmlClasses, true)) {
133
+			$this->htmlClasses[] = $htmlClass;
134
+		}
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param string $htmlClass
140
+	 */
141
+	public function removeHtmlClass(string $htmlClass): void
142
+	{
143
+		$htmlClass = sanitize_key($htmlClass);
144
+		unset($this->htmlClasses[ $htmlClass ]);
145
+	}
146
+
147
+
148
+	/**
149
+	 * @param array $htmlClasses
150
+	 */
151
+	public function setHtmlClasses(array $htmlClasses): void
152
+	{
153
+		$this->htmlClasses = array_map('sanitize_key', $htmlClasses);
154
+	}
155 155
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Answer.model.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -10,145 +10,145 @@
 block discarded – undo
10 10
 class EEM_Answer extends EEM_Base
11 11
 {
12 12
 
13
-    /**
14
-     * private instance of the EEM_Answer object
15
-     * @type EEM_Answer
16
-     */
17
-    protected static $_instance = null;
13
+	/**
14
+	 * private instance of the EEM_Answer object
15
+	 * @type EEM_Answer
16
+	 */
17
+	protected static $_instance = null;
18 18
 
19
-    /**
20
-     * Mapping from system question ids to attendee field names
21
-     * @type array
22
-     * @deprecated since version 4.8.8
23
-     */
24
-    protected $_question_id_to_att_field_map = array(
25
-        EEM_Attendee::fname_question_id => 'ATT_fname',
26
-        EEM_Attendee::lname_question_id => 'ATT_lname',
27
-        EEM_Attendee::email_question_id => 'ATT_email',
28
-        EEM_Attendee::address_question_id => 'ATT_address',
29
-        EEM_Attendee::address2_question_id => 'ATT_address2',
30
-        EEM_Attendee::city_question_id => 'ATT_city',
31
-        EEM_Attendee::state_question_id => 'STA_ID',
32
-        EEM_Attendee::country_question_id => 'CNT_ISO',
33
-        EEM_Attendee::zip_question_id => 'ATT_zip',
34
-        EEM_Attendee::phone_question_id => 'ATT_phone'
35
-    );
19
+	/**
20
+	 * Mapping from system question ids to attendee field names
21
+	 * @type array
22
+	 * @deprecated since version 4.8.8
23
+	 */
24
+	protected $_question_id_to_att_field_map = array(
25
+		EEM_Attendee::fname_question_id => 'ATT_fname',
26
+		EEM_Attendee::lname_question_id => 'ATT_lname',
27
+		EEM_Attendee::email_question_id => 'ATT_email',
28
+		EEM_Attendee::address_question_id => 'ATT_address',
29
+		EEM_Attendee::address2_question_id => 'ATT_address2',
30
+		EEM_Attendee::city_question_id => 'ATT_city',
31
+		EEM_Attendee::state_question_id => 'STA_ID',
32
+		EEM_Attendee::country_question_id => 'CNT_ISO',
33
+		EEM_Attendee::zip_question_id => 'ATT_zip',
34
+		EEM_Attendee::phone_question_id => 'ATT_phone'
35
+	);
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     *  constructor
41
-     */
42
-    protected function __construct($timezone = null)
43
-    {
44
-        $this->singular_item = __('Answer', 'event_espresso');
45
-        $this->plural_item = __('Answers', 'event_espresso');
46
-        $this->_tables = array(
47
-            'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID')
48
-        );
49
-        $this->_fields = array(
50
-            'Answer' => array(
51
-                'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')),
52
-                'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'),
53
-                'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'),
54
-                'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '')
55
-            ));
56
-        $this->_model_relations = array(
57
-            'Registration' => new EE_Belongs_To_Relation(),
58
-            'Question' => new EE_Belongs_To_Relation()
59
-        );
60
-        $this->_model_chain_to_wp_user = 'Registration.Event';
61
-        $this->_caps_slug = 'registrations';
62
-        parent::__construct($timezone);
63
-    }
39
+	/**
40
+	 *  constructor
41
+	 */
42
+	protected function __construct($timezone = null)
43
+	{
44
+		$this->singular_item = __('Answer', 'event_espresso');
45
+		$this->plural_item = __('Answers', 'event_espresso');
46
+		$this->_tables = array(
47
+			'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID')
48
+		);
49
+		$this->_fields = array(
50
+			'Answer' => array(
51
+				'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')),
52
+				'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'),
53
+				'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'),
54
+				'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '')
55
+			));
56
+		$this->_model_relations = array(
57
+			'Registration' => new EE_Belongs_To_Relation(),
58
+			'Question' => new EE_Belongs_To_Relation()
59
+		);
60
+		$this->_model_chain_to_wp_user = 'Registration.Event';
61
+		$this->_caps_slug = 'registrations';
62
+		parent::__construct($timezone);
63
+	}
64 64
 
65 65
 
66 66
 
67
-    /**
68
-     * Gets the string answer to the question for this registration (it could either be stored
69
-     * on the attendee or in the answer table. This function finds its value regardless)
70
-     * @param EE_Registration $registration
71
-     * @param int $question_id
72
-     * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value'
73
-     * @return string
74
-     */
75
-    public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false)
76
-    {
77
-        $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
78
-        if ($value === null) {
79
-            $answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
80
-            if ($answer_obj instanceof EE_Answer) {
81
-                if ($pretty_answer) {
82
-                    $value = $answer_obj->pretty_value();
83
-                } else {
84
-                    $value = $answer_obj->value();
85
-                }
86
-            }
87
-        }
88
-        return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id);
89
-    }
67
+	/**
68
+	 * Gets the string answer to the question for this registration (it could either be stored
69
+	 * on the attendee or in the answer table. This function finds its value regardless)
70
+	 * @param EE_Registration $registration
71
+	 * @param int $question_id
72
+	 * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value'
73
+	 * @return string
74
+	 */
75
+	public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false)
76
+	{
77
+		$value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
78
+		if ($value === null) {
79
+			$answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
80
+			if ($answer_obj instanceof EE_Answer) {
81
+				if ($pretty_answer) {
82
+					$value = $answer_obj->pretty_value();
83
+				} else {
84
+					$value = $answer_obj->value();
85
+				}
86
+			}
87
+		}
88
+		return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id);
89
+	}
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * Gets the EE_Answer object for the question for this registration (if it exists)
95
-     * @param EE_Registration $registration
96
-     * @param int $question_id
97
-     * @return EE_Answer
98
-     */
99
-    public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null)
100
-    {
101
-        $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() )));
102
-        return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
103
-    }
93
+	/**
94
+	 * Gets the EE_Answer object for the question for this registration (if it exists)
95
+	 * @param EE_Registration $registration
96
+	 * @param int $question_id
97
+	 * @return EE_Answer
98
+	 */
99
+	public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null)
100
+	{
101
+		$answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() )));
102
+		return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
103
+	}
104 104
 
105 105
 
106
-    /**
107
-     * Gets the string answer to the question for this registration's attendee
108
-     *
109
-     * @param EE_Registration $registration
110
-     * @param int|string      $question_system_id if an INT this is understood to be the question's ID; if a string
111
-     *                                            then it should be its QST_system value. Passing in the QST_system
112
-     *                                            value is more efficient
113
-     * @param boolean         $pretty_answer
114
-     * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or
115
-     *                                            QST_system for a question corresponding to an attendee field, returns
116
-     *                                            null)
117
-     * @throws EE_Error
118
-     * @throws ReflectionException
119
-     */
120
-    public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false)
121
-    {
122
-        $value = null;
123
-        // backward compat: we still want to find the question's ID
124
-        if (is_numeric($question_system_id)) {
125
-            // find this question's QST_system value
126
-            $question_id = $question_system_id;
127
-            $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system');
128
-        } else {
129
-            $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID');
130
-        }
131
-        // only bother checking if the registration has an attendee
132
-        if ($registration->attendee() instanceof EE_Attendee) {
133
-            $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
134
-            if ($field_name) {
135
-                if ($pretty_answer) {
136
-                    if ($field_name === 'STA_ID') {
137
-                        $state = $registration->attendee()->state_obj();
138
-                        $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
139
-                    } elseif ($field_name === 'CNT_ISO') {
140
-                        $country = $registration->attendee()->country_obj();
141
-                        $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
142
-                    } else {
143
-                        $value = $registration->attendee()->get_pretty($field_name);
144
-                    }
145
-                    // if field name is blank, leave the value as null too
146
-                } else {
147
-                    $value = $registration->attendee()->get($field_name);
148
-                }
149
-            }
150
-            // if no field was found, leave value blank
151
-        }
152
-        return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id);
153
-    }
106
+	/**
107
+	 * Gets the string answer to the question for this registration's attendee
108
+	 *
109
+	 * @param EE_Registration $registration
110
+	 * @param int|string      $question_system_id if an INT this is understood to be the question's ID; if a string
111
+	 *                                            then it should be its QST_system value. Passing in the QST_system
112
+	 *                                            value is more efficient
113
+	 * @param boolean         $pretty_answer
114
+	 * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or
115
+	 *                                            QST_system for a question corresponding to an attendee field, returns
116
+	 *                                            null)
117
+	 * @throws EE_Error
118
+	 * @throws ReflectionException
119
+	 */
120
+	public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false)
121
+	{
122
+		$value = null;
123
+		// backward compat: we still want to find the question's ID
124
+		if (is_numeric($question_system_id)) {
125
+			// find this question's QST_system value
126
+			$question_id = $question_system_id;
127
+			$question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system');
128
+		} else {
129
+			$question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID');
130
+		}
131
+		// only bother checking if the registration has an attendee
132
+		if ($registration->attendee() instanceof EE_Attendee) {
133
+			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
134
+			if ($field_name) {
135
+				if ($pretty_answer) {
136
+					if ($field_name === 'STA_ID') {
137
+						$state = $registration->attendee()->state_obj();
138
+						$value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
139
+					} elseif ($field_name === 'CNT_ISO') {
140
+						$country = $registration->attendee()->country_obj();
141
+						$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
142
+					} else {
143
+						$value = $registration->attendee()->get_pretty($field_name);
144
+					}
145
+					// if field name is blank, leave the value as null too
146
+				} else {
147
+					$value = $registration->attendee()->get($field_name);
148
+				}
149
+			}
150
+			// if no field was found, leave value blank
151
+		}
152
+		return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id);
153
+	}
154 154
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Form_Section.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -152,10 +152,10 @@
 block discarded – undo
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');
Please login to merge, or discard this patch.
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -21,244 +21,244 @@
 block discarded – undo
21 21
  */
22 22
 class EEM_Form_Section extends EEM_Base
23 23
 {
24
-    public const APPLIES_TO_ALL         = 'all';
24
+	public const APPLIES_TO_ALL         = 'all';
25 25
 
26
-    public const APPLIES_TO_PRIMARY     = 'primary';
26
+	public const APPLIES_TO_PRIMARY     = 'primary';
27 27
 
28
-    public const APPLIES_TO_PURCHASER   = 'purchaser';
28
+	public const APPLIES_TO_PURCHASER   = 'purchaser';
29 29
 
30
-    public const APPLIES_TO_REGISTRANTS = 'registrants';
30
+	public const APPLIES_TO_REGISTRANTS = 'registrants';
31 31
 
32
-    /**
33
-     * @var EEM_Form_Section
34
-     */
35
-    protected static $_instance;
32
+	/**
33
+	 * @var EEM_Form_Section
34
+	 */
35
+	protected static $_instance;
36 36
 
37
-    /**
38
-     * @var RequestInterface
39
-     */
40
-    private $request;
37
+	/**
38
+	 * @var RequestInterface
39
+	 */
40
+	private $request;
41 41
 
42
-    /**
43
-     * @var array
44
-     */
45
-    private $valid_applies_to_options;
42
+	/**
43
+	 * @var array
44
+	 */
45
+	private $valid_applies_to_options;
46 46
 
47 47
 
48
-    /**
49
-     * EEM_Form_Section constructor.
50
-     *
51
-     * @param FormStatus  $form_status
52
-     * @param string|null $timezone
53
-     * @throws EE_Error
54
-     */
55
-    protected function __construct(FormStatus $form_status, ?string $timezone)
56
-    {
57
-        $this->valid_applies_to_options = apply_filters(
58
-            'FHEE__EEM_Form_Section__valid_applies_to_options',
59
-            [
60
-                EEM_Form_Section::APPLIES_TO_ALL         => esc_html__('All Registrants', 'event_espresso'),
61
-                EEM_Form_Section::APPLIES_TO_PRIMARY     => esc_html__('Primary Registrant Only', 'event_espresso'),
62
-                EEM_Form_Section::APPLIES_TO_PURCHASER   => esc_html__('Purchasing Agent', 'event_espresso'),
63
-                EEM_Form_Section::APPLIES_TO_REGISTRANTS => esc_html__('Additional Registrants', 'event_espresso'),
64
-            ]
65
-        );
48
+	/**
49
+	 * EEM_Form_Section constructor.
50
+	 *
51
+	 * @param FormStatus  $form_status
52
+	 * @param string|null $timezone
53
+	 * @throws EE_Error
54
+	 */
55
+	protected function __construct(FormStatus $form_status, ?string $timezone)
56
+	{
57
+		$this->valid_applies_to_options = apply_filters(
58
+			'FHEE__EEM_Form_Section__valid_applies_to_options',
59
+			[
60
+				EEM_Form_Section::APPLIES_TO_ALL         => esc_html__('All Registrants', 'event_espresso'),
61
+				EEM_Form_Section::APPLIES_TO_PRIMARY     => esc_html__('Primary Registrant Only', 'event_espresso'),
62
+				EEM_Form_Section::APPLIES_TO_PURCHASER   => esc_html__('Purchasing Agent', 'event_espresso'),
63
+				EEM_Form_Section::APPLIES_TO_REGISTRANTS => esc_html__('Additional Registrants', 'event_espresso'),
64
+			]
65
+		);
66 66
 
67
-        $this->singular_item = esc_html__('Form Section', 'event_espresso');
68
-        $this->plural_item   = esc_html__('Form Sections', 'event_espresso');
67
+		$this->singular_item = esc_html__('Form Section', 'event_espresso');
68
+		$this->plural_item   = esc_html__('Form Sections', 'event_espresso');
69 69
 
70
-        $this->_tables          = [
71
-            'Form_Section' => new EE_Primary_Table('esp_form_section', 'FSC_UUID'),
72
-        ];
73
-        $this->_fields          = [
74
-            'Form_Section' => [
75
-                'FSC_UUID'      => new EE_Primary_Key_String_Field(
76
-                    'FSC_UUID',
77
-                    esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso')
78
-                ),
79
-                'FSC_appliesTo' => new EE_Enum_Text_Field(
80
-                    'FSC_appliesTo',
81
-                    esc_html(
82
-                        sprintf(
83
-                            /* translators: 1 class name */
84
-                            __(
85
-                                'Form user type that this form section should be presented to. Values correspond to the %s constants.',
86
-                                'event_espresso'
87
-                            ),
88
-                            'EEM_Form_Section::APPLIES_TO_*'
89
-                        )
90
-                    ),
91
-                    false,
92
-                    EEM_Form_Section::APPLIES_TO_ALL,
93
-                    $this->valid_applies_to_options
94
-                ),
95
-                'FSC_attributes' => new EE_JSON_Field(
96
-                    'FSC_attributes',
97
-                    esc_html__(
98
-                        'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.',
99
-                        'event_espresso'
100
-                    ),
101
-                    false,
102
-                    '{}'
103
-                ),
104
-                'FSC_belongsTo' => new EE_Plain_Text_Field(
105
-                    'FSC_belongsTo',
106
-                    esc_html__('UUID of parent form section that this one belongs to.', 'event_espresso'),
107
-                    false,
108
-                    ''
109
-                ),
110
-                'FSC_label' => new EE_JSON_Field(
111
-                    'FSC_label',
112
-                    esc_html__(
113
-                        'JSON string of properties pertaining to a form section\'s label.',
114
-                        'event_espresso'
115
-                    ),
116
-                    false,
117
-                    '{}'
118
-                ),
119
-                'FSC_order'     => new EE_Integer_Field(
120
-                    'FSC_order',
121
-                    esc_html__('Order in which form section appears in a form.', 'event_espresso'),
122
-                    false,
123
-                    0
124
-                ),
125
-                'FSC_status'    => new EE_Enum_Text_Field(
126
-                    'FSC_status',
127
-                    esc_html(
128
-                        sprintf(
129
-                            /* translators: 1 class name */
130
-                            __(
131
-                                'Whether form section is active, archived, shared, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.',
132
-                                'event_espresso'
133
-                            ),
134
-                            'EventEspresso\core\services\form\meta\FormStatus'
135
-                        )
136
-                    ),
137
-                    false,
138
-                    FormStatus::ACTIVE,
139
-                    $form_status->validStatusOptions()
140
-                ),
141
-                'FSC_wpUser'    => new EE_WP_User_Field(
142
-                    'FSC_wpUser',
143
-                    esc_html__('ID of the WP User that created this form section.', 'event_espresso'),
144
-                    false
145
-                ),
146
-            ],
147
-        ];
148
-        $this->_model_relations = [
149
-            'Form_Element' => new EE_Has_Many_Relation(),
150
-            'Form_Submission' => new EE_Has_Many_Relation(),
151
-            'WP_User'    => new EE_Belongs_To_Relation(),
152
-        ];
153
-        // this model is generally available for reading
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');
159
-        $this->_cap_restriction_generators         = $restrictions;
160
-        parent::__construct($timezone);
161
-        $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
162
-    }
70
+		$this->_tables          = [
71
+			'Form_Section' => new EE_Primary_Table('esp_form_section', 'FSC_UUID'),
72
+		];
73
+		$this->_fields          = [
74
+			'Form_Section' => [
75
+				'FSC_UUID'      => new EE_Primary_Key_String_Field(
76
+					'FSC_UUID',
77
+					esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso')
78
+				),
79
+				'FSC_appliesTo' => new EE_Enum_Text_Field(
80
+					'FSC_appliesTo',
81
+					esc_html(
82
+						sprintf(
83
+							/* translators: 1 class name */
84
+							__(
85
+								'Form user type that this form section should be presented to. Values correspond to the %s constants.',
86
+								'event_espresso'
87
+							),
88
+							'EEM_Form_Section::APPLIES_TO_*'
89
+						)
90
+					),
91
+					false,
92
+					EEM_Form_Section::APPLIES_TO_ALL,
93
+					$this->valid_applies_to_options
94
+				),
95
+				'FSC_attributes' => new EE_JSON_Field(
96
+					'FSC_attributes',
97
+					esc_html__(
98
+						'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.',
99
+						'event_espresso'
100
+					),
101
+					false,
102
+					'{}'
103
+				),
104
+				'FSC_belongsTo' => new EE_Plain_Text_Field(
105
+					'FSC_belongsTo',
106
+					esc_html__('UUID of parent form section that this one belongs to.', 'event_espresso'),
107
+					false,
108
+					''
109
+				),
110
+				'FSC_label' => new EE_JSON_Field(
111
+					'FSC_label',
112
+					esc_html__(
113
+						'JSON string of properties pertaining to a form section\'s label.',
114
+						'event_espresso'
115
+					),
116
+					false,
117
+					'{}'
118
+				),
119
+				'FSC_order'     => new EE_Integer_Field(
120
+					'FSC_order',
121
+					esc_html__('Order in which form section appears in a form.', 'event_espresso'),
122
+					false,
123
+					0
124
+				),
125
+				'FSC_status'    => new EE_Enum_Text_Field(
126
+					'FSC_status',
127
+					esc_html(
128
+						sprintf(
129
+							/* translators: 1 class name */
130
+							__(
131
+								'Whether form section is active, archived, shared, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.',
132
+								'event_espresso'
133
+							),
134
+							'EventEspresso\core\services\form\meta\FormStatus'
135
+						)
136
+					),
137
+					false,
138
+					FormStatus::ACTIVE,
139
+					$form_status->validStatusOptions()
140
+				),
141
+				'FSC_wpUser'    => new EE_WP_User_Field(
142
+					'FSC_wpUser',
143
+					esc_html__('ID of the WP User that created this form section.', 'event_espresso'),
144
+					false
145
+				),
146
+			],
147
+		];
148
+		$this->_model_relations = [
149
+			'Form_Element' => new EE_Has_Many_Relation(),
150
+			'Form_Submission' => new EE_Has_Many_Relation(),
151
+			'WP_User'    => new EE_Belongs_To_Relation(),
152
+		];
153
+		// this model is generally available for reading
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');
159
+		$this->_cap_restriction_generators         = $restrictions;
160
+		parent::__construct($timezone);
161
+		$this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
162
+	}
163 163
 
164 164
 
165
-    /**
166
-     * @param array $query_params
167
-     * @return array
168
-     */
169
-    private function addDefaultWhereConditions(array $query_params): array
170
-    {
171
-        // might need to add a way to identify GQL requests for admin domains
172
-        $admin_request                            = $this->request->isAdmin() || $this->request->isAdminAjax();
173
-        $query_params['default_where_conditions'] = $admin_request
174
-            ? EEM_Base::default_where_conditions_none
175
-            : EEM_Base::default_where_conditions_all;
176
-        return $query_params;
177
-    }
165
+	/**
166
+	 * @param array $query_params
167
+	 * @return array
168
+	 */
169
+	private function addDefaultWhereConditions(array $query_params): array
170
+	{
171
+		// might need to add a way to identify GQL requests for admin domains
172
+		$admin_request                            = $this->request->isAdmin() || $this->request->isAdminAjax();
173
+		$query_params['default_where_conditions'] = $admin_request
174
+			? EEM_Base::default_where_conditions_none
175
+			: EEM_Base::default_where_conditions_all;
176
+		return $query_params;
177
+	}
178 178
 
179 179
 
180
-    /**
181
-     * form sections should always be sorted in ascending order via the FSC_order field
182
-     *
183
-     * @param array $query_params
184
-     * @return array
185
-     */
186
-    private function addOrderByQueryParams(array $query_params): array
187
-    {
188
-        $query_params['order_by'] = ['FSC_order' => 'ASC'];
189
-        return $query_params;
190
-    }
180
+	/**
181
+	 * form sections should always be sorted in ascending order via the FSC_order field
182
+	 *
183
+	 * @param array $query_params
184
+	 * @return array
185
+	 */
186
+	private function addOrderByQueryParams(array $query_params): array
187
+	{
188
+		$query_params['order_by'] = ['FSC_order' => 'ASC'];
189
+		return $query_params;
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * returns an array of Form Sections that should be added by default to new Events
195
-     *
196
-     * @return EE_Form_Section[]
197
-     * @throws EE_Error
198
-     */
199
-    public function getDefaultFormSections(): array
200
-    {
201
-        return $this->getFormSections(['FSC_status' => FormStatus::DEFAULT]);
202
-    }
193
+	/**
194
+	 * returns an array of Form Sections that should be added by default to new Events
195
+	 *
196
+	 * @return EE_Form_Section[]
197
+	 * @throws EE_Error
198
+	 */
199
+	public function getDefaultFormSections(): array
200
+	{
201
+		return $this->getFormSections(['FSC_status' => FormStatus::DEFAULT]);
202
+	}
203 203
 
204 204
 
205
-    /**
206
-     * returns an array of Form Sections for the specified parent Form Section
207
-     *
208
-     * @param string $FSC_UUID
209
-     * @return EE_Form_Section[]
210
-     * @throws EE_Error
211
-     */
212
-    public function getChildFormSections(string $FSC_UUID): array
213
-    {
214
-        return $this->getFormSections(['FSC_belongsTo' => $FSC_UUID]);
215
-    }
205
+	/**
206
+	 * returns an array of Form Sections for the specified parent Form Section
207
+	 *
208
+	 * @param string $FSC_UUID
209
+	 * @return EE_Form_Section[]
210
+	 * @throws EE_Error
211
+	 */
212
+	public function getChildFormSections(string $FSC_UUID): array
213
+	{
214
+		return $this->getFormSections(['FSC_belongsTo' => $FSC_UUID]);
215
+	}
216 216
 
217 217
 
218
-    /**
219
-     * @return EE_Form_Section[]
220
-     * @throws EE_Error
221
-     */
222
-    public function getFormSections(array $where_params): array
223
-    {
224
-        $query_params = $this->addDefaultWhereConditions([$where_params]);
225
-        $query_params = $this->addOrderByQueryParams($query_params);
226
-        return $this->get_all($query_params);
227
-    }
218
+	/**
219
+	 * @return EE_Form_Section[]
220
+	 * @throws EE_Error
221
+	 */
222
+	public function getFormSections(array $where_params): array
223
+	{
224
+		$query_params = $this->addDefaultWhereConditions([$where_params]);
225
+		$query_params = $this->addOrderByQueryParams($query_params);
226
+		return $this->get_all($query_params);
227
+	}
228 228
 
229 229
 
230
-    /**
231
-     * returns an array of Form Sections for the specified Event
232
-     *
233
-     * @param EE_Event $event
234
-     * @return EE_Form_Section[]
235
-     * @throws EE_Error
236
-     * @throws ReflectionException
237
-     */
238
-    public function getFormSectionsForEvent(EE_Event $event): array
239
-    {
240
-        $FSC_UUID = $event->registrationFormUuid();
241
-        return ! empty($FSC_UUID)
242
-            ? $this->getFormSections(
243
-                [
244
-                    'OR' => [
245
-                        'FSC_UUID'      => $FSC_UUID, // top level form
246
-                        'FSC_belongsTo' => $FSC_UUID, // child form sections
247
-                    ]
248
-                ]
249
-            )
250
-            : [];
251
-    }
230
+	/**
231
+	 * returns an array of Form Sections for the specified Event
232
+	 *
233
+	 * @param EE_Event $event
234
+	 * @return EE_Form_Section[]
235
+	 * @throws EE_Error
236
+	 * @throws ReflectionException
237
+	 */
238
+	public function getFormSectionsForEvent(EE_Event $event): array
239
+	{
240
+		$FSC_UUID = $event->registrationFormUuid();
241
+		return ! empty($FSC_UUID)
242
+			? $this->getFormSections(
243
+				[
244
+					'OR' => [
245
+						'FSC_UUID'      => $FSC_UUID, // top level form
246
+						'FSC_belongsTo' => $FSC_UUID, // child form sections
247
+					]
248
+				]
249
+			)
250
+			: [];
251
+	}
252 252
 
253 253
 
254
-    /**
255
-     * @param bool $constants_only
256
-     * @return array
257
-     */
258
-    public function validAppliesToOptions(bool $constants_only = false): array
259
-    {
260
-        return $constants_only
261
-            ? array_keys($this->valid_applies_to_options)
262
-            : $this->valid_applies_to_options;
263
-    }
254
+	/**
255
+	 * @param bool $constants_only
256
+	 * @return array
257
+	 */
258
+	public function validAppliesToOptions(bool $constants_only = false): array
259
+	{
260
+		return $constants_only
261
+			? array_keys($this->valid_applies_to_options)
262
+			: $this->valid_applies_to_options;
263
+	}
264 264
 }
Please login to merge, or discard this patch.
services/graphql/connection_resolvers/FormElementConnectionResolver.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -14,122 +14,122 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.