... | ... |
@@ -51,7 +51,7 @@ class ManagedPropertyReaderController extends AbstractFrontendModuleController |
51 | 51 |
$jumpTo = PageModel::findByPk($model->jumpTo); |
52 | 52 |
|
53 | 53 |
// Set the item from the auto_item parameter |
54 |
- if (!isset($_GET['items']) && Config::get('useAutoItem') && Input::get('auto_item')) |
|
54 |
+ if (!isset($_GET['items']) && Input::get('auto_item')) |
|
55 | 55 |
{ |
56 | 56 |
Input::setGet('items', Input::get('auto_item')); |
57 | 57 |
} |
... | ... |
@@ -4,6 +4,7 @@ declare(strict_types=1); |
4 | 4 |
|
5 | 5 |
namespace vonRotenberg\RealEstateListingBundle\Controller\FrontendModule; |
6 | 6 |
|
7 |
+use Contao\Config; |
|
7 | 8 |
use vonRotenberg\RealEstateListingBundle\Model\ManagedPropertyModel; |
8 | 9 |
use Contao\ArrayUtil; |
9 | 10 |
use Contao\Controller; |
... | ... |
@@ -50,7 +51,7 @@ class ManagedPropertyReaderController extends AbstractFrontendModuleController |
50 | 51 |
$jumpTo = PageModel::findByPk($model->jumpTo); |
51 | 52 |
|
52 | 53 |
// Set the item from the auto_item parameter |
53 |
- if (!isset($_GET['items']) && \Config::get('useAutoItem') && isset($_GET['auto_item'])) |
|
54 |
+ if (!isset($_GET['items']) && Config::get('useAutoItem') && Input::get('auto_item')) |
|
54 | 55 |
{ |
55 | 56 |
Input::setGet('items', Input::get('auto_item')); |
56 | 57 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,187 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
5 |
+namespace vonRotenberg\RealEstateListingBundle\Controller\FrontendModule; |
|
6 |
+ |
|
7 |
+use vonRotenberg\RealEstateListingBundle\Model\ManagedPropertyModel; |
|
8 |
+use Contao\ArrayUtil; |
|
9 |
+use Contao\Controller; |
|
10 |
+use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; |
|
11 |
+use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule; |
|
12 |
+use Contao\CoreBundle\Exception\ResponseException; |
|
13 |
+use Contao\CoreBundle\Image\Studio\Figure; |
|
14 |
+use Contao\CoreBundle\Image\Studio\FigureBuilder; |
|
15 |
+use Contao\CoreBundle\Twig\FragmentTemplate; |
|
16 |
+use Contao\Date; |
|
17 |
+use Contao\File; |
|
18 |
+use Contao\FilesModel; |
|
19 |
+use Contao\FrontendTemplate; |
|
20 |
+use Contao\Input; |
|
21 |
+use Contao\ModuleModel; |
|
22 |
+use Contao\PageModel; |
|
23 |
+use Contao\StringUtil; |
|
24 |
+use Contao\System; |
|
25 |
+use Contao\Template; |
|
26 |
+use Symfony\Component\HttpFoundation\Request; |
|
27 |
+use Symfony\Component\HttpFoundation\Response; |
|
28 |
+use Symfony\Contracts\Translation\TranslatorInterface; |
|
29 |
+use vonRotenberg\RealEstateListingBundle\Model\RealEstateAssetsModel; |
|
30 |
+ |
|
31 |
+#[AsFrontendModule(category: 'vr_real_estate')] |
|
32 |
+class ManagedPropertyReaderController extends AbstractFrontendModuleController |
|
33 |
+{ |
|
34 |
+ public const TYPE = 'managed_property_reader'; |
|
35 |
+ /** |
|
36 |
+ * @var RealEstateAssetsModel|null |
|
37 |
+ */ |
|
38 |
+ protected $asset; |
|
39 |
+ |
|
40 |
+ /** |
|
41 |
+ * @var TranslatorInterface |
|
42 |
+ */ |
|
43 |
+ protected $translator; |
|
44 |
+ |
|
45 |
+ protected function getResponse(FragmentTemplate $template, ModuleModel $model, Request $request): Response |
|
46 |
+ { |
|
47 |
+ $this->translator = System::getContainer()->get('translator'); |
|
48 |
+ Controller::loadLanguageFile(ManagedPropertyModel::getTable()); |
|
49 |
+ |
|
50 |
+ $jumpTo = PageModel::findByPk($model->jumpTo); |
|
51 |
+ |
|
52 |
+ // Set the item from the auto_item parameter |
|
53 |
+ if (!isset($_GET['items']) && \Config::get('useAutoItem') && isset($_GET['auto_item'])) |
|
54 |
+ { |
|
55 |
+ Input::setGet('items', Input::get('auto_item')); |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ $this->asset = ManagedPropertyModel::findPublishedByIdOrAlias(Input::get('items')); |
|
59 |
+ |
|
60 |
+ if ($this->asset === null) |
|
61 |
+ { |
|
62 |
+ return new Response(); |
|
63 |
+ } |
|
64 |
+ |
|
65 |
+ $figureBuilder = System::getContainer() |
|
66 |
+ ->get('contao.image.studio') |
|
67 |
+ ->createFigureBuilder() |
|
68 |
+ ->setSize($model->imgSize) |
|
69 |
+ ->enableLightbox(true); |
|
70 |
+// ->setLightboxGroupIdentifier('lb' . $model->id); |
|
71 |
+ |
|
72 |
+ $arrItem = array_merge($this->asset->row(), [ |
|
73 |
+ 'features' => StringUtil::deserialize($this->asset->features,true), |
|
74 |
+ 'availableFrom' => ($this->asset->availability == 'immediately' ? $this->translator->trans('REF.re_availability.immediately', [], 'contao_default') : Date::parse(Date::getNumericDateFormat(), $this->asset->availableFrom)), |
|
75 |
+ 'deadline' => ($this->asset->stop > 0 ? Date::parse(Date::getNumericDateFormat(), $this->asset->stop) : ''), |
|
76 |
+ 'teaserFigure' => $this->getImageFigures($this->asset->gallerySRC, $figureBuilder, $this->asset->orderSRC, 1), |
|
77 |
+ 'galleryFigures' => $this->getImageFigures($this->asset->gallerySRC, $figureBuilder, $this->asset->orderSRC, 0, 0), |
|
78 |
+ 'floorPlansFigures' => $this->getImageFigures($this->asset->floorPlansSRC, $figureBuilder, $this->asset->floorPlansOrderSRC), |
|
79 |
+ 'listUrl' => $jumpTo !== null ? $jumpTo->getFrontendUrl() : null, |
|
80 |
+ 'pdfUrl' => $request->getBaseUrl() . $request->getPathInfo() . '?pdf', |
|
81 |
+ 'qrUrl' => $request->getUriForPath($request->getPathInfo()), |
|
82 |
+ 'map' => $this->asset->mapIframe ?? '' |
|
83 |
+ ]); |
|
84 |
+ |
|
85 |
+ $template->item = $arrItem; |
|
86 |
+ |
|
87 |
+ return $template->getResponse(); |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ /** |
|
91 |
+ * @param string|array $strUuids |
|
92 |
+ * @param FigureBuilder $figureBuilder |
|
93 |
+ * @param string|array $strOrder |
|
94 |
+ * |
|
95 |
+ * @return array|Figure |
|
96 |
+ * @throws \Exception |
|
97 |
+ */ |
|
98 |
+ public function getImageFigures($strUuids, $figureBuilder, $strOrder = null, int $intLimit = 0, int $intOffset = 0) |
|
99 |
+ { |
|
100 |
+ $arrImageFigures = []; |
|
101 |
+ |
|
102 |
+ if (($imageFiles = FilesModel::findMultipleByUuids(StringUtil::deserialize($strUuids))) !== null) |
|
103 |
+ { |
|
104 |
+ $images = array(); |
|
105 |
+ while ($imageFiles->next()) |
|
106 |
+ { |
|
107 |
+ // Continue if the files has been processed or does not exist |
|
108 |
+ if (isset($images[$imageFiles->path]) || !file_exists(System::getContainer()->getParameter('kernel.project_dir') . '/' . $imageFiles->path)) |
|
109 |
+ { |
|
110 |
+ continue; |
|
111 |
+ } |
|
112 |
+ |
|
113 |
+ // Single files |
|
114 |
+ if ($imageFiles->type == 'file') |
|
115 |
+ { |
|
116 |
+ $objFile = new File($imageFiles->path); |
|
117 |
+ |
|
118 |
+ if (!$objFile->isImage) |
|
119 |
+ { |
|
120 |
+ continue; |
|
121 |
+ } |
|
122 |
+ |
|
123 |
+ // Add the image |
|
124 |
+ $images[$imageFiles->path] = $imageFiles->current(); |
|
125 |
+ } // Folders |
|
126 |
+ else |
|
127 |
+ { |
|
128 |
+ $objSubfiles = FilesModel::findByPid($imageFiles->uuid, array('order' => 'name')); |
|
129 |
+ |
|
130 |
+ if ($objSubfiles === null) |
|
131 |
+ { |
|
132 |
+ continue; |
|
133 |
+ } |
|
134 |
+ |
|
135 |
+ while ($objSubfiles->next()) |
|
136 |
+ { |
|
137 |
+ // Skip subfolders |
|
138 |
+ if ($objSubfiles->type == 'folder') |
|
139 |
+ { |
|
140 |
+ continue; |
|
141 |
+ } |
|
142 |
+ |
|
143 |
+ $objFile = new File($objSubfiles->path); |
|
144 |
+ |
|
145 |
+ if (!$objFile->isImage) |
|
146 |
+ { |
|
147 |
+ continue; |
|
148 |
+ } |
|
149 |
+ |
|
150 |
+ // Add the image |
|
151 |
+ $images[$objSubfiles->path] = $objSubfiles->current(); |
|
152 |
+ } |
|
153 |
+ } |
|
154 |
+ } |
|
155 |
+ |
|
156 |
+ if ($strOrder !== null) |
|
157 |
+ { |
|
158 |
+ $images = ArrayUtil::sortByOrderField($images, $strOrder); |
|
159 |
+ } |
|
160 |
+ $images = array_values($images); |
|
161 |
+ |
|
162 |
+ // Offset images |
|
163 |
+ if ($intOffset > 0) |
|
164 |
+ { |
|
165 |
+ $images = \array_slice($images, ($intOffset < count($images) ? $intOffset : count($images))); |
|
166 |
+ } |
|
167 |
+ |
|
168 |
+ // Limit number of images |
|
169 |
+ if ($intLimit > 0) |
|
170 |
+ { |
|
171 |
+ $images = \array_slice($images, 0, $intLimit); |
|
172 |
+ } |
|
173 |
+ |
|
174 |
+ // Build figures of images |
|
175 |
+ foreach ($images as $image) |
|
176 |
+ { |
|
177 |
+ $figure = $figureBuilder |
|
178 |
+ ->fromFilesModel($image) |
|
179 |
+ ->build(); |
|
180 |
+ |
|
181 |
+ $arrImageFigures[] = $figure; |
|
182 |
+ } |
|
183 |
+ |
|
184 |
+ } |
|
185 |
+ return count ($arrImageFigures) === 1 && $intLimit === 1 ? array_shift($arrImageFigures) : $arrImageFigures; |
|
186 |
+ } |
|
187 |
+} |