Browse code

Save BE reservation list filter in session

Benjamin Roth authored on11/09/2024 10:03:22
Showing2 changed files
... ...
@@ -20,19 +20,19 @@
20 20
                 </div>
21 21
                 <div class="tl_filter tl_subpanel">
22 22
                     <strong>Filter:</strong>
23
-                    <select name="tl_day" id="tl_day" class="tl_select tl_chosen">
23
+                    <select name="tl_day" id="tl_day" class="tl_select tl_chosen{% if filter.day.selected is defined %} active{% endif %}">
24 24
                         <option value=""{{ filter.day.selected is not defined or not filter.day.selected ? ' selected' : '' }}>Tag</option>
25 25
                         {% for value, label in filter.day.options %}
26 26
                             <option value="{{ value }}"{{ filter.day.selected is defined and filter.day.selected == value ? ' selected' : '' }}>{{ label }}</option>
27 27
                         {% endfor %}
28 28
                     </select>
29
-                    {#<select name="tl_month" id="tl_month" class="tl_select tl_chosen">
29
+                    {#<select name="tl_month" id="tl_month" class="tl_select tl_chosen{% if filter.month.selected is defined %} active{% endif %}">
30 30
                         <option value=""{{ filter.month.selected is not defined or not filter.month.selected ? ' selected' : '' }}>Monat</option>
31 31
                         {% for value, label in filter.month.options %}
32 32
                             <option value="{{ value }}"{{ filter.month.selected is defined and filter.month.selected == value ? ' selected' : '' }}>{{ label }}</option>
33 33
                         {% endfor %}
34 34
                     </select>#}
35
-                    <select name="tl_standort" id="tl_standort" class="tl_select tl_chosen">
35
+                    <select name="tl_standort" id="tl_standort" class="tl_select tl_chosen{% if filter.standort.selected is defined %} active{% endif %}">
36 36
                         <option value=""{{ filter.standort.selected is not defined or not filter.standort.selected ? ' selected' : '' }}>Standort</option>
37 37
                         {% for value, label in filter.standort.options %}
38 38
                             <option value="{{ value }}"{{ filter.standort.selected is defined and filter.standort.selected == value ? ' selected' : '' }}>{{ label }}</option>
... ...
@@ -23,6 +23,7 @@ use Contao\System;
23 23
 use Doctrine\DBAL\Connection;
24 24
 use Symfony\Component\HttpFoundation\RequestStack;
25 25
 use Symfony\Component\HttpFoundation\Response;
26
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
26 27
 use Symfony\Component\Routing\Annotation\Route;
27 28
 use Twig\Environment as TwigEnvironment;
28 29
 use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungLeseartModel;
... ...
@@ -68,50 +69,70 @@ class WeinanlieferungBookingsController extends AbstractController
68 69
         System::loadLanguageFile('default');
69 70
 
70 71
         // Filter
71
-        if (Input::post('FORM_SUBMIT') === 'tl_filters' && Input::post('filter_reset') === null)
72
+        /** @var SessionInterface $objSession */
73
+        $objSession = \System::getContainer()->get('session');
74
+
75
+        $session = $objSession->get('filter');
76
+
77
+        if (Input::post('FORM_SUBMIT') === 'tl_filters')
72 78
         {
73
-            $queryBuilder = $this->db->createQueryBuilder()
74
-                ->select('id')
75
-                ->from(WeinanlieferungSlotsModel::getTable());
79
+            $arrFilterFields = ['tl_day', 'tl_standort', 'tl_status'];
76 80
 
77
-            if (!empty(Input::post('tl_day')) && is_numeric(Input::post('tl_day')))
81
+            foreach ($arrFilterFields as $v)
78 82
             {
79
-                $Day = new Date(Input::post('tl_day'));
80
-                $arrData['filter']['day']['selected'] = Input::post('tl_day');
81
-                $queryBuilder->andWhere('date BETWEEN :day_start AND :day_end')
82
-                    ->setParameter('day_start', $Day->dayBegin)
83
-                    ->setParameter('day_end', $Day->dayEnd);
84
-            } else {
85
-                $Today = new Date();
86
-                $queryBuilder->andWhere("time >= :today")
87
-                    ->setParameter('today',$Today->dayBegin);
83
+                if ($v == Input::post($v) || Input::post('filter_reset') == '1')
84
+                {
85
+                    unset($session['tl_vr_wa_reservation'][$v]);
86
+                } // Apply the filter
87
+                else
88
+                {
89
+                    $session['tl_vr_wa_reservation'][$v] = Input::post($v);
90
+                }
88 91
             }
92
+            $objSession->set('filter', $session);
93
+        }
89 94
 
90
-            /*if (!empty(Input::post('tl_month')) && is_numeric(Input::post('tl_month')))
91
-            {
92
-                $Month = new Date(Input::post('tl_month'));
93
-                $arrData['filter']['month']['selected'] = Input::post('tl_month');
94
-                $queryBuilder->andWhere('date BETWEEN :month_start AND :month_end')
95
-                    ->setParameter('month_start', $Month->monthBegin)
96
-                    ->setParameter('month_end', $Month->monthEnd);
97
-            } else {
98
-                $Today = new Date();
99
-                $queryBuilder->andWhere("time >= :today")
100
-                    ->setParameter('today',$Today->dayBegin);
101
-            }*/
95
+        $queryBuilder = $this->db->createQueryBuilder()
96
+            ->select('id')
97
+            ->from(WeinanlieferungSlotsModel::getTable());
102 98
 
103
-            if (!empty(Input::post('tl_standort')) && is_numeric(Input::post('tl_standort')))
104
-            {
105
-                $Month = new Date(Input::post('tl_standort'));
106
-                $arrData['filter']['standort']['selected'] = Input::post('tl_standort');
107
-                $queryBuilder->andWhere('pid = :pid')
108
-                    ->setParameter('pid', (int) Input::post('tl_standort'));
109
-            }
99
+        if (!empty($session['tl_vr_wa_reservation']['tl_day']) && is_numeric($session['tl_vr_wa_reservation']['tl_day']))
100
+        {
101
+            $Day = new Date($session['tl_vr_wa_reservation']['tl_day']);
102
+            $arrData['filter']['day']['selected'] = $session['tl_vr_wa_reservation']['tl_day'];
103
+            $queryBuilder->andWhere('date BETWEEN :day_start AND :day_end')
104
+                ->setParameter('day_start', $Day->dayBegin)
105
+                ->setParameter('day_end', $Day->dayEnd);
106
+        } else {
107
+            $Today = new Date();
108
+            $queryBuilder->andWhere("time >= :today")
109
+                ->setParameter('today',$Today->dayBegin);
110
+        }
110 111
 
111
-            $arrSlots = $queryBuilder->fetchFirstColumn();
112
+        /*if (!empty(Input::post('tl_month')) && is_numeric(Input::post('tl_month')))
113
+        {
114
+            $Month = new Date(Input::post('tl_month'));
115
+            $arrData['filter']['month']['selected'] = Input::post('tl_month');
116
+            $queryBuilder->andWhere('date BETWEEN :month_start AND :month_end')
117
+                ->setParameter('month_start', $Month->monthBegin)
118
+                ->setParameter('month_end', $Month->monthEnd);
119
+        } else {
120
+            $Today = new Date();
121
+            $queryBuilder->andWhere("time >= :today")
122
+                ->setParameter('today',$Today->dayBegin);
123
+        }*/
112 124
 
125
+        if (!empty($session['tl_vr_wa_reservation']['tl_standort']) && is_numeric($session['tl_vr_wa_reservation']['tl_standort']))
126
+        {
127
+            $Month = new Date($session['tl_vr_wa_reservation']['tl_standort']);
128
+            $arrData['filter']['standort']['selected'] = $session['tl_vr_wa_reservation']['tl_standort'];
129
+            $queryBuilder->andWhere('pid = :pid')
130
+                ->setParameter('pid', (int) $session['tl_vr_wa_reservation']['tl_standort']);
113 131
         }
114 132
 
133
+        $arrSlots = $queryBuilder->fetchFirstColumn();
134
+
135
+
115 136
         $arrDayOptions = [];
116 137
         $DayRequest = $this->db->executeQuery("SELECT s.date, DATE_FORMAT(FROM_UNIXTIME(s.date),'%d.%m.%Y') as 'day_label' FROM tl_vr_wa_reservation r INNER JOIN tl_vr_wa_slot s ON s.id = r.pid GROUP BY day_label ORDER BY s.date DESC");
117 138