Browse code

Add search module

Benjamin Roth authored on06/02/2023 12:15:21
Showing6 changed files
... ...
@@ -11,5 +11,7 @@ declare(strict_types=1);
11 11
  */
12 12
 
13 13
 use vossmedien\AloxBundle\Controller\Frontend\Module\JoblistModuleController;
14
+use vossmedien\AloxBundle\Controller\Frontend\Module\JobSearchModuleController;
14 15
 
15 16
 $GLOBALS['TL_DCA']['tl_module']['palettes'][JoblistModuleController::TYPE] = '{title_legend},name,type;{alox_legend},perPage;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
17
+$GLOBALS['TL_DCA']['tl_module']['palettes'][JobSearchModuleController::TYPE] = '{title_legend},name,type;{aloxSearch_legend},jumpTo;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
... ...
@@ -11,6 +11,9 @@ declare(strict_types=1);
11 11
  */
12 12
 
13 13
 use vossmedien\AloxBundle\Controller\Frontend\Module\JoblistModuleController;
14
+use vossmedien\AloxBundle\Controller\Frontend\Module\JobSearchModuleController;
14 15
 
15 16
 $GLOBALS['TL_LANG']['FMD'][JoblistModuleController::TYPE][0] = 'Alox Job Liste';
16 17
 $GLOBALS['TL_LANG']['FMD'][JoblistModuleController::TYPE][1] = 'Gibt eine Liste mit Jobs aus.';
18
+$GLOBALS['TL_LANG']['FMD'][JobSearchModuleController::TYPE][0] = 'Alox Job Suchmaske';
19
+$GLOBALS['TL_LANG']['FMD'][JobSearchModuleController::TYPE][1] = 'Gibt eine Suchmaske aus, die auf eine Joblistenseite verlinkt werden kann.';
... ...
@@ -12,3 +12,4 @@ declare(strict_types=1);
12 12
 
13 13
 
14 14
 $GLOBALS['TL_LANG']['tl_module']['alox_legend'] = 'Listen-Konfiguration';
15
+$GLOBALS['TL_LANG']['tl_module']['aloxSearch_legend'] = 'Such-Konfiguration';
15 16
new file mode 100644
... ...
@@ -0,0 +1,74 @@
1
+{% extends '@Contao/block_unsearchable' %}
2
+
3
+{% block content %}
4
+    <form{{ formAction is defined ? ' action='~formAction : '' }} class="filter" method="get">
5
+        <div class="formbody">
6
+            <input type="hidden" name="FORM_SUBMIT" value="{{ formSubmit }}">
7
+            <div class="widget widget-text">
8
+                <input type="text" name="filter_keywords" placeholder="Jobtitel" value="">
9
+            </div>
10
+            <div class="widget widget-autocomplete">
11
+                <input type="hidden" id="filter-city-label-{{ id }}" name="filter_city_label" value="">
12
+                <select id="filter-city-{{ id }}" name="filter_city" data-placeholder="PLZ/Ort" autocomplete="off">
13
+                    <option value="">PLZ/Ort</option>
14
+                </select>
15
+            </div>
16
+            <div class="widget widget-text">
17
+                <input type="text" name="filter_radius" placeholder="Suchradius in km" value="">
18
+            </div>
19
+            {% if filterVertragsarten is defined %}
20
+                <div class="widget widget-select">
21
+                    <select name="filter_vertragsart">
22
+                        <option value="">Art der Anstellung</option>
23
+                        {% for vertragsart in filterVertragsarten %}
24
+                            <option value="{{ vertragsart.ObjectUuid }}">{{ vertragsart.Bezeichnung }}</option>
25
+                        {% endfor %}
26
+                    </select>
27
+                </div>
28
+            {% endif %}
29
+            {% if filterAbteilung is defined %}
30
+                <div class="widget widget-select">
31
+                    <select name="filter_abteilung">
32
+                        <option value="">Unternehmensbereich / Abteilung</option>
33
+                        {% for abteilung in filterAbteilung %}
34
+                            <option value="{{ abteilung.ObjectUuid }}">{{ abteilung.Bezeichnung }}</option>
35
+                        {% endfor %}
36
+                    </select>
37
+                </div>
38
+            {% endif %}
39
+            <div class="widget widget-submit">
40
+                <button type="submit">Suchen</button>
41
+            </div>
42
+        </div>
43
+    </form>
44
+
45
+    <script>
46
+        document.addEventListener('DOMContentLoaded', function () {
47
+            new TomSelect("#filter-city-{{ id }}",{
48
+                allowEmptyOption: true,
49
+                create: false,
50
+                valueField: 'latLon',
51
+                labelField: 'name',
52
+                searchField: 'name',
53
+                load: function(query, callback) {
54
+                    var url = '_geodb/getLatLon?q=' + encodeURIComponent(query);
55
+                    fetch(url)
56
+                        .then(response => response.json())
57
+                        .then(json => {
58
+                            callback(json.items);
59
+                        }).catch(() => {
60
+                        callback();
61
+                    });
62
+                },
63
+                onChange: function (values) {
64
+                    let target = document.getElementById('filter-city-label-{{ id }}');
65
+                    if (target !== undefined && this.activeOption.innerText !== undefined)
66
+                    {
67
+                        target.value = this.activeOption.innerText
68
+                    }
69
+                }
70
+            });
71
+        }, false);
72
+    </script>
73
+
74
+{% endblock %}
0 75
new file mode 100644
... ...
@@ -0,0 +1,80 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of alox bundle for Contao.
7
+ *
8
+ * (c) Benjamin Roth
9
+ *
10
+ * @license commercial
11
+ */
12
+
13
+namespace vossmedien\AloxBundle\Controller\Frontend\Module;
14
+
15
+use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
16
+use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
17
+use Contao\ModuleModel;
18
+use Contao\PageModel;
19
+use Contao\Template;
20
+use Symfony\Component\HttpFoundation\Request;
21
+use Symfony\Component\HttpFoundation\Response;
22
+use vossmedien\AloxBundle\API\Zvoove;
23
+
24
+/**
25
+ * @FrontendModule(JobSearchModuleController::TYPE, category="miscellaneous")
26
+ */
27
+class JobSearchModuleController extends AbstractFrontendModuleController
28
+{
29
+    public const TYPE = 'alox_jobsearch';
30
+
31
+    /**
32
+     * @var Zvoove
33
+     */
34
+    protected $api;
35
+
36
+    public function __construct(Zvoove $api)
37
+    {
38
+        $this->api = $api;
39
+    }
40
+
41
+
42
+    protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
43
+    {
44
+        $limit = null;
45
+        $offset = 0;
46
+
47
+        $strFormId = 'joblist-form';
48
+
49
+        $filterVertragsarten = $this->api->getKatalogByRelationName('StelleVertragsart','ChildEntity');
50
+        $filterAbteilung = $this->api->getKatalogByRelationName('StelleAbteilung','Abteilung');
51
+
52
+
53
+        // Populate template vars
54
+        if ($filterVertragsarten !== null && $filterVertragsarten->TotalItems > 0)
55
+        {
56
+            $template->filterVertragsarten = $filterVertragsarten;
57
+        }
58
+
59
+        if ($filterAbteilung !== null && $filterAbteilung->TotalItems > 0)
60
+        {
61
+            $template->filterAbteilung = $filterAbteilung;
62
+        }
63
+
64
+        $template->formSubmit = $strFormId;
65
+
66
+        // Submit action if jumpTo is defined
67
+        if ($model->jumpTo && ($jumpTo = PageModel::findByPk($model->jumpTo)) !== null)
68
+        {
69
+            $template->formAction = $jumpTo->getFrontendUrl();
70
+        }
71
+
72
+
73
+        // Add scripts
74
+        $GLOBALS['TL_BODY']['tomselect'] = Template::generateScriptTag('bundles/vossmedienalox/lib/tomselect/js/tom-select.base.js',false,null);
75
+        $GLOBALS['TL_CSS']['tomselect'] = 'bundles/vossmedienalox/lib/tomselect/css/tom-select.min.css';
76
+
77
+        return $template->getResponse();
78
+    }
79
+
80
+}
... ...
@@ -45,7 +45,7 @@ class JoblistModuleController extends AbstractFrontendModuleController
45 45
         $limit = null;
46 46
         $offset = 0;
47 47
 
48
-        $strFormId = 'joblist-form-' . $model->id;
48
+        $strFormId = 'joblist-form';
49 49
         $arrSearchParams = [];
50 50
         $arrSetFilters = [
51 51
             'filter_keywords' => null,