← All changes
|
backend/src/ValueObjects/Field/FieldGeneralSettings.php
+233
-45
0.4
→
1.5
View file →
| @@ -1,20 +1,17 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See LICENCE.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\ValueObjects\Field; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | - | |
| 16 | 10 | use IvyForms\Common\Exceptions\ValidationException; |
| 11 | +use IvyForms\ValueObjects\Field\ConfirmationGeneralSettings; | |
| 12 | +use IvyForms\ValueObjects\Field\TimeFieldGeneralSettings; | |
| 13 | +use IvyForms\ValueObjects\Field\DateFieldGeneralSettings; | |
| 17 | 14 | |
| 18 | 15 | /** |
| 19 | 16 | * Class FieldGeneralSettings |
| 20 | 17 | * |
| @@ -79,23 +76,59 @@ | ||
| 79 | 76 | * @var bool |
| 80 | 77 | */ |
| 81 | 78 | private bool $phoneAutoDetect; |
| 82 | 79 | /** |
| 83 | - * @var float | |
| 80 | + * @var float|null | |
| 84 | 81 | */ |
| 85 | - public float $minValue; | |
| 82 | + public ?float $minValue; | |
| 86 | 83 | /** |
| 87 | - * @var float | |
| 84 | + * @var float|null | |
| 88 | 85 | */ |
| 89 | - public float $maxValue; | |
| 86 | + public ?float $maxValue; | |
| 90 | 87 | /** |
| 91 | 88 | * @var float Step increment for number fields |
| 92 | 89 | */ |
| 93 | 90 | public float $step; |
| 94 | 91 | /** |
| 92 | + * @var bool Show grid marks on slider | |
| 93 | + */ | |
| 94 | + public bool $showGrid; | |
| 95 | + /** | |
| 95 | 96 | * @var string Number format key |
| 96 | 97 | */ |
| 97 | 98 | public string $numberFormat; |
| 99 | + /** | |
| 100 | + * Confirmation settings grouped in a dedicated value object. | |
| 101 | + * @var ConfirmationGeneralSettings | |
| 102 | + */ | |
| 103 | + private ConfirmationGeneralSettings $confirmationSettings; | |
| 104 | + /** | |
| 105 | + * Time settings grouped in a dedicated value object. | |
| 106 | + * @var TimeFieldGeneralSettings | |
| 107 | + */ | |
| 108 | + private TimeFieldGeneralSettings $timeSettings; | |
| 109 | + /** | |
| 110 | + * Date settings grouped in a dedicated value object. | |
| 111 | + * @var DateFieldGeneralSettings | |
| 112 | + */ | |
| 113 | + private DateFieldGeneralSettings $dateSettings; | |
| 114 | + /** | |
| 115 | + * Whether to show text labels alongside rating. | |
| 116 | + * @var bool | |
| 117 | + */ | |
| 118 | + private bool $showRatingText; | |
| 119 | + /** | |
| 120 | + * @var string HTML content for HTML field type | |
| 121 | + */ | |
| 122 | + private string $htmlContent; | |
| 123 | + /** | |
| 124 | + * @var string Agreement text for GDPR field type | |
| 125 | + */ | |
| 126 | + private string $agreementText; | |
| 127 | + /** | |
| 128 | + * @var bool | |
| 129 | + */ | |
| 130 | + private bool $limitRange; | |
| 98 | 131 | |
| 99 | 132 | /** |
| 100 | 133 | * Public constructor |
| 101 | 134 | * |
| @@ -111,13 +144,20 @@ | ||
| 111 | 144 | * @param bool $showValues |
| 112 | 145 | * @param bool $enableSearch |
| 113 | 146 | * @param string $phoneFormat |
| 114 | 147 | * @param bool $phoneAutoDetect |
| 115 | - * @param float $minValue | |
| 116 | - * @param float $maxValue | |
| 148 | + * @param float|null $minValue | |
| 149 | + * @param float|null $maxValue | |
| 117 | 150 | * @param float $step |
| 151 | + * @param bool $showGrid | |
| 118 | 152 | * @param string $numberFormat |
| 153 | + * @param ConfirmationGeneralSettings $confirmationSettings | |
| 154 | + * @param TimeFieldGeneralSettings $timeSettings | |
| 155 | + * @param DateFieldGeneralSettings $dateSettings | |
| 119 | 156 | * @param bool $visible |
| 157 | + * @param bool $showRatingText | |
| 158 | + * @param string $htmlContent | |
| 159 | + * @param bool $limitRange | |
| 120 | 160 | */ |
| 121 | 161 | /** |
| 122 | 162 | * @SuppressWarnings("ExcessiveParameterList") |
| 123 | 163 | * @SuppressWarnings("BooleanArgumentFlag") |
| @@ -135,13 +175,21 @@ | ||
| 135 | 175 | bool $showValues, |
| 136 | 176 | bool $enableSearch, |
| 137 | 177 | string $phoneFormat, |
| 138 | 178 | bool $phoneAutoDetect, |
| 139 | - float $minValue, | |
| 140 | - float $maxValue, | |
| 179 | + ?float $minValue, | |
| 180 | + ?float $maxValue, | |
| 141 | 181 | float $step, |
| 182 | + bool $showGrid, | |
| 142 | 183 | string $numberFormat, |
| 143 | - bool $visible = true | |
| 184 | + ConfirmationGeneralSettings $confirmationSettings, | |
| 185 | + TimeFieldGeneralSettings $timeSettings, | |
| 186 | + DateFieldGeneralSettings $dateSettings, | |
| 187 | + bool $showRatingText, | |
| 188 | + bool $visible = true, | |
| 189 | + string $htmlContent = '', | |
| 190 | + string $agreementText = '', | |
| 191 | + bool $limitRange = false | |
| 144 | 192 | ) { |
| 145 | 193 | $this->label = $label; |
| 146 | 194 | $this->required = $required; |
| 147 | 195 | $this->placeholder = $placeholder; |
| @@ -157,10 +205,18 @@ | ||
| 157 | 205 | $this->phoneAutoDetect = $phoneAutoDetect; |
| 158 | 206 | $this->minValue = $minValue; |
| 159 | 207 | $this->maxValue = $maxValue; |
| 160 | 208 | $this->step = $step; |
| 209 | + $this->showGrid = $showGrid; | |
| 161 | 210 | $this->numberFormat = $numberFormat; |
| 162 | 211 | $this->visible = $visible; |
| 212 | + $this->confirmationSettings = $confirmationSettings; | |
| 213 | + $this->timeSettings = $timeSettings; | |
| 214 | + $this->dateSettings = $dateSettings; | |
| 215 | + $this->htmlContent = $htmlContent; | |
| 216 | + $this->showRatingText = $showRatingText; | |
| 217 | + $this->agreementText = $agreementText; | |
| 218 | + $this->limitRange = $limitRange; | |
| 163 | 219 | } |
| 164 | 220 | |
| 165 | 221 | /** |
| 166 | 222 | * Get the label. |
| @@ -270,8 +326,35 @@ | ||
| 270 | 326 | return $this->visible; |
| 271 | 327 | } |
| 272 | 328 | |
| 273 | 329 | /** |
| 330 | + * Accessor for confirmation settings value object. | |
| 331 | + * @return ConfirmationGeneralSettings | |
| 332 | + */ | |
| 333 | + public function getConfirmationSettings(): ConfirmationGeneralSettings | |
| 334 | + { | |
| 335 | + return $this->confirmationSettings; | |
| 336 | + } | |
| 337 | + | |
| 338 | + /** | |
| 339 | + * Accessor for time settings value object. | |
| 340 | + * @return TimeFieldGeneralSettings | |
| 341 | + */ | |
| 342 | + public function getTimeSettings(): TimeFieldGeneralSettings | |
| 343 | + { | |
| 344 | + return $this->timeSettings; | |
| 345 | + } | |
| 346 | + | |
| 347 | + /** | |
| 348 | + * Accessor for date settings value object. | |
| 349 | + * @return DateFieldGeneralSettings | |
| 350 | + */ | |
| 351 | + public function getDateSettings(): DateFieldGeneralSettings | |
| 352 | + { | |
| 353 | + return $this->dateSettings; | |
| 354 | + } | |
| 355 | + | |
| 356 | + /** | |
| 274 | 357 | * Get the phone format. |
| 275 | 358 | * |
| 276 | 359 | * @return string |
| 277 | 360 | */ |
| @@ -311,11 +394,11 @@ | ||
| 311 | 394 | } |
| 312 | 395 | /** |
| 313 | 396 | * Get the minimum value. |
| 314 | 397 | * |
| 315 | - * @return float | |
| 398 | + * @return float|null | |
| 316 | 399 | */ |
| 317 | - public function getMinValue(): float | |
| 400 | + public function getMinValue(): ?float | |
| 318 | 401 | { |
| 319 | 402 | return $this->minValue; |
| 320 | 403 | } |
| 321 | 404 | |
| @@ -321,11 +404,11 @@ | ||
| 321 | 404 | |
| 322 | 405 | /** |
| 323 | 406 | * Set the minimum value. |
| 324 | 407 | * |
| 325 | - * @param float $minValue | |
| 408 | + * @param float|null $minValue | |
| 326 | 409 | */ |
| 327 | - public function setMinValue(float $minValue): void | |
| 410 | + public function setMinValue(?float $minValue): void | |
| 328 | 411 | { |
| 329 | 412 | $this->minValue = $minValue; |
| 330 | 413 | } |
| 331 | 414 | |
| @@ -331,11 +414,11 @@ | ||
| 331 | 414 | |
| 332 | 415 | /** |
| 333 | 416 | * Get the maximum value. |
| 334 | 417 | * |
| 335 | - * @return float | |
| 418 | + * @return float|null | |
| 336 | 419 | */ |
| 337 | - public function getMaxValue(): float | |
| 420 | + public function getMaxValue(): ?float | |
| 338 | 421 | { |
| 339 | 422 | return $this->maxValue; |
| 340 | 423 | } |
| 341 | 424 | |
| @@ -341,11 +424,11 @@ | ||
| 341 | 424 | |
| 342 | 425 | /** |
| 343 | 426 | * Set the maximum value. |
| 344 | 427 | * |
| 345 | - * @param float $maxValue | |
| 428 | + * @param float|null $maxValue | |
| 346 | 429 | */ |
| 347 | - public function setMaxValue(float $maxValue): void | |
| 430 | + public function setMaxValue(?float $maxValue): void | |
| 348 | 431 | { |
| 349 | 432 | $this->maxValue = $maxValue; |
| 350 | 433 | } |
| 351 | 434 | |
| @@ -369,8 +452,28 @@ | ||
| 369 | 452 | $this->step = $step; |
| 370 | 453 | } |
| 371 | 454 | |
| 372 | 455 | /** |
| 456 | + * Get the show grid value. | |
| 457 | + * | |
| 458 | + * @return bool | |
| 459 | + */ | |
| 460 | + public function getShowGrid(): bool | |
| 461 | + { | |
| 462 | + return $this->showGrid; | |
| 463 | + } | |
| 464 | + | |
| 465 | + /** | |
| 466 | + * Set the show grid value. | |
| 467 | + * | |
| 468 | + * @param bool $showGrid | |
| 469 | + */ | |
| 470 | + public function setShowGrid(bool $showGrid): void | |
| 471 | + { | |
| 472 | + $this->showGrid = $showGrid; | |
| 473 | + } | |
| 474 | + | |
| 475 | + /** | |
| 373 | 476 | * Get the number format. |
| 374 | 477 | * |
| 375 | 478 | * @return string |
| 376 | 479 | */ |
| @@ -389,30 +492,115 @@ | ||
| 389 | 492 | $this->numberFormat = $numberFormat; |
| 390 | 493 | } |
| 391 | 494 | |
| 392 | 495 | /** |
| 393 | - * @return array<string, bool|float|string> | |
| 496 | + * Get the HTML content. | |
| 497 | + * @return string | |
| 394 | 498 | */ |
| 499 | + public function getHtmlContent(): string | |
| 500 | + { | |
| 501 | + return $this->htmlContent; | |
| 502 | + } | |
| 503 | + | |
| 504 | + /** | |
| 505 | + * Set the HTML content. | |
| 506 | + * | |
| 507 | + * @param string $htmlContent | |
| 508 | + */ | |
| 509 | + public function setHtmlContent(string $htmlContent): void | |
| 510 | + { | |
| 511 | + $this->htmlContent = $htmlContent; | |
| 512 | + } | |
| 513 | + | |
| 514 | + /** | |
| 515 | + * Get showRatingText flag. | |
| 516 | + * @return bool | |
| 517 | + */ | |
| 518 | + public function isShowRatingText(): bool | |
| 519 | + { | |
| 520 | + return $this->showRatingText; | |
| 521 | + } | |
| 522 | + | |
| 523 | + /** | |
| 524 | + * Set showRatingText flag. | |
| 525 | + * | |
| 526 | + * @param bool|null $val | |
| 527 | + */ | |
| 528 | + public function setShowRatingText(?bool $val): void | |
| 529 | + { | |
| 530 | + $this->showRatingText = (bool)$val; | |
| 531 | + } | |
| 532 | + | |
| 533 | + /** | |
| 534 | + * Get the agreement text. | |
| 535 | + * @return string | |
| 536 | + */ | |
| 537 | + public function getAgreementText(): string | |
| 538 | + { | |
| 539 | + return $this->agreementText; | |
| 540 | + } | |
| 541 | + | |
| 542 | + /** | |
| 543 | + * Set the agreement text. | |
| 544 | + * | |
| 545 | + * @param string $agreementText | |
| 546 | + */ | |
| 547 | + public function setAgreementText(string $agreementText): void | |
| 548 | + { | |
| 549 | + $this->agreementText = $agreementText; | |
| 550 | + } | |
| 551 | + | |
| 552 | + /** | |
| 553 | + * Get limitRange. | |
| 554 | + * @return bool | |
| 555 | + */ | |
| 556 | + public function isLimitRange(): bool | |
| 557 | + { | |
| 558 | + return $this->limitRange; | |
| 559 | + } | |
| 560 | + | |
| 561 | + /** | |
| 562 | + * Set limitRange. | |
| 563 | + * @param bool $limitRange | |
| 564 | + */ | |
| 565 | + public function setLimitRange(bool $limitRange): void | |
| 566 | + { | |
| 567 | + $this->limitRange = $limitRange; | |
| 568 | + } | |
| 569 | + | |
| 570 | + /** | |
| 571 | + * @return array<string, mixed> | |
| 572 | + */ | |
| 395 | 573 | public function toArray(): array |
| 396 | 574 | { |
| 397 | - return [ | |
| 398 | - 'label' => $this->getLabel(), | |
| 399 | - 'required' => $this->isRequired(), | |
| 400 | - 'placeholder' => $this->getPlaceholder(), | |
| 401 | - 'hideLabel' => $this->isHideLabel(), | |
| 402 | - 'readOnly' => $this->isReadOnly(), | |
| 403 | - 'description' => $this->getDescription(), | |
| 404 | - 'requiredMessage' => $this->getRequiredMessage(), | |
| 405 | - 'cssClasses' => $this->getCssClasses(), | |
| 406 | - 'shuffleOptions' => $this->isShuffleOptions(), | |
| 407 | - 'showValues' => $this->isShowValues(), | |
| 408 | - 'enableSearch' => $this->isEnableSearch(), | |
| 409 | - 'phoneFormat' => $this->getPhoneFormat(), | |
| 410 | - 'phoneAutoDetect' => $this->isPhoneAutoDetect(), | |
| 411 | - 'minValue' => $this->getMinValue(), | |
| 412 | - 'maxValue' => $this->getMaxValue(), | |
| 413 | - 'step' => $this->getStep(), | |
| 414 | - 'numberFormat' => $this->getNumberFormat(), | |
| 415 | - 'visible' => $this->isVisible(), | |
| 416 | - ]; | |
| 575 | + return array_merge( | |
| 576 | + [ | |
| 577 | + 'label' => $this->getLabel(), | |
| 578 | + 'required' => $this->isRequired(), | |
| 579 | + 'placeholder' => $this->getPlaceholder(), | |
| 580 | + 'hideLabel' => $this->isHideLabel(), | |
| 581 | + 'readOnly' => $this->isReadOnly(), | |
| 582 | + 'description' => $this->getDescription(), | |
| 583 | + 'requiredMessage' => $this->getRequiredMessage(), | |
| 584 | + 'cssClasses' => $this->getCssClasses(), | |
| 585 | + 'shuffleOptions' => $this->isShuffleOptions(), | |
| 586 | + 'showValues' => $this->isShowValues(), | |
| 587 | + 'enableSearch' => $this->isEnableSearch(), | |
| 588 | + 'phoneFormat' => $this->getPhoneFormat(), | |
| 589 | + 'phoneAutoDetect' => $this->isPhoneAutoDetect(), | |
| 590 | + 'minValue' => $this->getMinValue(), | |
| 591 | + 'maxValue' => $this->getMaxValue(), | |
| 592 | + 'step' => $this->getStep(), | |
| 593 | + 'showGrid' => $this->getShowGrid(), | |
| 594 | + 'numberFormat' => $this->getNumberFormat(), | |
| 595 | + 'visible' => $this->isVisible(), | |
| 596 | + 'showRatingText' => $this->isShowRatingText(), | |
| 597 | + 'htmlContent' => $this->getHtmlContent(), | |
| 598 | + 'agreementText' => $this->getAgreementText(), | |
| 599 | + 'limitRange' => $this->isLimitRange(), | |
| 600 | + ], | |
| 601 | + $this->confirmationSettings->toArray(), | |
| 602 | + $this->timeSettings->toArray(), | |
| 603 | + $this->dateSettings->toArray() | |
| 604 | + ); | |
| 417 | 605 | } |
| 418 | 606 | } |