Browse code

Progress

Benjamin Roth authored on21/02/2023 19:42:19
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,75 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+namespace App\Module;
6
+
7
+use Contao\Widget;
8
+use Isotope\Module\CumulativeFilter;
9
+use Contao\Database;
10
+
11
+/**
12
+ * @property array $iso_cumulativeFields
13
+ */
14
+class IsoCumulativeFilter extends CumulativeFilter
15
+{
16
+    /**
17
+     * Gets the used and available options for given attribute
18
+     *
19
+     * @param string $attribute The attribute name
20
+     * @param string $label     Set to the label of the attribute
21
+     *
22
+     * @return array
23
+     */
24
+    protected function getOptionsForAttribute($attribute, &$label)
25
+    {
26
+        if ($attribute !== 'attr_monthyear')
27
+        {
28
+            $options = parent::getOptionsForAttribute($attribute, $label);
29
+        } else {
30
+            $usedValues = $this->getUsedValuesForAttribute(
31
+                $attribute,
32
+                $this->findCategories(),
33
+                $this->iso_newFilter,
34
+                $this->iso_list_where
35
+            );
36
+
37
+            if (empty($usedValues)) {
38
+                return array();
39
+            }
40
+
41
+            // Use the default routine to initialize options data
42
+            $arrWidget = Widget::getAttributesFromDca(
43
+                $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$attribute],
44
+                $attribute
45
+            );
46
+
47
+            $label   = $arrWidget['label'];
48
+
49
+            $result = Database::getInstance()->execute("
50
+                    SELECT id AS 'value', month AS 'label'
51
+                    FROM tl_iso_product_month
52
+                    WHERE id IN (" . implode(',', $usedValues) . ")
53
+                    ORDER BY CASE
54
+                    WHEN label LIKE 'Januar%' THEN 1
55
+                    WHEN label LIKE 'Februar%' THEN 2
56
+                    WHEN label LIKE 'März%' THEN 3
57
+                    WHEN label LIKE 'April%' THEN 4
58
+                    WHEN label LIKE 'Mai%' THEN 5
59
+                    WHEN label LIKE 'Juni%' THEN 6
60
+                    WHEN label LIKE 'Juli%' THEN 7
61
+                    WHEN label LIKE 'August%' THEN 8
62
+                    WHEN label LIKE 'September%' THEN 9
63
+                    WHEN label LIKE 'Oktober%' THEN 10
64
+                    WHEN label LIKE 'November%' THEN 11
65
+                    WHEN label LIKE 'Dezember%' THEN 12
66
+                    ELSE 13
67
+                    END
68
+                ");
69
+
70
+            $options = $result->fetchAllAssoc();
71
+        }
72
+
73
+        return $options;
74
+    }
75
+}