Browse code

Add month filter to backend reservations list

Benjamin Roth authored on21/09/2023 15:44:16
Showing2 changed files
... ...
@@ -20,8 +20,11 @@
20 20
                 </div>
21 21
                 <div class="tl_sorting tl_subpanel">
22 22
                     <strong>Filter:</strong>
23
-                    <select name="tl_sort" id="tl_sort" class="tl_select tl_chosen">
24
-                        <option value="title" selected="selected">Monat</option>
23
+                    <select name="tl_month" id="tl_month" class="tl_select tl_chosen">
24
+                        <option value=""{{ filter.month.selected is not defined or not filter.month.selected ? ' selected' : '' }}>Monat</option>
25
+                        {% for value, label in filter.month.options %}
26
+                            <option value="{{ value }}"{{ filter.month.selected is defined and filter.month.selected == value ? ' selected' : '' }}>{{ label }}</option>
27
+                        {% endfor %}
25 28
                     </select>
26 29
                 </div>
27 30
             </div>
... ...
@@ -68,6 +68,28 @@ class WeinanlieferungBookingsController extends AbstractController
68 68
         System::loadLanguageFile('default');
69 69
 
70 70
         // Filter
71
+        if (Input::post('FORM_SUBMIT') === 'tl_filters' && Input::post('filter_reset') === null)
72
+        {
73
+            $queryBuilder = $this->db->createQueryBuilder()
74
+                ->select('id')
75
+                ->from(WeinanlieferungSlotsModel::getTable());
76
+
77
+            if (!empty(Input::post('tl_month')) && is_numeric(Input::post('tl_month')))
78
+            {
79
+                $Month = new Date(Input::post('tl_month'));
80
+                $arrData['filter']['month']['selected'] = Input::post('tl_month');
81
+                $queryBuilder->andWhere('date BETWEEN :month_start AND :month_end')
82
+                    ->setParameter('month_start', $Month->monthBegin)
83
+                    ->setParameter('month_end', $Month->monthEnd);
84
+            } else {
85
+                $Today = new Date();
86
+                $queryBuilder->andWhere("time >= :today")
87
+                    ->setParameter('today',$Today->dayBegin);
88
+            }
89
+
90
+            $arrSlots = $queryBuilder->fetchFirstColumn();
91
+
92
+        }
71 93
         $arrMonthOptions = [];
72 94
         $MonthRequest = $this->db->executeQuery("SELECT s.date, DATE_FORMAT(FROM_UNIXTIME(s.date),'%m/%Y') as 'month_label' FROM tl_vr_wa_reservation r INNER JOIN tl_vr_wa_slot s ON s.id = r.pid GROUP BY month_label, s.date ORDER BY s.date ASC");
73 95
 
... ...
@@ -76,9 +98,28 @@ class WeinanlieferungBookingsController extends AbstractController
76 98
             $arrMonthOptions[$month['date']] = $month['month_label'];
77 99
         }
78 100
 
101
+        $arrData['filter']['month']['options'] = $arrMonthOptions;
102
+
79 103
 
80 104
         // Get bookings
81
-        if (($bookings = WeinanlieferungReservationModel::findAllFuture(['order' => "(SELECT tl_vr_wa_slot.time FROM tl_vr_wa_slot WHERE tl_vr_wa_slot.id=tl_vr_wa_reservation.pid) ASC"])) !== null)
105
+        if (isset($queryBuilder))
106
+        {
107
+            $arrColumns = null;
108
+            if (count($arrSlots))
109
+            {
110
+                $arrColumns[] = "pid IN (".implode(',',$arrSlots).")";
111
+            }
112
+            if (!$arrColumns)
113
+            {
114
+                $bookings = WeinanlieferungReservationModel::findAllFuture(['order' => "(SELECT tl_vr_wa_slot.time FROM tl_vr_wa_slot WHERE tl_vr_wa_slot.id=tl_vr_wa_reservation.pid) ASC"]);
115
+            } else {
116
+                $bookings = WeinanlieferungReservationModel::findBy($arrColumns,null,['order' => "(SELECT tl_vr_wa_slot.time FROM tl_vr_wa_slot WHERE tl_vr_wa_slot.id=tl_vr_wa_reservation.pid) ASC"]);
117
+            }
118
+
119
+        } else {
120
+            $bookings = WeinanlieferungReservationModel::findAllFuture(['order' => "(SELECT tl_vr_wa_slot.time FROM tl_vr_wa_slot WHERE tl_vr_wa_slot.id=tl_vr_wa_reservation.pid) ASC"]);
121
+        }
122
+        if ($bookings !== null)
82 123
         {
83 124
             /** @var WeinanlieferungReservationModel $booking */
84 125
             foreach ($bookings as $booking)