Browse code

Initial commit

Benjamin Roth authored on26/02/2024 17:53:24
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,51 @@
1
+<?php
2
+/**
3
+ * OBG Customizations
4
+ *
5
+ * Copyright (c) 2021 vonRotenberg
6
+ *
7
+ * @license commercial
8
+ */
9
+
10
+namespace vonRotenberg\RealEstateListingBundle\Controller\FrontendModule;
11
+
12
+use Contao\CoreBundle\DependencyInjection\Attribute\AsFrontendModule;
13
+use Contao\CoreBundle\Twig\FragmentTemplate;
14
+use vonRotenberg\RealEstateListingBundle\Model\RealEstateAssetsModel;
15
+use Contao\Controller;
16
+use Contao\ModuleModel;
17
+use Contao\PageModel;
18
+use Contao\StringUtil;
19
+use Contao\System;
20
+use Symfony\Component\HttpFoundation\Request;
21
+use Symfony\Component\HttpFoundation\Response;
22
+use Symfony\Contracts\Translation\TranslatorInterface;
23
+
24
+#[AsFrontendModule(RealEstateAssetsAdController::TYPE, category: 'miscellaneous')]
25
+class RealEstateAssetsAdController extends RealEstateAssetsModuleController
26
+{
27
+    public const TYPE = 'vr_re_assets_ad';
28
+
29
+    /**
30
+     * @var TranslatorInterface
31
+     */
32
+    protected $translator;
33
+
34
+    protected function getResponse(FragmentTemplate $template, ModuleModel $model, Request $request): Response
35
+    {
36
+        $this->translator = System::getContainer()->get('translator');
37
+        Controller::loadLanguageFile(RealEstateAssetsModel::getTable());
38
+
39
+        if (($assetsCount = $this->countRealEstateAssets(StringUtil::deserialize($model->vr_re_categories))) < 1)
40
+        {
41
+            return new Response();
42
+        }
43
+
44
+        $jumpTo = PageModel::findByPk($model->jumpTo);
45
+
46
+        $template->listUrl = $jumpTo !== null ? $jumpTo->getFrontendUrl() : null;
47
+
48
+        return $template->getResponse();
49
+    }
50
+
51
+}