From e0ae1cd645d37a7775c8c30e1c3fefbced816819 Mon Sep 17 00:00:00 2001 From: Beppe Date: Thu, 20 Oct 2022 11:57:29 +0200 Subject: [PATCH] Gestione setting multipli da query di estrazione --- src/Settings.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Settings.php b/src/Settings.php index b4fa996e3..7a27eb09f 100755 --- a/src/Settings.php +++ b/src/Settings.php @@ -176,18 +176,26 @@ class Settings // Lista multipla elseif (preg_match("/multiple\[(.+?)\]/", $setting->tipo, $m)) { - $values = explode(',', $m[1]); - $list = []; - foreach ($values as $value) { - $list[] = [ - 'id' => $value, - 'text' => $value, - ]; + //Gestisco il multiple da query + if (strstr($setting->tipo,'query=')) { + $value = str_replace(']', '', explode('[', $setting->tipo)[1]); + $select_values = '"'.str_replace('"', '\"', $value).'"'; + }else{ + $values = explode(',', $m[1]); + + $list = []; + foreach ($values as $value) { + $list[] = [ + 'id' => $value, + 'text' => $value, + ]; + } + $select_values = json_encode($list); } $result = ' - {[ "type": "select", "multiple": 1, "label": '.json_encode($setting->nome).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.'][]", "values": '.json_encode($list).', "value": "'.$setting->valore.'", "required": "'.intval($required).'", "help": "'.$setting->help.'" ]}'; + {[ "type": "select", "multiple": 1, "label": '.json_encode($setting->nome).', "readonly": "'.!$setting->editable.'", "name": "setting['.$setting->id.'][]", "values": '.$select_values.', "value": "'.$setting->valore.'", "required": "'.intval($required).'", "help": "'.$setting->help.'" ]}'; } // Lista da query