CategoryFactory.php
2 years ago
ExtraFactory.php
2 years ago
PackageCustomerFactory.php
1 year ago
PackageCustomerServiceFactory.php
1 year ago
PackageFactory.php
2 years ago
PackageServiceFactory.php
2 years ago
ResourceFactory.php
2 years ago
ServiceFactory.php
1 year ago
PackageServiceFactory.php
85 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace AmeliaBooking\Domain\Factory\Bookable\Service; |
| 8 | |
| 9 | use AmeliaBooking\Domain\Collection\Collection; |
| 10 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 11 | use AmeliaBooking\Domain\Entity\Bookable\Service\PackageService; |
| 12 | use AmeliaBooking\Domain\Factory\Location\LocationFactory; |
| 13 | use AmeliaBooking\Domain\Factory\User\UserFactory; |
| 14 | use AmeliaBooking\Domain\ValueObjects\BooleanValueObject; |
| 15 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\PositiveInteger; |
| 16 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 17 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\WholeNumber; |
| 18 | |
| 19 | /** |
| 20 | * Class PackageServiceFactory |
| 21 | * |
| 22 | * @package AmeliaBooking\Domain\Factory\Bookable\Service |
| 23 | */ |
| 24 | class PackageServiceFactory |
| 25 | { |
| 26 | /** |
| 27 | * @param $data |
| 28 | * |
| 29 | * @return PackageService |
| 30 | * @throws InvalidArgumentException |
| 31 | */ |
| 32 | public static function create($data) |
| 33 | { |
| 34 | /** @var PackageService $packageService */ |
| 35 | $packageService = new PackageService(); |
| 36 | |
| 37 | if (isset($data['id'])) { |
| 38 | $packageService->setId(new Id($data['id'])); |
| 39 | } |
| 40 | |
| 41 | if (isset($data['quantity'])) { |
| 42 | $packageService->setQuantity(new PositiveInteger($data['quantity'])); |
| 43 | } |
| 44 | |
| 45 | if (isset($data['service'])) { |
| 46 | $packageService->setService(ServiceFactory::create($data['service'])); |
| 47 | } |
| 48 | |
| 49 | if (isset($data['minimumScheduled'])) { |
| 50 | $packageService->setMinimumScheduled(new WholeNumber($data['minimumScheduled'])); |
| 51 | } |
| 52 | |
| 53 | if (isset($data['maximumScheduled'])) { |
| 54 | $packageService->setMaximumScheduled(new WholeNumber($data['maximumScheduled'])); |
| 55 | } |
| 56 | |
| 57 | if (isset($data['allowProviderSelection'])) { |
| 58 | $packageService->setAllowProviderSelection(new BooleanValueObject($data['allowProviderSelection'])); |
| 59 | } |
| 60 | |
| 61 | $packageService->setProviders(new Collection()); |
| 62 | |
| 63 | if (!empty($data['providers'])) { |
| 64 | foreach ($data['providers'] as $providerData) { |
| 65 | $providerData['type'] = 'provider'; |
| 66 | $packageService->getProviders()->addItem(UserFactory::create($providerData)); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | $packageService->setLocations(new Collection()); |
| 71 | |
| 72 | if (!empty($data['locations'])) { |
| 73 | foreach ($data['locations'] as $locationData) { |
| 74 | $packageService->getLocations()->addItem(LocationFactory::create($locationData)); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (!empty($data['position'])) { |
| 79 | $packageService->setPosition(new PositiveInteger($data['position'])); |
| 80 | } |
| 81 | |
| 82 | return $packageService; |
| 83 | } |
| 84 | } |
| 85 |