diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php new file mode 100644 index 000000000..12c2a5365 --- /dev/null +++ b/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php @@ -0,0 +1,116 @@ +separatorchar, $this->__toString()); + + foreach ($this->selectOptions as $optKey => $optValue) { + $result[$optKey] = array("value"=>$optValue, "selected"=>0); + } + + foreach ($selectlist as $optKey) { + if (strlen($optKey) > 0) { + if (array_key_exists($optKey, $result)) { + $result[$optKey]["selected"] = 1; + } else { + $result[$optKey] = array("value"=>$optKey, "selected" => 1); + } + } + } + + return $result; + } + + /** + * set all options for this select item. + * push a key/value array type to set all options or deliver a comma separated list with keys and optional values + * divided by a pipe | sign. + * example : optionA|text for option A, optionB|test for option B + * @param array|string $list key/value option list + */ + public function setSelectOptions($list) + { + if (is_array($list)) { + foreach ($list as $optKey => $optValue) { + $this->selectOptions[$optKey] = $optValue; + } + } else { + // string list + foreach (explode($this->separatorchar, $list) as $option) { + if (strpos($option, "|") !== false) { + $tmp = explode("|", $option); + $this->selectOptions[$tmp[0]] = $tmp[1]; + } else { + $this->selectOptions[$option] = $option; + } + } + } + } + + /** + * @return array returns validators + */ + public function getValidators() + { + return array() ; + } +}