PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Domain / Factory / Bookable / Service / ResourceFactory.php
ameliabooking / src / Domain / Factory / Bookable / Service Last commit date
CategoryFactory.php 6 months ago ExtraFactory.php 2 years ago PackageCustomerFactory.php 2 weeks ago PackageCustomerServiceFactory.php 2 weeks ago PackageFactory.php 2 months ago PackageServiceFactory.php 6 months ago ResourceFactory.php 6 months ago ServiceFactory.php 6 months ago
ResourceFactory.php
125 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Domain\Factory\Bookable\Service;
9
10 use AmeliaBooking\Domain\Collection\Collection;
11 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
12 use AmeliaBooking\Domain\Entity\Bookable\Service\Resource;
13 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
14 use AmeliaBooking\Domain\ValueObjects\Number\Integer\PositiveInteger;
15 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
16 use AmeliaBooking\Domain\ValueObjects\String\EntityType;
17 use AmeliaBooking\Domain\ValueObjects\String\Name;
18 use AmeliaBooking\Domain\ValueObjects\String\Status;
19
20 /**
21 * Class ResourceFactory
22 *
23 * @package AmeliaBooking\Domain\Factory\Bookable\Service
24 */
25 class ResourceFactory
26 {
27 /**
28 * @param $data
29 *
30 * @return Resource
31 * @throws InvalidArgumentException
32 */
33 public static function create($data)
34 {
35 /** @var Resource $resource */
36 $resource = new Resource();
37
38 if (isset($data['id'])) {
39 $resource->setId(new Id($data['id']));
40 }
41
42 if (isset($data['name'])) {
43 $resource->setName(new Name($data['name']));
44 }
45
46 if (!empty($data['quantity'])) {
47 $resource->setQuantity(new PositiveInteger($data['quantity']));
48 }
49
50 if (!empty($data['status'])) {
51 $resource->setStatus(new Status($data['status']));
52 }
53
54 if (isset($data['shared'])) {
55 $resource->setShared(new EntityType($data['shared']));
56 }
57
58 if (isset($data['entities'])) {
59 $resource->setEntities(($data['entities']));
60 }
61
62 if (!empty($data['countAdditionalPeople'])) {
63 $resource->setCountAdditionalPeople(new BooleanValueObject($data['countAdditionalPeople']));
64 }
65
66 return $resource;
67 }
68
69 /**
70 * @param array $rows
71 *
72 * @return Collection
73 * @throws InvalidArgumentException
74 */
75 public static function createCollection($rows)
76 {
77 $resources = [];
78
79 foreach ($rows as $row) {
80 $resourceId = $row['resource_id'];
81
82 $resourceEntityId = $row['resource_entity_id'];
83
84 $resources[$resourceId]['id'] = $row['resource_id'];
85
86 $resources[$resourceId]['name'] = $row['resource_name'];
87
88 $resources[$resourceId]['quantity'] = $row['resource_quantity'];
89
90 $resources[$resourceId]['countAdditionalPeople'] = $row['resource_countAdditionalPeople'];
91
92 $resources[$resourceId]['status'] = $row['resource_status'];
93
94 $resources[$resourceId]['shared'] = $row['resource_shared'];
95
96 if (!isset($resources[$resourceId]['entities'])) {
97 $resources[$resourceId]['entities'] = [];
98 }
99
100 if ($resourceEntityId) {
101 $resources[$resourceId]['entities'][$resourceEntityId]['id'] = (int)$resourceEntityId;
102
103 $resources[$resourceId]['entities'][$resourceEntityId]['resourceId'] = (int)$resourceId;
104
105 $resources[$resourceId]['entities'][$resourceEntityId]['entityId'] =
106 (int)$row['resource_entity_entityId'];
107
108 $resources[$resourceId]['entities'][$resourceEntityId]['entityType'] =
109 $row['resource_entity_entityType'];
110 }
111 }
112
113 $resourcesCollection = new Collection();
114
115 foreach ($resources as $key => $resourceArray) {
116 $resourcesCollection->addItem(
117 self::create($resourceArray),
118 $key
119 );
120 }
121
122 return $resourcesCollection;
123 }
124 }
125