PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/ValueObjects/Confirmation/Confirmation.php +99 -15 0.2.1 → 1.5 View file →
@@ -1,20 +1,19 @@
1 1 <?php
2 2
3 3 namespace IvyForms\ValueObjects\Confirmation;
4 4
5 -// phpcs:disable PSR1.Files.SideEffects
6 -if (!defined('ABSPATH')) {
7 - exit; // Exit if accessed directly
8 -}
9 -
10 5 use IvyForms\Common\Exceptions\InvalidArgumentException;
11 6 use IvyForms\Common\Exceptions\ValidationException;
7 +use IvyForms\Services\Translations\BackendStrings;
12 8
13 9 /**
14 10 * Class Confirmation
15 11 *
16 12 * @package IvyForms\ValueObjects\Confirmation
13 + *
14 + * @SuppressWarnings(PHPMD.ExcessiveParameterList)
15 + * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
17 16 */
18 17 final class Confirmation
19 18 {
20 19 /**
@@ -27,8 +26,12 @@
27 26 public int $formId;
28 27 /**
29 28 * @var string
30 29 */
30 + public string $name;
31 + /**
32 + * @var string
33 + */
31 34 public string $type;
32 35 /**
33 36 * @var bool
34 37 */
@@ -48,8 +51,20 @@
48 51 /**
49 52 * @var string
50 53 */
51 54 public string $page;
55 + /**
56 + * @var int
57 + */
58 + public int $position;
59 + /**
60 + * @var bool
61 + */
62 + public bool $isDefault;
63 + /**
64 + * @var array<string, mixed>
65 + */
66 + public array $smartLogic;
52 67
53 68 /**
54 69 * Confirmation constructor.
55 70 *
@@ -54,8 +69,9 @@
54 69 * Confirmation constructor.
55 70 *
56 71 * @param int $id
57 72 * @param int $formId
73 + * @param string $name
58 74 * @param string $type
59 75 * @param bool $enabled
60 76 * @param bool $showForm
61 77 * @param string $message
@@ -60,28 +76,39 @@
60 76 * @param bool $showForm
61 77 * @param string $message
62 78 * @param string $url
63 79 * @param string $page
80 + * @param int $position
81 + * @param bool $isDefault
82 + * @param array<string, mixed> $smartLogic
64 83 * @throws InvalidArgumentException|ValidationException
65 84 */
66 85 public function __construct(
67 86 int $id,
68 87 int $formId,
88 + string $name,
69 89 string $type,
70 90 bool $enabled,
71 91 bool $showForm,
72 92 string $message,
73 93 string $url,
74 - string $page
94 + string $page,
95 + int $position = 0,
96 + bool $isDefault = false,
97 + array $smartLogic = []
75 98 ) {
76 - $this->id = $this->validateId($id);
77 - $this->formId = $this->validateId($formId);
78 - $this->type = $this->validateString($type, 255, 'type');
79 - $this->enabled = $this->validateBool($enabled);
80 - $this->showForm = $this->validateBool($showForm);
81 - $this->message = $this->validateString($message, 1000, 'message');
82 - $this->url = $this->validateString($url, 255, 'url');
83 - $this->page = $this->validateString($page, 255, 'page');
99 + $this->id = $this->validateId($id);
100 + $this->formId = $this->validateId($formId);
101 + $this->name = $this->validateString($name, 255, 'name');
102 + $this->type = $this->validateString($type, 255, 'type');
103 + $this->enabled = $this->validateBool($enabled);
104 + $this->showForm = $this->validateBool($showForm);
105 + $this->message = $this->validateString($message, 4294967295, 'message');
106 + $this->url = $this->validateString($url, 255, 'url');
107 + $this->page = $this->validateString($page, 255, 'page');
108 + $this->position = $position >= 0 ? $position : 0;
109 + $this->isDefault = $this->validateBool($isDefault);
110 + $this->smartLogic = $this->validateSmartLogic($smartLogic);
84 111 }
85 112
86 113 /**
87 114 * Validates the ID.
@@ -93,9 +120,9 @@
93 120 */
94 121 private function validateId(int $id): int
95 122 {
96 123 if ($id < 0) {
97 - throw new InvalidArgumentException("Id must be a positive integer.");
124 + throw new InvalidArgumentException(BackendStrings::getExceptionStrings()['id_positive_integer']);
98 125 }
99 126 return $id;
100 127 }
101 128
@@ -147,8 +174,18 @@
147 174 return $this->id;
148 175 }
149 176
150 177 /**
178 + * Get the confirmation name.
179 + *
180 + * @return string
181 + */
182 + public function getName(): string
183 + {
184 + return $this->name;
185 + }
186 +
187 + /**
151 188 * Get the form ID.
152 189 *
153 190 * @return int
154 191 */
@@ -217,8 +254,51 @@
217 254 return $this->page;
218 255 }
219 256
220 257 /**
258 + * Get the confirmation list position.
259 + *
260 + * @return int
261 + */
262 + public function getPosition(): int
263 + {
264 + return $this->position;
265 + }
266 +
267 + /**
268 + * Whether this confirmation is the default for the form.
269 + *
270 + * @return bool
271 + */
272 + public function isDefault(): bool
273 + {
274 + return $this->isDefault;
275 + }
276 +
277 + /**
278 + * @return array<string, mixed>
279 + */
280 + public function getSmartLogic(): array
281 + {
282 + return $this->smartLogic;
283 + }
284 +
285 + /**
286 + * @param array<string, mixed> $smartLogic
287 + * @return array<string, mixed>
288 + */
289 + private function validateSmartLogic(array $smartLogic): array
290 + {
291 + $match = $smartLogic['match'] ?? 'any';
292 +
293 + return [
294 + 'enabled' => (bool)($smartLogic['enabled'] ?? false),
295 + 'match' => in_array($match, ['any', 'all'], true) ? $match : 'any',
296 + 'rules' => is_array($smartLogic['rules'] ?? null) ? $smartLogic['rules'] : [],
297 + ];
298 + }
299 +
300 + /**
221 301 * Convert the confirmation to an array.
222 302 *
223 303 * @return array<string, mixed>
224 304 */
@@ -226,8 +306,9 @@
226 306 {
227 307 return [
228 308 'id' => $this->getId(),
229 309 'formId' => $this->getFormId(),
310 + 'name' => $this->getName(),
230 311 'type' => $this->getType(),
231 312 'enabled' => $this->isEnabled(),
232 313 'showForm' => $this->isShowForm(),
233 314 'message' => $this->getMessage(),
@@ -232,7 +313,10 @@
232 313 'showForm' => $this->isShowForm(),
233 314 'message' => $this->getMessage(),
234 315 'url' => $this->getUrl(),
235 316 'page' => $this->getPage(),
317 + 'position' => $this->getPosition(),
318 + 'isDefault' => $this->isDefault(),
319 + 'smartLogic' => $this->getSmartLogic(),
236 320 ];
237 321 }
238 322 }