NotificationFactory.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\Factory\Notification; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | use AmeliaBooking\Domain\Entity\Notification\Notification; |
| 7 | use AmeliaBooking\Domain\ValueObjects\BooleanValueObject; |
| 8 | use AmeliaBooking\Domain\ValueObjects\DateTime\TimeOfDay; |
| 9 | use AmeliaBooking\Domain\ValueObjects\Duration; |
| 10 | use AmeliaBooking\Domain\ValueObjects\Json; |
| 11 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 12 | use AmeliaBooking\Domain\ValueObjects\String\BookingType; |
| 13 | use AmeliaBooking\Domain\ValueObjects\String\Html; |
| 14 | use AmeliaBooking\Domain\ValueObjects\String\Name; |
| 15 | use AmeliaBooking\Domain\ValueObjects\String\NotificationSendTo; |
| 16 | use AmeliaBooking\Domain\ValueObjects\String\NotificationStatus; |
| 17 | use AmeliaBooking\Domain\ValueObjects\String\NotificationType; |
| 18 | |
| 19 | /** |
| 20 | * Class NotificationFactory |
| 21 | * |
| 22 | * @package AmeliaBooking\Domain\Factory\Notification |
| 23 | */ |
| 24 | class NotificationFactory |
| 25 | { |
| 26 | /** |
| 27 | * @param array $data |
| 28 | * |
| 29 | * @return Notification |
| 30 | * @throws InvalidArgumentException |
| 31 | */ |
| 32 | public static function create($data) |
| 33 | { |
| 34 | $notification = new Notification( |
| 35 | new Name($data['name']), |
| 36 | new NotificationStatus($data['status']), |
| 37 | new NotificationType($data['type']), |
| 38 | new BookingType($data['entity']), |
| 39 | new NotificationSendTo($data['sendTo']), |
| 40 | new Name($data['subject']), |
| 41 | new Html($data['content']) |
| 42 | ); |
| 43 | |
| 44 | if (isset($data['id'])) { |
| 45 | $notification->setId(new Id($data['id'])); |
| 46 | } |
| 47 | |
| 48 | if (isset($data['customName']) && !empty($data['customName'])) { |
| 49 | $notification->setCustomName($data['customName']); |
| 50 | } |
| 51 | |
| 52 | if (isset($data['time'])) { |
| 53 | $notification->setTime(new TimeOfDay($data['time'])); |
| 54 | } |
| 55 | |
| 56 | if (isset($data['timeBefore'])) { |
| 57 | $notification->setTimeBefore(new Duration($data['timeBefore'])); |
| 58 | } |
| 59 | |
| 60 | if (isset($data['translations'])) { |
| 61 | $notification->setTranslations(new Json($data['translations'])); |
| 62 | } |
| 63 | |
| 64 | if (isset($data['timeAfter'])) { |
| 65 | $notification->setTimeAfter(new Duration($data['timeAfter'])); |
| 66 | } |
| 67 | |
| 68 | if (isset($data['entityIds'])) { |
| 69 | $notification->setEntityIds(($data['entityIds'])); |
| 70 | } |
| 71 | |
| 72 | if (isset($data['sendOnlyMe']) && !empty($data['sendOnlyMe'])) { |
| 73 | $notification->setSendOnlyMe(new BooleanValueObject($data['sendOnlyMe'])); |
| 74 | } |
| 75 | |
| 76 | if (isset($data['whatsAppTemplate'])) { |
| 77 | $notification->setWhatsAppTemplate($data['whatsAppTemplate']); |
| 78 | } |
| 79 | |
| 80 | if (isset($data['minimumTimeBeforeBooking'])) { |
| 81 | $notification->setMinimumTimeBeforeBooking(new Json($data['minimumTimeBeforeBooking'])); |
| 82 | } |
| 83 | |
| 84 | return $notification; |
| 85 | } |
| 86 | } |
| 87 |