PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 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 / Application / Services / Gallery / GalleryApplicationService.php
ameliabooking / src / Application / Services / Gallery Last commit date
GalleryApplicationService.php 1 year ago
GalleryApplicationService.php
124 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Services\Gallery;
4
5 use AmeliaBooking\Domain\Collection\Collection;
6 use AmeliaBooking\Domain\Entity\Gallery\GalleryImage;
7 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
8 use AmeliaBooking\Infrastructure\Common\Container;
9 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
10 use AmeliaBooking\Infrastructure\Repository\Gallery\GalleryRepository;
11
12 /**
13 * Class GalleryApplicationService
14 *
15 * @package AmeliaBooking\Application\Services\Gallery
16 */
17 class GalleryApplicationService
18 {
19 private $container;
20
21 /**
22 * GalleryApplicationService constructor.
23 *
24 * @param Container $container
25 */
26 public function __construct(Container $container)
27 {
28 $this->container = $container;
29 }
30
31 /**
32 * @param Collection $entityGallery
33 * @param int $entityId
34 *
35 * @throws \Slim\Exception\ContainerValueNotFoundException
36 * @throws QueryExecutionException
37 * @throws \Interop\Container\Exception\ContainerException
38 */
39 public function manageGalleryForEntityAdd($entityGallery, $entityId)
40 {
41 /** @var GalleryRepository $galleryRepository */
42 $galleryRepository = $this->container->get('domain.galleries.repository');
43
44 /** @var GalleryImage $image */
45 foreach ($entityGallery->getItems() as $image) {
46 $image->setEntityId(new Id($entityId));
47
48 if (!($imageId = $galleryRepository->add($image))) {
49 $galleryRepository->rollback();
50 }
51
52 $image->setId(new Id($imageId));
53 }
54 }
55
56 /**
57 * @param Collection $entityGallery
58 * @param int $entityId
59 * @param string $entityType
60 *
61 * @throws \Slim\Exception\ContainerValueNotFoundException
62 * @throws QueryExecutionException
63 * @throws \Interop\Container\Exception\ContainerException
64 */
65 public function manageGalleryForEntityUpdate($entityGallery, $entityId, $entityType)
66 {
67 /** @var GalleryRepository $galleryRepository */
68 $galleryRepository = $this->container->get('domain.galleries.repository');
69
70 $imagesIds = [];
71
72 /** @var GalleryImage $image */
73 foreach ($entityGallery->getItems() as $image) {
74 if ($image->getId()) {
75 $imagesIds[] = $image->getId()->getValue();
76 }
77 }
78
79 if (
80 !$galleryRepository->deleteAllNotInImagesArray(
81 $imagesIds,
82 $entityId,
83 $entityType
84 )
85 ) {
86 $galleryRepository->rollback();
87 }
88
89 /** @var GalleryImage $image */
90 foreach ($entityGallery->getItems() as $image) {
91 if (!$image->getId()) {
92 $galleryRepository->add($image);
93 } else {
94 $galleryRepository->update($image->getId()->getValue(), $image);
95 }
96 }
97 }
98
99 /**
100 * @param Collection $entityGallery
101 *
102 * @return boolean
103 *
104 * @throws \Slim\Exception\ContainerValueNotFoundException
105 * @throws QueryExecutionException
106 * @throws \Interop\Container\Exception\ContainerException
107 */
108 public function manageGalleryForEntityDelete($entityGallery)
109 {
110 /** @var GalleryRepository $galleryRepository */
111 $galleryRepository = $this->container->get('domain.galleries.repository');
112
113 /** @var GalleryImage $image */
114 foreach ($entityGallery->getItems() as $image) {
115 if (!$galleryRepository->delete($image->getId()->getValue())) {
116 $galleryRepository->rollback();
117 return false;
118 }
119 }
120
121 return true;
122 }
123 }
124