← All changes
|
backend/src/ValueObjects/Field/FieldAdvancedSettings.php
+325
-0
0.6.1
→
1.5
View file →
| @@ -1,0 +1,325 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | + * @licence See LICENCE.md for license details. | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace IvyForms\ValueObjects\Field; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Class FieldAdvancedSettings | |
| 12 | + * | |
| 13 | + * @package IvyForms\ValueObjects\Field | |
| 14 | + */ | |
| 15 | +final class FieldAdvancedSettings | |
| 16 | +{ | |
| 17 | + /** | |
| 18 | + * @var string | |
| 19 | + */ | |
| 20 | + public string $defaultValue; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * @var bool | |
| 24 | + */ | |
| 25 | + public bool $limitMaxLength; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * @var int | |
| 29 | + */ | |
| 30 | + public int $maxLength; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * @var string | |
| 34 | + */ | |
| 35 | + public string $labelPosition; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * @var bool | |
| 39 | + */ | |
| 40 | + public bool $noDuplicates; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * @var string field prefix (e.g., https://) | |
| 44 | + */ | |
| 45 | + private string $inputPrefix; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * @var string field suffix (e.g., .com) | |
| 49 | + */ | |
| 50 | + private string $inputSuffix; | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @var string Type of rating icon (star, heart, etc.) | |
| 54 | + */ | |
| 55 | + private string $ratingIcon; | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * @var FileUploadFieldAdvancedSettings | |
| 59 | + */ | |
| 60 | + private FileUploadFieldAdvancedSettings $fileUploadSettings; | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * FieldAdvancedSettings constructor. | |
| 64 | + * | |
| 65 | + * @param string $defaultValue | |
| 66 | + * @param bool $limitMaxLength | |
| 67 | + * @param int $maxLength | |
| 68 | + * @param string $labelPosition | |
| 69 | + * @param bool $noDuplicates | |
| 70 | + * @param string $inputPrefix | |
| 71 | + * @param string $inputSuffix | |
| 72 | + * @param string $ratingIcon | |
| 73 | + * @param FileUploadFieldAdvancedSettings $fileUploadSettings | |
| 74 | + */ | |
| 75 | + public function __construct( | |
| 76 | + string $defaultValue, | |
| 77 | + bool $limitMaxLength, | |
| 78 | + int $maxLength, | |
| 79 | + string $labelPosition, | |
| 80 | + bool $noDuplicates, | |
| 81 | + string $inputPrefix, | |
| 82 | + string $inputSuffix, | |
| 83 | + string $ratingIcon, | |
| 84 | + FileUploadFieldAdvancedSettings $fileUploadSettings | |
| 85 | + ) { | |
| 86 | + $this->defaultValue = $defaultValue; | |
| 87 | + $this->limitMaxLength = $limitMaxLength; | |
| 88 | + $this->maxLength = $maxLength; | |
| 89 | + $this->labelPosition = $labelPosition; | |
| 90 | + $this->noDuplicates = $noDuplicates; | |
| 91 | + $this->inputPrefix = $inputPrefix; | |
| 92 | + $this->inputSuffix = $inputSuffix; | |
| 93 | + $this->ratingIcon = $ratingIcon; | |
| 94 | + $this->fileUploadSettings = $fileUploadSettings; | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * Get the default value. | |
| 99 | + * | |
| 100 | + * @return string | |
| 101 | + */ | |
| 102 | + public function getDefaultValue(): string | |
| 103 | + { | |
| 104 | + return $this->defaultValue; | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Set the default value. | |
| 109 | + * | |
| 110 | + * @param string $defaultValue | |
| 111 | + */ | |
| 112 | + public function setDefaultValue(string $defaultValue): void | |
| 113 | + { | |
| 114 | + $this->defaultValue = $defaultValue; | |
| 115 | + } | |
| 116 | + | |
| 117 | + /** | |
| 118 | + * Check if maximum length limit is enabled. | |
| 119 | + * | |
| 120 | + * @return bool | |
| 121 | + */ | |
| 122 | + public function isLimitMaxLength(): bool | |
| 123 | + { | |
| 124 | + return $this->limitMaxLength; | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * Set the limit maximum length setting. | |
| 129 | + * | |
| 130 | + * @param bool $limitMaxLength | |
| 131 | + */ | |
| 132 | + public function setLimitMaxLength(bool $limitMaxLength): void | |
| 133 | + { | |
| 134 | + $this->limitMaxLength = $limitMaxLength; | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * Get the maximum length. | |
| 139 | + * | |
| 140 | + * @return int | |
| 141 | + */ | |
| 142 | + public function getMaxLength(): int | |
| 143 | + { | |
| 144 | + return $this->maxLength; | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * Set the maximum length setting. | |
| 149 | + * | |
| 150 | + * @param int $maxLength | |
| 151 | + */ | |
| 152 | + public function setMaxLength(int $maxLength): void | |
| 153 | + { | |
| 154 | + $this->maxLength = $maxLength; | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Get the label position. | |
| 159 | + * | |
| 160 | + * @return string | |
| 161 | + */ | |
| 162 | + public function getLabelPosition(): string | |
| 163 | + { | |
| 164 | + return $this->labelPosition; | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * Set the label position setting. | |
| 169 | + * | |
| 170 | + * @param string $labelPosition | |
| 171 | + */ | |
| 172 | + public function setLabelPosition(string $labelPosition): void | |
| 173 | + { | |
| 174 | + $this->labelPosition = $labelPosition; | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** | |
| 178 | + * Check if duplicates are not allowed. | |
| 179 | + * | |
| 180 | + * @return bool | |
| 181 | + */ | |
| 182 | + public function isNoDuplicates(): bool | |
| 183 | + { | |
| 184 | + return $this->noDuplicates; | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 188 | + * Set the noDuplicates setting. | |
| 189 | + * | |
| 190 | + * @param bool $noDuplicates | |
| 191 | + */ | |
| 192 | + public function setNoDuplicates(bool $noDuplicates): void | |
| 193 | + { | |
| 194 | + $this->noDuplicates = $noDuplicates; | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** | |
| 198 | + * Get the field prefix. | |
| 199 | + * | |
| 200 | + * @return string | |
| 201 | + */ | |
| 202 | + public function getInputPrefix(): string | |
| 203 | + { | |
| 204 | + return $this->inputPrefix; | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * Set the field prefix. | |
| 209 | + * | |
| 210 | + * @param string $prefix | |
| 211 | + */ | |
| 212 | + public function setInputPrefix(string $prefix): void | |
| 213 | + { | |
| 214 | + $this->inputPrefix = $prefix; | |
| 215 | + } | |
| 216 | + | |
| 217 | + /** | |
| 218 | + * Get the field suffix. | |
| 219 | + * | |
| 220 | + * @return string | |
| 221 | + */ | |
| 222 | + public function getInputSuffix(): string | |
| 223 | + { | |
| 224 | + return $this->inputSuffix; | |
| 225 | + } | |
| 226 | + | |
| 227 | + /** | |
| 228 | + * Set the field suffix. | |
| 229 | + * | |
| 230 | + * @param string $suffix | |
| 231 | + */ | |
| 232 | + public function setInputSuffix(string $suffix): void | |
| 233 | + { | |
| 234 | + $this->inputSuffix = $suffix; | |
| 235 | + } | |
| 236 | + | |
| 237 | + /** | |
| 238 | + * Get the rating icon type. | |
| 239 | + * | |
| 240 | + * @return string | |
| 241 | + */ | |
| 242 | + public function getRatingIcon(): string | |
| 243 | + { | |
| 244 | + return $this->ratingIcon; | |
| 245 | + } | |
| 246 | + | |
| 247 | + /** | |
| 248 | + * Set the rating icon type. | |
| 249 | + * | |
| 250 | + * @param string $ratingIcon | |
| 251 | + */ | |
| 252 | + public function setRatingIcon(string $ratingIcon): void | |
| 253 | + { | |
| 254 | + $this->ratingIcon = $ratingIcon; | |
| 255 | + } | |
| 256 | + | |
| 257 | + public function getFileUploadSettings(): FileUploadFieldAdvancedSettings | |
| 258 | + { | |
| 259 | + return $this->fileUploadSettings; | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** | |
| 263 | + * Maximum file size in MB for file-upload fields (0 = server default). | |
| 264 | + */ | |
| 265 | + public function getMaxFileSizeMb(): int | |
| 266 | + { | |
| 267 | + return $this->fileUploadSettings->getMaxFileSizeMb(); | |
| 268 | + } | |
| 269 | + | |
| 270 | + public function setMaxFileSizeMb(int $maxFileSizeMb): void | |
| 271 | + { | |
| 272 | + $this->fileUploadSettings->setMaxFileSizeMb($maxFileSizeMb); | |
| 273 | + } | |
| 274 | + | |
| 275 | + /** | |
| 276 | + * Target storage for uploads: ivyforms or media_library. | |
| 277 | + */ | |
| 278 | + public function getSaveUploadsTo(): string | |
| 279 | + { | |
| 280 | + return $this->fileUploadSettings->getSaveUploadsTo(); | |
| 281 | + } | |
| 282 | + | |
| 283 | + public function setSaveUploadsTo(string $saveUploadsTo): void | |
| 284 | + { | |
| 285 | + $this->fileUploadSettings->setSaveUploadsTo($saveUploadsTo); | |
| 286 | + } | |
| 287 | + | |
| 288 | + /** | |
| 289 | + * @return array<int, string> | |
| 290 | + */ | |
| 291 | + public function getAllowedFileExtensions(): array | |
| 292 | + { | |
| 293 | + return $this->fileUploadSettings->getAllowedFileExtensions(); | |
| 294 | + } | |
| 295 | + | |
| 296 | + /** | |
| 297 | + * @param array<int, string> $allowedFileExtensions | |
| 298 | + */ | |
| 299 | + public function setAllowedFileExtensions(array $allowedFileExtensions): void | |
| 300 | + { | |
| 301 | + $this->fileUploadSettings->setAllowedFileExtensions($allowedFileExtensions); | |
| 302 | + } | |
| 303 | + | |
| 304 | + /** | |
| 305 | + * Convert the advanced settings to an array. | |
| 306 | + * | |
| 307 | + * @return array<string, mixed> | |
| 308 | + */ | |
| 309 | + public function toArray(): array | |
| 310 | + { | |
| 311 | + return array_merge( | |
| 312 | + [ | |
| 313 | + 'defaultValue' => $this->getDefaultValue(), | |
| 314 | + 'limitMaxLength' => $this->isLimitMaxLength(), | |
| 315 | + 'maxLength' => $this->getMaxLength(), | |
| 316 | + 'labelPosition' => $this->getLabelPosition(), | |
| 317 | + 'noDuplicates' => $this->isNoDuplicates(), | |
| 318 | + 'inputPrefix' => $this->getInputPrefix(), | |
| 319 | + 'inputSuffix' => $this->getInputSuffix(), | |
| 320 | + 'ratingIcon' => $this->getRatingIcon(), | |
| 321 | + ], | |
| 322 | + $this->fileUploadSettings->toArray() | |
| 323 | + ); | |
| 324 | + } | |
| 325 | +} | |