| @@ -6,13 +6,8 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\Entity\Notification; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | 10 | use IvyForms\ValueObjects\Notification\Notification as NotificationValueObject; |
| 16 | 11 | |
| 17 | 12 | /** |
| 18 | 13 | * Class Notification |
| @@ -26,8 +21,20 @@ | ||
| 26 | 21 | */ |
| 27 | 22 | private NotificationValueObject $notification; |
| 28 | 23 | |
| 29 | 24 | /** |
| 25 | + * @var NotificationContact | |
| 26 | + */ | |
| 27 | + private NotificationContact $contact; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Opaque extension payload (Pro / add-ons). Not owned by Lite domain fields. | |
| 31 | + * | |
| 32 | + * @var array<string, mixed> | |
| 33 | + */ | |
| 34 | + private array $extensionData = []; | |
| 35 | + | |
| 36 | + /** | |
| 30 | 37 | * Notification constructor. |
| 31 | 38 | * |
| 32 | 39 | * @param NotificationValueObject $notification The notification object. |
| 33 | 40 | */ |
| @@ -33,11 +40,28 @@ | ||
| 33 | 40 | */ |
| 34 | 41 | public function __construct(NotificationValueObject $notification) |
| 35 | 42 | { |
| 36 | 43 | $this->notification = $notification; |
| 44 | + $this->contact = new NotificationContact($notification->contact); | |
| 37 | 45 | } |
| 38 | 46 | |
| 39 | 47 | /** |
| 48 | + * @param array<string, mixed> $data | |
| 49 | + */ | |
| 50 | + public function setExtensionData(array $data): void | |
| 51 | + { | |
| 52 | + $this->extensionData = $data; | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * @return array<string, mixed> | |
| 57 | + */ | |
| 58 | + public function getExtensionData(): array | |
| 59 | + { | |
| 60 | + return $this->extensionData; | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 40 | 64 | * Get the notification ID. |
| 41 | 65 | * |
| 42 | 66 | * @return int |
| 43 | 67 | */ |
| @@ -76,68 +100,18 @@ | ||
| 76 | 100 | $this->notification->name = $name; |
| 77 | 101 | } |
| 78 | 102 | |
| 79 | 103 | /** |
| 80 | - * Get the notification sender. | |
| 104 | + * Get the NotificationContact entity. | |
| 81 | 105 | * |
| 82 | - * @return string | |
| 106 | + * @return NotificationContact | |
| 83 | 107 | */ |
| 84 | - public function getSender(): string | |
| 108 | + public function getNotificationContact(): NotificationContact | |
| 85 | 109 | { |
| 86 | - return $this->notification->getSender(); | |
| 110 | + return $this->contact; | |
| 87 | 111 | } |
| 88 | 112 | |
| 89 | 113 | /** |
| 90 | - * Set the notification sender. | |
| 91 | - * | |
| 92 | - * @param string $sender | |
| 93 | - */ | |
| 94 | - public function setSender(string $sender): void | |
| 95 | - { | |
| 96 | - $this->notification->sender = $sender; | |
| 97 | - } | |
| 98 | - | |
| 99 | - /** | |
| 100 | - * Get the notification reply-to address. | |
| 101 | - * | |
| 102 | - * @return string | |
| 103 | - */ | |
| 104 | - public function getReplyTo(): string | |
| 105 | - { | |
| 106 | - return $this->notification->getReplyTo(); | |
| 107 | - } | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * Set the notification reply-to address. | |
| 111 | - * | |
| 112 | - * @param string $replyTo | |
| 113 | - */ | |
| 114 | - public function setReplyTo(string $replyTo): void | |
| 115 | - { | |
| 116 | - $this->notification->replyTo = $replyTo; | |
| 117 | - } | |
| 118 | - | |
| 119 | - /** | |
| 120 | - * Get the notification receiver. | |
| 121 | - * | |
| 122 | - * @return string | |
| 123 | - */ | |
| 124 | - public function getReceiver(): string | |
| 125 | - { | |
| 126 | - return $this->notification->getReceiver(); | |
| 127 | - } | |
| 128 | - | |
| 129 | - /** | |
| 130 | - * Set the notification receiver. | |
| 131 | - * | |
| 132 | - * @param string $receiver | |
| 133 | - */ | |
| 134 | - public function setReceiver(string $receiver): void | |
| 135 | - { | |
| 136 | - $this->notification->receiver = $receiver; | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | 114 | * Get the notification status. |
| 141 | 115 | * |
| 142 | 116 | * @return bool |
| 143 | 117 | */ |
| @@ -196,23 +170,43 @@ | ||
| 196 | 170 | $this->notification->message = $message; |
| 197 | 171 | } |
| 198 | 172 | |
| 199 | 173 | /** |
| 174 | + * Get the show empty fields status. | |
| 175 | + * | |
| 176 | + * @return bool | |
| 177 | + */ | |
| 178 | + public function isShowEmptyFields(): bool | |
| 179 | + { | |
| 180 | + return $this->notification->isShowEmptyFields(); | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * Set the show empty fields status. | |
| 185 | + * | |
| 186 | + * @param bool $showEmptyFields | |
| 187 | + */ | |
| 188 | + public function setShowEmptyFields(bool $showEmptyFields): void | |
| 189 | + { | |
| 190 | + $this->notification->showEmptyFields = $showEmptyFields; | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 200 | 194 | * Get the smart logic status. |
| 201 | 195 | * |
| 202 | - * @return bool | |
| 196 | + * @return array<string, mixed> | |
| 203 | 197 | */ |
| 204 | - public function isSmartLogic(): bool | |
| 198 | + public function getSmartLogic(): array | |
| 205 | 199 | { |
| 206 | - return $this->notification->isSmartLogic(); | |
| 200 | + return $this->notification->getSmartLogic(); | |
| 207 | 201 | } |
| 208 | 202 | |
| 209 | 203 | /** |
| 210 | 204 | * Set the smart logic status. |
| 211 | 205 | * |
| 212 | - * @param bool $smartLogic | |
| 206 | + * @param array<string, mixed> $smartLogic | |
| 213 | 207 | */ |
| 214 | - public function setSmartLogic(bool $smartLogic): void | |
| 208 | + public function setSmartLogic(array $smartLogic): void | |
| 215 | 209 | { |
| 216 | 210 | $this->notification->smartLogic = $smartLogic; |
| 217 | 211 | } |
| 218 | 212 | |
| @@ -242,18 +236,20 @@ | ||
| 242 | 236 | * @return array<string, mixed> The notification entity as an array. |
| 243 | 237 | */ |
| 244 | 238 | public function toArray(): array |
| 245 | 239 | { |
| 246 | - return [ | |
| 247 | - 'id' => $this->getId(), | |
| 248 | - 'name' => $this->getName(), | |
| 249 | - 'sender' => $this->getSender(), | |
| 250 | - 'replyTo' => $this->getReplyTo(), | |
| 251 | - 'receiver' => $this->getReceiver(), | |
| 252 | - 'enabled' => $this->isEnabled(), | |
| 253 | - 'subject' => $this->getSubject(), | |
| 254 | - 'message' => $this->getMessage(), | |
| 255 | - 'smartLogic' => $this->isSmartLogic(), | |
| 256 | - 'formId' => $this->getFormId(), | |
| 257 | - ]; | |
| 240 | + return array_merge( | |
| 241 | + [ | |
| 242 | + 'id' => $this->getId(), | |
| 243 | + 'name' => $this->getName(), | |
| 244 | + 'enabled' => $this->isEnabled(), | |
| 245 | + 'subject' => $this->getSubject(), | |
| 246 | + 'message' => $this->getMessage(), | |
| 247 | + 'showEmptyFields' => $this->isShowEmptyFields(), | |
| 248 | + 'smartLogic' => $this->getSmartLogic(), | |
| 249 | + 'formId' => $this->getFormId(), | |
| 250 | + ], | |
| 251 | + $this->getNotificationContact()->toArray(), | |
| 252 | + $this->extensionData | |
| 253 | + ); | |
| 258 | 254 | } |
| 259 | 255 | } |