Browse code

Use option groups for slot types in the slot assistant

Benjamin Roth authored on25/07/2024 22:00:10
Showing1 changed files
... ...
@@ -363,19 +363,23 @@ class WeinanlieferungSlotAssistantController extends AbstractController
363 363
     protected function getSlottypeOptions()
364 364
     {
365 365
         $arrOptions = [['value'=>'','label'=>'-']];
366
-        $Slottypes = $this->db->prepare("SELECT t.id, t.title, t.containers, t.duration, s.title as 'standort' FROM tl_vr_wa_slottypes t INNER JOIN tl_vr_wa_standort s ON s.id = t.pid ORDER BY title")->executeQuery();
366
+        $Slottypes = $this->db->prepare("SELECT t.id, t.title, t.containers, t.duration, t.`default`, s.title as 'standort' FROM tl_vr_wa_slottypes t INNER JOIN tl_vr_wa_standort s ON s.id = t.pid ORDER BY t.`default` DESC, t.title")->executeQuery();
367 367
 
368
+        $arrOptGroups = [];
368 369
         if ($Slottypes->rowCount() > 0)
369 370
         {
370 371
             foreach ($Slottypes->fetchAllAssociative() as $option)
371 372
             {
372
-                $arrOptions[] = [
373
+                $arrOptGroups[$option['standort']][] = [
373 374
                     'value' => $option['id'],
374
-                    'label' => $option['title'].' ['.$this->translator->trans('MSC.wa_container', [], 'contao_tl_vr_wa_units').': '.$option['containers'].'] ['.$this->translator->trans('MSC.wa_duration', [], 'contao_tl_vr_wa_units').': '.$option['duration'].' '.($option['duration'] == 1 ? $this->translator->trans('MSC.wa_duration_minute', [], 'contao_tl_vr_wa_units') : $this->translator->trans('MSC.wa_duration_minutes', [], 'contao_tl_vr_wa_units')).'] ['.$option['standort'].']'
375
+                    'label' => $option['title'].' ['.$this->translator->trans('MSC.wa_container', [], 'contao_tl_vr_wa_units').': '.$option['containers'].'] ['.$this->translator->trans('MSC.wa_duration', [], 'contao_tl_vr_wa_units').': '.$option['duration'].' '.($option['duration'] == 1 ? $this->translator->trans('MSC.wa_duration_minute', [], 'contao_tl_vr_wa_units') : $this->translator->trans('MSC.wa_duration_minutes', [], 'contao_tl_vr_wa_units')).'] ['.$option['standort'].']' . ($option['default'] ? ' (Standard)' : '')
375 376
                 ];
376 377
             }
377 378
         }
378 379
 
380
+        ksort($arrOptGroups);
381
+        $arrOptions = array_merge($arrOptions, $arrOptGroups);
382
+
379 383
         return $arrOptions;
380 384
     }
381 385