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/Notification/Notification.php +79 -41 0.8 → 1.5 View file →
@@ -1,13 +1,8 @@
1 1 <?php
2 2
3 3 namespace IvyForms\ValueObjects\Notification;
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
@@ -26,20 +21,12 @@
26 21 * @var string
27 22 */
28 23 public string $name;
29 24 /**
30 - * @var string
25 + * @var NotificationContact
31 26 */
32 - public string $sender;
27 + public NotificationContact $contact;
33 28 /**
34 - * @var string
35 - */
36 - public string $replyTo;
37 - /**
38 - * @var string
39 - */
40 - public string $receiver;
41 - /**
42 29 * @var bool
43 30 */
44 31 public bool $enabled;
45 32 /**
@@ -52,10 +39,14 @@
52 39 public string $message;
53 40 /**
54 41 * @var bool
55 42 */
56 - public bool $smartLogic;
43 + public bool $showEmptyFields;
57 44 /**
45 + * @var array<string, mixed>
46 + */
47 + public array $smartLogic;
48 + /**
58 49 * @var int
59 50 */
60 51 public int $formId;
61 52
@@ -63,15 +54,14 @@
63 54 * Form constructor.
64 55 *
65 56 * @param int $id
66 57 * @param string $name
67 - * @param string $sender
68 - * @param string $replyTo
69 - * @param string $receiver
58 + * @param NotificationContact $contact
70 59 * @param bool $enabled
71 60 * @param string $subject
72 61 * @param string $message
73 - * @param bool $smartLogic
62 + * @param bool $showEmptyFields
63 + * @param array<string, mixed> $smartLogic
74 64 * @param int $formId
75 65 * @throws InvalidArgumentException|ValidationException
76 66 */
77 67 public function __construct(
@@ -76,27 +66,25 @@
76 66 */
77 67 public function __construct(
78 68 int $id,
79 69 string $name,
80 - string $sender,
81 - string $replyTo,
82 - string $receiver,
70 + NotificationContact $contact,
83 71 bool $enabled,
84 72 string $subject,
85 73 string $message,
86 - bool $smartLogic,
74 + bool $showEmptyFields,
75 + array $smartLogic,
87 76 int $formId
88 77 ) {
89 - $this->id = $this->validateId($id);
90 - $this->name = $this->validateString($name, 255, 'name');
91 - $this->sender = $this->validateString($sender, 255, 'sender');
92 - $this->replyTo = $this->validateString($replyTo, 255, 'replyTo');
93 - $this->receiver = $this->validateString($receiver, 255, 'receiver');
94 - $this->enabled = $this->validateBool($enabled);
95 - $this->subject = $this->validateString($subject, 255, 'subject');
96 - $this->message = $this->validateString($message, 1000, 'message');
97 - $this->smartLogic = $this->validateBool($smartLogic);
98 - $this->formId = $this->validateId($formId);
78 + $this->id = $this->validateId($id);
79 + $this->name = $this->validateString($name, 255, 'name');
80 + $this->contact = $contact;
81 + $this->enabled = $this->validateBool($enabled);
82 + $this->subject = $this->validateString($subject, 255, 'subject');
83 + $this->message = $this->validateString($message, 4294967295, 'message');
84 + $this->showEmptyFields = $this->validateBool($showEmptyFields);
85 + $this->smartLogic = $this->validateSmartLogic($smartLogic);
86 + $this->formId = $this->validateId($formId);
99 87 }
100 88
101 89 /**
102 90 * Validates the ID.
@@ -178,9 +166,9 @@
178 166 * @return string
179 167 */
180 168 public function getSender(): string
181 169 {
182 - return $this->sender;
170 + return $this->contact->getSender();
183 171 }
184 172
185 173 /**
186 174 * Get the notification reply-to address.
@@ -188,9 +176,9 @@
188 176 * @return string
189 177 */
190 178 public function getReplyTo(): string
191 179 {
192 - return $this->replyTo;
180 + return $this->contact->getReplyTo();
193 181 }
194 182
195 183 /**
196 184 * Get the notification receiver.
@@ -198,12 +186,32 @@
198 186 * @return string
199 187 */
200 188 public function getReceiver(): string
201 189 {
202 - return $this->receiver;
190 + return $this->contact->getReceiver();
203 191 }
204 192
205 193 /**
194 + * Get the notification CC addresses.
195 + *
196 + * @return string
197 + */
198 + public function getCc(): string
199 + {
200 + return $this->contact->getCc();
201 + }
202 +
203 + /**
204 + * Get the notification BCC addresses.
205 + *
206 + * @return string
207 + */
208 + public function getBcc(): string
209 + {
210 + return $this->contact->getBcc();
211 + }
212 +
213 + /**
206 214 * Get the notification status.
207 215 *
208 216 * @return bool
209 217 */
@@ -232,18 +240,45 @@
232 240 return $this->message;
233 241 }
234 242
235 243 /**
244 + * Get the show empty fields status.
245 + *
246 + * @return bool
247 + */
248 + public function isShowEmptyFields(): bool
249 + {
250 + return $this->showEmptyFields;
251 + }
252 +
253 + /**
236 254 * Get the smart logic status.
237 255 *
238 - * @return bool
256 + * @return array<string, mixed>
239 257 */
240 - public function isSmartLogic(): bool
258 + public function getSmartLogic(): array
241 259 {
242 260 return $this->smartLogic;
243 261 }
244 262
245 263 /**
264 + * Normalize smart logic payload structure.
265 + *
266 + * @param array<string, mixed> $smartLogic
267 + * @return array<string, mixed>
268 + */
269 + private function validateSmartLogic(array $smartLogic): array
270 + {
271 + $match = $smartLogic['match'] ?? 'any';
272 +
273 + return [
274 + 'enabled' => (bool)($smartLogic['enabled'] ?? false),
275 + 'match' => in_array($match, ['any', 'all'], true) ? $match : 'any',
276 + 'rules' => is_array($smartLogic['rules'] ?? null) ? $smartLogic['rules'] : [],
277 + ];
278 + }
279 +
280 + /**
246 281 * Get the form ID associated with the notification.
247 282 *
248 283 * @return int
249 284 */
@@ -264,12 +299,15 @@
264 299 'name' => $this->getName(),
265 300 'sender' => $this->getSender(),
266 301 'replyTo' => $this->getReplyTo(),
267 302 'receiver' => $this->getReceiver(),
303 + 'cc' => $this->getCc(),
304 + 'bcc' => $this->getBcc(),
268 305 'enabled' => $this->isEnabled(),
269 306 'subject' => $this->getSubject(),
270 307 'message' => $this->getMessage(),
271 - 'smartLogic' => $this->isSmartLogic(),
272 - 'formId' => $this->getFormId(),
308 + 'showEmptyFields' => $this->isShowEmptyFields(),
309 + 'smartLogic' => $this->getSmartLogic(),
310 + 'formId' => $this->getFormId(),
273 311 ];
274 312 }
275 313 }