PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 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
ResourceFactory.php
124 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\Resource;
12 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
13 use AmeliaBooking\Domain\ValueObjects\Number\Integer\PositiveInteger;
14 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
15 use AmeliaBooking\Domain\ValueObjects\String\EntityType;
16 use AmeliaBooking\Domain\ValueObjects\String\Name;
17 use AmeliaBooking\Domain\ValueObjects\String\Status;
18
19 /**
20 * Class ResourceFactory
21 *
22 * @package AmeliaBooking\Domain\Factory\Bookable\Service
23 */
24 class ResourceFactory
25 {
26 /**
27 * @param $data
28 *
29 * @return Resource
30 * @throws InvalidArgumentException
31 */
32 public static function create($data)
33 {
34 /** @var Resource $resource */
35 $resource = new Resource();
36
37 if (isset($data['id'])) {
38 $resource->setId(new Id($data['id']));
39 }
40
41 if (isset($data['name'])) {
42 $resource->setName(new Name($data['name']));
43 }
44
45 if (!empty($data['quantity'])) {
46 $resource->setQuantity(new PositiveInteger($data['quantity']));
47 }
48
49 if (!empty($data['status'])) {
50 $resource->setStatus(new Status($data['status']));
51 }
52
53 if (isset($data['shared'])) {
54 $resource->setShared(new EntityType($data['shared']));
55 }
56
57 if (isset($data['entities'])) {
58 $resource->setEntities(($data['entities']));
59 }
60
61 if (!empty($data['countAdditionalPeople'])) {
62 $resource->setCountAdditionalPeople(new BooleanValueObject($data['countAdditionalPeople']));
63 }
64
65 return $resource;
66 }
67
68 /**
69 * @param array $rows
70 *
71 * @return Collection
72 * @throws InvalidArgumentException
73 */
74 public static function createCollection($rows)
75 {
76 $resources = [];
77
78 foreach ($rows as $row) {
79 $resourceId = $row['resource_id'];
80
81 $resourceEntityId = $row['resource_entity_id'];
82
83 $resources[$resourceId]['id'] = $row['resource_id'];
84
85 $resources[$resourceId]['name'] = $row['resource_name'];
86
87 $resources[$resourceId]['quantity'] = $row['resource_quantity'];
88
89 $resources[$resourceId]['countAdditionalPeople'] = $row['resource_countAdditionalPeople'];
90
91 $resources[$resourceId]['status'] = $row['resource_status'];
92
93 $resources[$resourceId]['shared'] = $row['resource_shared'];
94
95 if (!isset($resources[$resourceId]['entities'])) {
96 $resources[$resourceId]['entities'] = [];
97 }
98
99 if ($resourceEntityId) {
100 $resources[$resourceId]['entities'][$resourceEntityId]['id'] = (int)$resourceEntityId;
101
102 $resources[$resourceId]['entities'][$resourceEntityId]['resourceId'] = (int)$resourceId;
103
104 $resources[$resourceId]['entities'][$resourceEntityId]['entityId'] =
105 (int)$row['resource_entity_entityId'];
106
107 $resources[$resourceId]['entities'][$resourceEntityId]['entityType'] =
108 $row['resource_entity_entityType'];
109 }
110 }
111
112 $resourcesCollection = new Collection();
113
114 foreach ($resources as $key => $resourceArray) {
115 $resourcesCollection->addItem(
116 self::create($resourceArray),
117 $key
118 );
119 }
120
121 return $resourcesCollection;
122 }
123 }
124