| ... | ... |
@@ -105,7 +105,7 @@ $GLOBALS['TL_DCA']['tl_vr_wa_standort'] = array |
| 105 | 105 |
'palettes' => array |
| 106 | 106 |
( |
| 107 | 107 |
'__selector__' => ['nc_enable'], |
| 108 |
- 'default' => '{title_legend},title;{notification_legend},nc_enable'
|
|
| 108 |
+ 'default' => '{title_legend},title,number_ranges;{notification_legend},nc_enable'
|
|
| 109 | 109 |
), |
| 110 | 110 |
|
| 111 | 111 |
// Subpalettes |
| ... | ... |
@@ -167,6 +167,21 @@ $GLOBALS['TL_DCA']['tl_vr_wa_standort'] = array |
| 167 | 167 |
'eval' => array('mandatory'=>true, 'multiple'=>true,'tl_class'=>'clr'),
|
| 168 | 168 |
'sql' => "blob NULL", |
| 169 | 169 |
'relation' => array('type'=>'hasMany', 'load'=>'lazy')
|
| 170 |
+ ), |
|
| 171 |
+ 'number_ranges' => array |
|
| 172 |
+ ( |
|
| 173 |
+ 'exclude' => true, |
|
| 174 |
+ 'inputType' => 'textarea', |
|
| 175 |
+ 'eval' => array( |
|
| 176 |
+ 'mandatory' => false, |
|
| 177 |
+ 'rows' => 4, |
|
| 178 |
+ 'cols' => 40, |
|
| 179 |
+ 'tl_class' => 'clr' |
|
| 180 |
+ ), |
|
| 181 |
+ 'save_callback' => array( |
|
| 182 |
+ array('tl_vr_wa_standort', 'validateNumberRanges')
|
|
| 183 |
+ ), |
|
| 184 |
+ 'sql' => "text NULL" |
|
| 170 | 185 |
) |
| 171 | 186 |
) |
| 172 | 187 |
); |
| ... | ... |
@@ -14,6 +14,12 @@ $GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_enable'][0] = 'Benachrichtigungen a |
| 14 | 14 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_enable'][1] = 'Ermöglicht das Versenden von Benachrichtigungen beim Veröffentlichen neuer Nachrichten.'; |
| 15 | 15 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification'][0] = 'Benachrichtigung'; |
| 16 | 16 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification'][1] = 'Die zu versendende Benachrichtigung.'; |
| 17 |
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification_slots'][0] = 'Benachrichtigung für Slots'; |
|
| 18 |
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification_slots'][1] = 'Die zu versendende Benachrichtigung für Slot-Änderungen.'; |
|
| 19 |
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification_groups'][0] = 'Mitgliedergruppen'; |
|
| 20 |
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['nc_notification_groups'][1] = 'Die Mitgliedergruppen, die benachrichtigt werden sollen.'; |
|
| 21 |
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['number_ranges'][0] = 'Büttennummern'; |
|
| 22 |
+$GLOBALS['TL_LANG']['tl_vr_wa_standort']['number_ranges'][1] = 'Geben Sie kommagetrennte Nummern oder Nummernbereiche ein (z.B. 0000, 0001, 0010-0020). Es sind nur Zahlen, Bereiche (mit Bindestrich) und Kommas erlaubt.'; |
|
| 17 | 23 |
|
| 18 | 24 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['title_legend'] = 'Standort'; |
| 19 | 25 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['notification_legend'] = 'Benachrichtigung-Einstellungen'; |
| ... | ... |
@@ -21,3 +27,7 @@ $GLOBALS['TL_LANG']['tl_vr_wa_standort']['notification_legend'] = 'Benachrichtig |
| 21 | 27 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['rebsorte'] = 'Rebsorten'; |
| 22 | 28 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['leseart'] = 'Leseart'; |
| 23 | 29 |
$GLOBALS['TL_LANG']['tl_vr_wa_standort']['lage'] = 'Lage'; |
| 30 |
+ |
|
| 31 |
+// Error messages |
|
| 32 |
+$GLOBALS['TL_LANG']['ERR']['invalidNumberRanges'] = 'Bitte geben Sie nur Zahlen, Bereiche (mit Bindestrich) und Kommas ein.'; |
|
| 33 |
+$GLOBALS['TL_LANG']['ERR']['invalidNumberRange'] = 'Ungültiger Bereich: Der Startwert muss kleiner oder gleich dem Endwert sein.'; |
| ... | ... |
@@ -14,6 +14,7 @@ namespace vonRotenberg\WeinanlieferungBundle\EventListener\DataContainer; |
| 14 | 14 |
|
| 15 | 15 |
use Contao\CoreBundle\ServiceAnnotation\Callback; |
| 16 | 16 |
use Contao\DataContainer; |
| 17 |
+use Contao\StringUtil; |
|
| 17 | 18 |
use Doctrine\DBAL\Connection; |
| 18 | 19 |
|
| 19 | 20 |
class WeinanlieferungStandortContainerListener |
| ... | ... |
@@ -67,4 +68,54 @@ class WeinanlieferungStandortContainerListener |
| 67 | 68 |
|
| 68 | 69 |
return $arrOptions; |
| 69 | 70 |
} |
| 71 |
+ |
|
| 72 |
+ /** |
|
| 73 |
+ * @Callback(table="tl_vr_wa_standort", target="fields.number_ranges.save") |
|
| 74 |
+ */ |
|
| 75 |
+ public function onNumberRangesSaveCallback($varValue, DataContainer $dc) |
|
| 76 |
+ {
|
|
| 77 |
+ if (empty($varValue)) {
|
|
| 78 |
+ return ''; |
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ // Remove whitespace |
|
| 82 |
+ $varValue = preg_replace('/\s+/', '', $varValue);
|
|
| 83 |
+ |
|
| 84 |
+ // Check if the input contains only numbers, hyphens, and commas |
|
| 85 |
+ if (!preg_match('/^[0-9,-]+$/', $varValue)) {
|
|
| 86 |
+ throw new \Exception($GLOBALS['TL_LANG']['ERR']['invalidNumberRanges']); |
|
| 87 |
+ } |
|
| 88 |
+ |
|
| 89 |
+ // Validate each part (number or range) |
|
| 90 |
+ $parts = StringUtil::trimsplit(',', $varValue);
|
|
| 91 |
+ $validatedParts = []; |
|
| 92 |
+ |
|
| 93 |
+ foreach ($parts as $part) {
|
|
| 94 |
+ // Check if it's a range (contains a hyphen) |
|
| 95 |
+ if (strpos($part, '-') !== false) {
|
|
| 96 |
+ list($start, $end) = explode('-', $part, 2);
|
|
| 97 |
+ |
|
| 98 |
+ // Ensure both start and end are valid numbers |
|
| 99 |
+ if (!is_numeric($start) || !is_numeric($end)) {
|
|
| 100 |
+ throw new \Exception($GLOBALS['TL_LANG']['ERR']['invalidNumberRanges']); |
|
| 101 |
+ } |
|
| 102 |
+ |
|
| 103 |
+ // Ensure the range is valid (start <= end) |
|
| 104 |
+ if ((int)$start > (int)$end) {
|
|
| 105 |
+ throw new \Exception($GLOBALS['TL_LANG']['ERR']['invalidNumberRange']); |
|
| 106 |
+ } |
|
| 107 |
+ |
|
| 108 |
+ $validatedParts[] = $start . '-' . $end; |
|
| 109 |
+ } else {
|
|
| 110 |
+ // Ensure it's a valid number |
|
| 111 |
+ if (!is_numeric($part)) {
|
|
| 112 |
+ throw new \Exception($GLOBALS['TL_LANG']['ERR']['invalidNumberRanges']); |
|
| 113 |
+ } |
|
| 114 |
+ |
|
| 115 |
+ $validatedParts[] = $part; |
|
| 116 |
+ } |
|
| 117 |
+ } |
|
| 118 |
+ |
|
| 119 |
+ return implode(', ', $validatedParts);
|
|
| 120 |
+ } |
|
| 70 | 121 |
} |