PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
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 +91 -34 0.3.1 → 1.5.1 View file →
@@ -1,15 +1,11 @@
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;
7 +use IvyForms\Services\Translations\BackendStrings;
12 8
13 9 /**
14 10 * Class Notification
15 11 *
@@ -25,16 +21,12 @@
25 21 * @var string
26 22 */
27 23 public string $name;
28 24 /**
29 - * @var string
25 + * @var NotificationContact
30 26 */
31 - public string $sender;
27 + public NotificationContact $contact;
32 28 /**
33 - * @var string
34 - */
35 - public string $receiver;
36 - /**
37 29 * @var bool
38 30 */
39 31 public bool $enabled;
40 32 /**
@@ -47,10 +39,14 @@
47 39 public string $message;
48 40 /**
49 41 * @var bool
50 42 */
51 - public bool $smartLogic;
43 + public bool $showEmptyFields;
52 44 /**
45 + * @var array<string, mixed>
46 + */
47 + public array $smartLogic;
48 + /**
53 49 * @var int
54 50 */
55 51 public int $formId;
56 52
@@ -58,14 +54,14 @@
58 54 * Form constructor.
59 55 *
60 56 * @param int $id
61 57 * @param string $name
62 - * @param string $sender
63 - * @param string $receiver
58 + * @param NotificationContact $contact
64 59 * @param bool $enabled
65 60 * @param string $subject
66 61 * @param string $message
67 - * @param bool $smartLogic
62 + * @param bool $showEmptyFields
63 + * @param array<string, mixed> $smartLogic
68 64 * @param int $formId
69 65 * @throws InvalidArgumentException|ValidationException
70 66 */
71 67 public function __construct(
@@ -70,25 +66,25 @@
70 66 */
71 67 public function __construct(
72 68 int $id,
73 69 string $name,
74 - string $sender,
75 - string $receiver,
70 + NotificationContact $contact,
76 71 bool $enabled,
77 72 string $subject,
78 73 string $message,
79 - bool $smartLogic,
74 + bool $showEmptyFields,
75 + array $smartLogic,
80 76 int $formId
81 77 ) {
82 - $this->id = $this->validateId($id);
83 - $this->name = $this->validateString($name, 255, 'name');
84 - $this->sender = $this->validateString($sender, 255, 'sender');
85 - $this->receiver = $this->validateString($receiver, 255, 'receiver');
86 - $this->enabled = $this->validateBool($enabled);
87 - $this->subject = $this->validateString($subject, 255, 'subject');
88 - $this->message = $this->validateString($message, 1000, 'message');
89 - $this->smartLogic = $this->validateBool($smartLogic);
90 - $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);
91 87 }
92 88
93 89 /**
94 90 * Validates the ID.
@@ -100,9 +96,9 @@
100 96 */
101 97 private function validateId(int $id): int
102 98 {
103 99 if ($id < 0) {
104 - throw new InvalidArgumentException("Id must be a positive integer.");
100 + throw new InvalidArgumentException(BackendStrings::getExceptionStrings()['id_positive_integer']);
105 101 }
106 102 return $id;
107 103 }
108 104
@@ -170,12 +166,22 @@
170 166 * @return string
171 167 */
172 168 public function getSender(): string
173 169 {
174 - return $this->sender;
170 + return $this->contact->getSender();
175 171 }
176 172
177 173 /**
174 + * Get the notification reply-to address.
175 + *
176 + * @return string
177 + */
178 + public function getReplyTo(): string
179 + {
180 + return $this->contact->getReplyTo();
181 + }
182 +
183 + /**
178 184 * Get the notification receiver.
179 185 *
180 186 * @return string
181 187 */
@@ -180,12 +186,32 @@
180 186 * @return string
181 187 */
182 188 public function getReceiver(): string
183 189 {
184 - return $this->receiver;
190 + return $this->contact->getReceiver();
185 191 }
186 192
187 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 + /**
188 214 * Get the notification status.
189 215 *
190 216 * @return bool
191 217 */
@@ -214,18 +240,45 @@
214 240 return $this->message;
215 241 }
216 242
217 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 + /**
218 254 * Get the smart logic status.
219 255 *
220 - * @return bool
256 + * @return array<string, mixed>
221 257 */
222 - public function isSmartLogic(): bool
258 + public function getSmartLogic(): array
223 259 {
224 260 return $this->smartLogic;
225 261 }
226 262
227 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 + /**
228 281 * Get the form ID associated with the notification.
229 282 *
230 283 * @return int
231 284 */
@@ -244,13 +297,17 @@
244 297 return [
245 298 'id' => $this->getId(),
246 299 'name' => $this->getName(),
247 300 'sender' => $this->getSender(),
301 + 'replyTo' => $this->getReplyTo(),
248 302 'receiver' => $this->getReceiver(),
303 + 'cc' => $this->getCc(),
304 + 'bcc' => $this->getBcc(),
249 305 'enabled' => $this->isEnabled(),
250 306 'subject' => $this->getSubject(),
251 307 'message' => $this->getMessage(),
252 - 'smartLogic' => $this->isSmartLogic(),
253 - 'formId' => $this->getFormId(),
308 + 'showEmptyFields' => $this->isShowEmptyFields(),
309 + 'smartLogic' => $this->getSmartLogic(),
310 + 'formId' => $this->getFormId(),
254 311 ];
255 312 }
256 313 }