Browse code

Add reader module and extend API service to provide job details

Benjamin Roth authored on06/02/2023 17:22:18
Showing1 changed files
... ...
@@ -17,6 +17,7 @@ use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController
17 17
 use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
18 18
 use Contao\Input;
19 19
 use Contao\ModuleModel;
20
+use Contao\PageModel;
20 21
 use Contao\Template;
21 22
 use Symfony\Component\HttpFoundation\Request;
22 23
 use Symfony\Component\HttpFoundation\Response;
... ...
@@ -168,6 +169,12 @@ class JoblistModuleController extends AbstractFrontendModuleController
168 169
             $template->filterAbteilung = $filterAbteilung;
169 170
         }
170 171
 
172
+        // Details link if jumpto page is defined
173
+        if ($model->jumpTo && ($jumpTo = PageModel::findByPk($model->jumpTo)) !== null)
174
+        {
175
+            $template->detailsLink = $jumpTo->getFrontendUrl();
176
+        }
177
+
171 178
         $template->formSubmit = $strFormId;
172 179
         $template->formSetFilters = $arrSetFilters;
173 180
         $template->pagination = $pagination;
Browse code

Add search module

Benjamin Roth authored on06/02/2023 12:15:21
Showing1 changed files
... ...
@@ -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,
Browse code

Implement pagination

Benjamin Roth authored on03/02/2023 10:49:12
Showing1 changed files
... ...
@@ -12,6 +12,7 @@ declare(strict_types=1);
12 12
 
13 13
 namespace vossmedien\AloxBundle\Controller\Frontend\Module;
14 14
 
15
+use Contao\Config;
15 16
 use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
16 17
 use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
17 18
 use Contao\Input;
... ...
@@ -41,6 +42,9 @@ class JoblistModuleController extends AbstractFrontendModuleController
41 42
 
42 43
     protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
43 44
     {
45
+        $limit = null;
46
+        $offset = 0;
47
+
44 48
         $strFormId = 'joblist-form-' . $model->id;
45 49
         $arrSearchParams = [];
46 50
         $arrSetFilters = [
... ...
@@ -99,6 +103,49 @@ class JoblistModuleController extends AbstractFrontendModuleController
99 103
         // Get (filtered) jobs
100 104
         $jobs = $this->api->getStellenFiltered($arrSearchParams);
101 105
 
106
+        // Get the total number of items
107
+        $intTotal = $jobs->TotalItems;
108
+        $total = $intTotal;
109
+        $pagination = '';
110
+
111
+        if ($model->perPage > 0)
112
+        {
113
+            // Adjust the overall limit
114
+            if (isset($limit))
115
+            {
116
+                $total = min($limit, $total);
117
+            }
118
+
119
+            // Get the current page
120
+            $id = 'list_page' . $model->id;
121
+            $page = Input::get($id) ?? 1;
122
+
123
+            // Do not index or cache the page if the page number is outside the range
124
+            if ($page < 1 || $page > max(ceil($total / $model->perPage), 1))
125
+            {
126
+                throw new \PageNotFoundException('Page not found: ' . \Environment::get('uri'));
127
+            }
128
+
129
+            // Set limit and offset
130
+            $limit = $model->perPage;
131
+            $offset += (max($page, 1) - 1) * $model->perPage;
132
+
133
+            // Overall limit
134
+            if ($offset + $limit > $total)
135
+            {
136
+                $limit = $total - $offset;
137
+            }
138
+
139
+            // Add the pagination menu
140
+            $objPagination = new \Pagination($total, $model->perPage, Config::get('maxPaginationLinks'), $id);
141
+            $pagination = $objPagination->generate("\n  ");
142
+
143
+            $arrSearchParams['pageNo'] = $page;
144
+            $arrSearchParams['pageSize'] = $limit;
145
+            $jobs = $this->api->getStellenFiltered($arrSearchParams);
146
+
147
+        }
148
+
102 149
 
103 150
         // Get filter options
104 151
         $filterVertragsarten = $this->api->getKatalogByRelationName('StelleVertragsart','ChildEntity');
... ...
@@ -123,6 +170,7 @@ class JoblistModuleController extends AbstractFrontendModuleController
123 170
 
124 171
         $template->formSubmit = $strFormId;
125 172
         $template->formSetFilters = $arrSetFilters;
173
+        $template->pagination = $pagination;
126 174
 
127 175
 
128 176
         // Add scripts
Browse code

Add tom select dropdown for test purposes

Benjamin Roth authored on02/02/2023 13:15:02
Showing1 changed files
... ...
@@ -43,7 +43,14 @@ class JoblistModuleController extends AbstractFrontendModuleController
43 43
     {
44 44
         $strFormId = 'joblist-form-' . $model->id;
45 45
         $arrSearchParams = [];
46
-        $arrSetFilters = [];
46
+        $arrSetFilters = [
47
+            'filter_keywords' => null,
48
+            'filter_city' => null,
49
+            'filter_city_label' => null,
50
+            'filter_radius' => null,
51
+            'filter_vertragsart' => null,
52
+            'filter_abteilung' => null
53
+        ];
47 54
 
48 55
         // Prepare search parameters
49 56
         if (Input::get('FORM_SUBMIT') == $strFormId)
... ...
@@ -54,6 +61,18 @@ class JoblistModuleController extends AbstractFrontendModuleController
54 61
                 $arrSetFilters['filter_keywords'] = Input::get('filter_keywords');
55 62
             }
56 63
 
64
+            if (Input::get('filter_city'))
65
+            {
66
+                list($lat,$lon) = explode(',',Input::get('filter_city'));
67
+                $arrSearchParams['lat'] = floatval($lat);
68
+                $arrSearchParams['lon'] = floatval($lon);
69
+                $arrSearchParams['radius'] = max((intval(Input::get('filter_radius')) ?: 25),5);
70
+
71
+                $arrSetFilters['filter_city'] = Input::get('filter_city');
72
+                $arrSetFilters['filter_city_label'] = Input::get('filter_city_label');
73
+                $arrSetFilters['filter_radius'] = Input::get('filter_radius');
74
+            }
75
+
57 76
             if (Input::get('filter_vertragsart'))
58 77
             {
59 78
                 $value = Input::get('filter_vertragsart');
... ...
@@ -106,6 +125,10 @@ class JoblistModuleController extends AbstractFrontendModuleController
106 125
         $template->formSetFilters = $arrSetFilters;
107 126
 
108 127
 
128
+        // Add scripts
129
+        $GLOBALS['TL_BODY']['tomselect'] = Template::generateScriptTag('bundles/vossmedienalox/lib/tomselect/js/tom-select.base.js',false,null);
130
+        $GLOBALS['TL_CSS']['tomselect'] = 'bundles/vossmedienalox/lib/tomselect/css/tom-select.min.css';
131
+
109 132
         return $template->getResponse();
110 133
     }
111 134
 
Browse code

Allow multi select filters

Benjamin Roth authored on01/02/2023 22:51:44
Showing1 changed files
... ...
@@ -56,13 +56,23 @@ class JoblistModuleController extends AbstractFrontendModuleController
56 56
 
57 57
             if (Input::get('filter_vertragsart'))
58 58
             {
59
-                $arrSearchParams['vaUuids'] = Input::get('filter_vertragsart');
59
+                $value = Input::get('filter_vertragsart');
60
+                if (\is_array($value))
61
+                {
62
+                    $value = implode(',',$value);
63
+                }
64
+                $arrSearchParams['vaUuids'] = $value;
60 65
                 $arrSetFilters['filter_vertragsart'] = Input::get('filter_vertragsart');
61 66
             }
62 67
 
63 68
             if (Input::get('filter_abteilung'))
64 69
             {
65
-                $arrSearchParams['abtUuids'] = Input::get('filter_abteilung');
70
+                $value = Input::get('filter_abteilung');
71
+                if (\is_array($value))
72
+                {
73
+                    $value = implode(',',$value);
74
+                }
75
+                $arrSearchParams['abtUuids'] = $value;
66 76
                 $arrSetFilters['filter_abteilung'] = Input::get('filter_abteilung');
67 77
             }
68 78
         }
Browse code

First iteration of filterable joblist

Benjamin Roth authored on01/02/2023 22:36:09
Showing1 changed files
... ...
@@ -14,12 +14,12 @@ namespace vossmedien\AloxBundle\Controller\Frontend\Module;
14 14
 
15 15
 use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
16 16
 use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
17
+use Contao\Input;
17 18
 use Contao\ModuleModel;
18
-use Contao\System;
19 19
 use Contao\Template;
20
-use Symfony\Component\HttpClient\HttpClient;
21 20
 use Symfony\Component\HttpFoundation\Request;
22 21
 use Symfony\Component\HttpFoundation\Response;
22
+use vossmedien\AloxBundle\API\Zvoove;
23 23
 
24 24
 /**
25 25
  * @FrontendModule(JoblistModuleController::TYPE, category="miscellaneous")
... ...
@@ -28,24 +28,75 @@ class JoblistModuleController extends AbstractFrontendModuleController
28 28
 {
29 29
     public const TYPE = 'alox_joblist';
30 30
 
31
+    /**
32
+     * @var Zvoove
33
+     */
34
+    protected $api;
35
+
36
+    public function __construct(Zvoove $api)
37
+    {
38
+        $this->api = $api;
39
+    }
40
+
41
+
31 42
     protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
32 43
     {
33
-        $apiKey = System::getContainer()->getParameter('vossmedien_alox.zvoove.api_key');
34
-        $apiDomain = System::getContainer()->getParameter('vossmedien_alox.zvoove.api_domain');
44
+        $strFormId = 'joblist-form-' . $model->id;
45
+        $arrSearchParams = [];
46
+        $arrSetFilters = [];
47
+
48
+        // Prepare search parameters
49
+        if (Input::get('FORM_SUBMIT') == $strFormId)
50
+        {
51
+            if (Input::get('filter_keywords'))
52
+            {
53
+                $arrSearchParams['keywords'] = Input::get('filter_keywords');
54
+                $arrSetFilters['filter_keywords'] = Input::get('filter_keywords');
55
+            }
56
+
57
+            if (Input::get('filter_vertragsart'))
58
+            {
59
+                $arrSearchParams['vaUuids'] = Input::get('filter_vertragsart');
60
+                $arrSetFilters['filter_vertragsart'] = Input::get('filter_vertragsart');
61
+            }
62
+
63
+            if (Input::get('filter_abteilung'))
64
+            {
65
+                $arrSearchParams['abtUuids'] = Input::get('filter_abteilung');
66
+                $arrSetFilters['filter_abteilung'] = Input::get('filter_abteilung');
67
+            }
68
+        }
69
+
70
+        // Get (filtered) jobs
71
+        $jobs = $this->api->getStellenFiltered($arrSearchParams);
72
+
73
+
74
+        // Get filter options
75
+        $filterVertragsarten = $this->api->getKatalogByRelationName('StelleVertragsart','ChildEntity');
76
+        $filterAbteilung = $this->api->getKatalogByRelationName('StelleAbteilung','Abteilung');
77
+
78
+
79
+        // Populate template vars
80
+        if ($jobs !== null && $jobs->TotalItems > 0)
81
+        {
82
+            $template->jobs = $jobs;
83
+        }
35 84
 
36
-        $httpClient = HttpClient::create();
85
+        if ($filterVertragsarten !== null && $filterVertragsarten->TotalItems > 0)
86
+        {
87
+            $template->filterVertragsarten = $filterVertragsarten;
88
+        }
37 89
 
38
-        $header = [
39
-            'headers' => [
40
-                'X-ApiKey' => $apiKey
41
-            ]
42
-        ];
90
+        if ($filterAbteilung !== null && $filterAbteilung->TotalItems > 0)
91
+        {
92
+            $template->filterAbteilung = $filterAbteilung;
93
+        }
43 94
 
44
-        $response = $httpClient->request('GET',$apiDomain, $header);
95
+        $template->formSubmit = $strFormId;
96
+        $template->formSetFilters = $arrSetFilters;
45 97
 
46
-        dump($response->getContent());
47 98
 
48
-        return new Response();
99
+        return $template->getResponse();
49 100
     }
50 101
 
51 102
 }
Browse code

Add Joblist skeletton for further development

Benjamin Roth authored on31/01/2023 08:55:26
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,51 @@
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\System;
19
+use Contao\Template;
20
+use Symfony\Component\HttpClient\HttpClient;
21
+use Symfony\Component\HttpFoundation\Request;
22
+use Symfony\Component\HttpFoundation\Response;
23
+
24
+/**
25
+ * @FrontendModule(JoblistModuleController::TYPE, category="miscellaneous")
26
+ */
27
+class JoblistModuleController extends AbstractFrontendModuleController
28
+{
29
+    public const TYPE = 'alox_joblist';
30
+
31
+    protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
32
+    {
33
+        $apiKey = System::getContainer()->getParameter('vossmedien_alox.zvoove.api_key');
34
+        $apiDomain = System::getContainer()->getParameter('vossmedien_alox.zvoove.api_domain');
35
+
36
+        $httpClient = HttpClient::create();
37
+
38
+        $header = [
39
+            'headers' => [
40
+                'X-ApiKey' => $apiKey
41
+            ]
42
+        ];
43
+
44
+        $response = $httpClient->request('GET',$apiDomain, $header);
45
+
46
+        dump($response->getContent());
47
+
48
+        return new Response();
49
+    }
50
+
51
+}