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 / Application / Services / Gallery / GalleryApplicationService.php
ameliabooking / src / Application / Services / Gallery Last commit date
GalleryApplicationService.php 6 years ago
GalleryApplicationService.php
123 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
20 private $container;
21
22 /**
23 * GalleryApplicationService constructor.
24 *
25 * @param Container $container
26 */
27 public function __construct(Container $container)
28 {
29 $this->container = $container;
30 }
31
32 /**
33 * @param Collection $entityGallery
34 * @param int $entityId
35 *
36 * @throws \Slim\Exception\ContainerValueNotFoundException
37 * @throws QueryExecutionException
38 * @throws \Interop\Container\Exception\ContainerException
39 */
40 public function manageGalleryForEntityAdd($entityGallery, $entityId)
41 {
42 /** @var GalleryRepository $galleryRepository */
43 $galleryRepository = $this->container->get('domain.galleries.repository');
44
45 /** @var GalleryImage $image */
46 foreach ($entityGallery->getItems() as $image) {
47 $image->setEntityId(new Id($entityId));
48
49 if (!($imageId = $galleryRepository->add($image))) {
50 $galleryRepository->rollback();
51 }
52
53 $image->setId(new Id($imageId));
54 }
55 }
56
57 /**
58 * @param Collection $entityGallery
59 * @param int $entityId
60 * @param string $entityType
61 *
62 * @throws \Slim\Exception\ContainerValueNotFoundException
63 * @throws QueryExecutionException
64 * @throws \Interop\Container\Exception\ContainerException
65 */
66 public function manageGalleryForEntityUpdate($entityGallery, $entityId, $entityType)
67 {
68 /** @var GalleryRepository $galleryRepository */
69 $galleryRepository = $this->container->get('domain.galleries.repository');
70
71 $imagesIds = [];
72
73 /** @var GalleryImage $image */
74 foreach ($entityGallery->getItems() as $image) {
75 if ($image->getId()) {
76 $imagesIds[] = $image->getId()->getValue();
77 }
78 }
79
80 if (!$galleryRepository->deleteAllNotInImagesArray(
81 $imagesIds,
82 $entityId,
83 $entityType
84 )) {
85 $galleryRepository->rollback();
86 }
87
88 /** @var GalleryImage $image */
89 foreach ($entityGallery->getItems() as $image) {
90 if (!$image->getId()) {
91 $galleryRepository->add($image);
92 } else {
93 $galleryRepository->update($image->getId()->getValue(), $image);
94 }
95 }
96 }
97
98 /**
99 * @param Collection $entityGallery
100 *
101 * @return boolean
102 *
103 * @throws \Slim\Exception\ContainerValueNotFoundException
104 * @throws QueryExecutionException
105 * @throws \Interop\Container\Exception\ContainerException
106 */
107 public function manageGalleryForEntityDelete($entityGallery)
108 {
109 /** @var GalleryRepository $galleryRepository */
110 $galleryRepository = $this->container->get('domain.galleries.repository');
111
112 /** @var GalleryImage $image */
113 foreach ($entityGallery->getItems() as $image) {
114 if (!$galleryRepository->delete($image->getId()->getValue())) {
115 $galleryRepository->rollback();
116 return false;
117 }
118 }
119
120 return true;
121 }
122 }
123