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 +89 -33 0.5 → 1.5.1 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,16 +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 $receiver;
37 - /**
38 29 * @var bool
39 30 */
40 31 public bool $enabled;
41 32 /**
@@ -48,10 +39,14 @@
48 39 public string $message;
49 40 /**
50 41 * @var bool
51 42 */
52 - public bool $smartLogic;
43 + public bool $showEmptyFields;
53 44 /**
45 + * @var array<string, mixed>
46 + */
47 + public array $smartLogic;
48 + /**
54 49 * @var int
55 50 */
56 51 public int $formId;
57 52
@@ -59,14 +54,14 @@
59 54 * Form constructor.
60 55 *
61 56 * @param int $id
62 57 * @param string $name
63 - * @param string $sender
64 - * @param string $receiver
58 + * @param NotificationContact $contact
65 59 * @param bool $enabled
66 60 * @param string $subject
67 61 * @param string $message
68 - * @param bool $smartLogic
62 + * @param bool $showEmptyFields
63 + * @param array<string, mixed> $smartLogic
69 64 * @param int $formId
70 65 * @throws InvalidArgumentException|ValidationException
71 66 */
72 67 public function __construct(
@@ -71,25 +66,25 @@
71 66 */
72 67 public function __construct(
73 68 int $id,
74 69 string $name,
75 - string $sender,
76 - string $receiver,
70 + NotificationContact $contact,
77 71 bool $enabled,
78 72 string $subject,
79 73 string $message,
80 - bool $smartLogic,
74 + bool $showEmptyFields,
75 + array $smartLogic,
81 76 int $formId
82 77 ) {
83 - $this->id = $this->validateId($id);
84 - $this->name = $this->validateString($name, 255, 'name');
85 - $this->sender = $this->validateString($sender, 255, 'sender');
86 - $this->receiver = $this->validateString($receiver, 255, 'receiver');
87 - $this->enabled = $this->validateBool($enabled);
88 - $this->subject = $this->validateString($subject, 255, 'subject');
89 - $this->message = $this->validateString($message, 1000, 'message');
90 - $this->smartLogic = $this->validateBool($smartLogic);
91 - $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);
92 87 }
93 88
94 89 /**
95 90 * Validates the ID.
@@ -171,12 +166,22 @@
171 166 * @return string
172 167 */
173 168 public function getSender(): string
174 169 {
175 - return $this->sender;
170 + return $this->contact->getSender();
176 171 }
177 172
178 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 + /**
179 184 * Get the notification receiver.
180 185 *
181 186 * @return string
182 187 */
@@ -181,12 +186,32 @@
181 186 * @return string
182 187 */
183 188 public function getReceiver(): string
184 189 {
185 - return $this->receiver;
190 + return $this->contact->getReceiver();
186 191 }
187 192
188 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 + /**
189 214 * Get the notification status.
190 215 *
191 216 * @return bool
192 217 */
@@ -215,18 +240,45 @@
215 240 return $this->message;
216 241 }
217 242
218 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 + /**
219 254 * Get the smart logic status.
220 255 *
221 - * @return bool
256 + * @return array<string, mixed>
222 257 */
223 - public function isSmartLogic(): bool
258 + public function getSmartLogic(): array
224 259 {
225 260 return $this->smartLogic;
226 261 }
227 262
228 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 + /**
229 281 * Get the form ID associated with the notification.
230 282 *
231 283 * @return int
232 284 */
@@ -245,13 +297,17 @@
245 297 return [
246 298 'id' => $this->getId(),
247 299 'name' => $this->getName(),
248 300 'sender' => $this->getSender(),
301 + 'replyTo' => $this->getReplyTo(),
249 302 'receiver' => $this->getReceiver(),
303 + 'cc' => $this->getCc(),
304 + 'bcc' => $this->getBcc(),
250 305 'enabled' => $this->isEnabled(),
251 306 'subject' => $this->getSubject(),
252 307 'message' => $this->getMessage(),
253 - 'smartLogic' => $this->isSmartLogic(),
254 - 'formId' => $this->getFormId(),
308 + 'showEmptyFields' => $this->isShowEmptyFields(),
309 + 'smartLogic' => $this->getSmartLogic(),
310 + 'formId' => $this->getFormId(),
255 311 ];
256 312 }
257 313 }