PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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
ivyforms / backend / src / Factory / Notification / NotificationFactory.php

NotificationFactory.php in The Innovative Form Builder – IvyForms 1.0, at backend/src/Factory/Notification/NotificationFactory.php

94 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Factory\Notification;
4
5 use IvyForms\Common\Exceptions\InvalidArgumentException;
6 use IvyForms\Entity\Notification\Notification as NotificationEntity;
7 use IvyForms\ValueObjects\Notification\Notification;
8 use IvyForms\ValueObjects\Notification\NotificationContact;
9
10 /**
11 * Class NotificationFactory
12 *
13 * @package IvyForms\Factory\Notification
14 */
15 class NotificationFactory
16 {
17 /**
18 * Create a NotificationEntity from an array of data.
19 *
20 * @param array<string, mixed> $data
21 *
22 * @return NotificationEntity
23 * @throws InvalidArgumentException
24 */
25 public static function create(array $data): NotificationEntity
26 {
27 $contact = new NotificationContact(
28 $data['sender'] ?? '',
29 $data['receiver'] ?? '',
30 $data['replyTo'] ?? ''
31 );
32
33 $notificationValueObject = new Notification(
34 $data['id'] ?? 0,
35 $data['name'] ?? '',
36 $contact,
37 $data['enabled'] ?? true,
38 $data['subject'] ?? '',
39 $data['message'] ?? '',
40 $data['showEmptyFields'] ?? false,
41 $data['smartLogic'] ?? false,
42 $data['formId'] ?? 0
43 );
44
45 $notificationEntity = new NotificationEntity($notificationValueObject);
46
47 if (isset($data['id'])) {
48 $notificationEntity->setId($data['id']);
49 }
50
51 if (isset($data['name'])) {
52 $notificationEntity->setName($data['name']);
53 }
54
55 if (isset($data['sender'])) {
56 $notificationEntity->getNotificationContact()->setSender($data['sender']);
57 }
58
59 if (isset($data['replyTo'])) {
60 $notificationEntity->getNotificationContact()->setReplyTo($data['replyTo']);
61 }
62
63 if (isset($data['receiver'])) {
64 $notificationEntity->getNotificationContact()->setReceiver($data['receiver']);
65 }
66
67 if (isset($data['enabled'])) {
68 $notificationEntity->setEnabled($data['enabled']);
69 }
70
71 if (isset($data['subject'])) {
72 $notificationEntity->setSubject($data['subject']);
73 }
74
75 if (isset($data['message'])) {
76 $notificationEntity->setMessage(wp_unslash($data['message']));
77 }
78
79 if (isset($data['showEmptyFields'])) {
80 $notificationEntity->setShowEmptyFields($data['showEmptyFields']);
81 }
82
83 if (isset($data['smartLogic'])) {
84 $notificationEntity->setSmartLogic($data['smartLogic']);
85 }
86
87 if (isset($data['formId'])) {
88 $notificationEntity->setFormId($data['formId']);
89 }
90
91 return $notificationEntity;
92 }
93 }
94