← All changes
|
backend/src/ValueObjects/Confirmation/Confirmation.php
+97
-14
0.6.1-backup
→
1.5
View file →
| @@ -1,13 +1,8 @@ | ||
| 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; |
| 12 | 7 | use IvyForms\Services\Translations\BackendStrings; |
| 13 | 8 | |
| @@ -14,8 +9,11 @@ | ||
| 14 | 9 | /** |
| 15 | 10 | * Class Confirmation |
| 16 | 11 | * |
| 17 | 12 | * @package IvyForms\ValueObjects\Confirmation |
| 13 | + * | |
| 14 | + * @SuppressWarnings(PHPMD.ExcessiveParameterList) | |
| 15 | + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) | |
| 18 | 16 | */ |
| 19 | 17 | final class Confirmation |
| 20 | 18 | { |
| 21 | 19 | /** |
| @@ -28,8 +26,12 @@ | ||
| 28 | 26 | public int $formId; |
| 29 | 27 | /** |
| 30 | 28 | * @var string |
| 31 | 29 | */ |
| 30 | + public string $name; | |
| 31 | + /** | |
| 32 | + * @var string | |
| 33 | + */ | |
| 32 | 34 | public string $type; |
| 33 | 35 | /** |
| 34 | 36 | * @var bool |
| 35 | 37 | */ |
| @@ -49,8 +51,20 @@ | ||
| 49 | 51 | /** |
| 50 | 52 | * @var string |
| 51 | 53 | */ |
| 52 | 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; | |
| 53 | 67 | |
| 54 | 68 | /** |
| 55 | 69 | * Confirmation constructor. |
| 56 | 70 | * |
| @@ -55,8 +69,9 @@ | ||
| 55 | 69 | * Confirmation constructor. |
| 56 | 70 | * |
| 57 | 71 | * @param int $id |
| 58 | 72 | * @param int $formId |
| 73 | + * @param string $name | |
| 59 | 74 | * @param string $type |
| 60 | 75 | * @param bool $enabled |
| 61 | 76 | * @param bool $showForm |
| 62 | 77 | * @param string $message |
| @@ -61,28 +76,39 @@ | ||
| 61 | 76 | * @param bool $showForm |
| 62 | 77 | * @param string $message |
| 63 | 78 | * @param string $url |
| 64 | 79 | * @param string $page |
| 80 | + * @param int $position | |
| 81 | + * @param bool $isDefault | |
| 82 | + * @param array<string, mixed> $smartLogic | |
| 65 | 83 | * @throws InvalidArgumentException|ValidationException |
| 66 | 84 | */ |
| 67 | 85 | public function __construct( |
| 68 | 86 | int $id, |
| 69 | 87 | int $formId, |
| 88 | + string $name, | |
| 70 | 89 | string $type, |
| 71 | 90 | bool $enabled, |
| 72 | 91 | bool $showForm, |
| 73 | 92 | string $message, |
| 74 | 93 | string $url, |
| 75 | - string $page | |
| 94 | + string $page, | |
| 95 | + int $position = 0, | |
| 96 | + bool $isDefault = false, | |
| 97 | + array $smartLogic = [] | |
| 76 | 98 | ) { |
| 77 | - $this->id = $this->validateId($id); | |
| 78 | - $this->formId = $this->validateId($formId); | |
| 79 | - $this->type = $this->validateString($type, 255, 'type'); | |
| 80 | - $this->enabled = $this->validateBool($enabled); | |
| 81 | - $this->showForm = $this->validateBool($showForm); | |
| 82 | - $this->message = $this->validateString($message, 1000, 'message'); | |
| 83 | - $this->url = $this->validateString($url, 255, 'url'); | |
| 84 | - $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); | |
| 85 | 111 | } |
| 86 | 112 | |
| 87 | 113 | /** |
| 88 | 114 | * Validates the ID. |
| @@ -148,8 +174,18 @@ | ||
| 148 | 174 | return $this->id; |
| 149 | 175 | } |
| 150 | 176 | |
| 151 | 177 | /** |
| 178 | + * Get the confirmation name. | |
| 179 | + * | |
| 180 | + * @return string | |
| 181 | + */ | |
| 182 | + public function getName(): string | |
| 183 | + { | |
| 184 | + return $this->name; | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 152 | 188 | * Get the form ID. |
| 153 | 189 | * |
| 154 | 190 | * @return int |
| 155 | 191 | */ |
| @@ -218,8 +254,51 @@ | ||
| 218 | 254 | return $this->page; |
| 219 | 255 | } |
| 220 | 256 | |
| 221 | 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 | + /** | |
| 222 | 301 | * Convert the confirmation to an array. |
| 223 | 302 | * |
| 224 | 303 | * @return array<string, mixed> |
| 225 | 304 | */ |
| @@ -227,8 +306,9 @@ | ||
| 227 | 306 | { |
| 228 | 307 | return [ |
| 229 | 308 | 'id' => $this->getId(), |
| 230 | 309 | 'formId' => $this->getFormId(), |
| 310 | + 'name' => $this->getName(), | |
| 231 | 311 | 'type' => $this->getType(), |
| 232 | 312 | 'enabled' => $this->isEnabled(), |
| 233 | 313 | 'showForm' => $this->isShowForm(), |
| 234 | 314 | 'message' => $this->getMessage(), |
| @@ -233,7 +313,10 @@ | ||
| 233 | 313 | 'showForm' => $this->isShowForm(), |
| 234 | 314 | 'message' => $this->getMessage(), |
| 235 | 315 | 'url' => $this->getUrl(), |
| 236 | 316 | 'page' => $this->getPage(), |
| 317 | + 'position' => $this->getPosition(), | |
| 318 | + 'isDefault' => $this->isDefault(), | |
| 319 | + 'smartLogic' => $this->getSmartLogic(), | |
| 237 | 320 | ]; |
| 238 | 321 | } |
| 239 | 322 | } |