store arrays in config, edit in setup with add_multichoice_option
This commit is contained in:
parent
84e4420332
commit
d9b97996ca
@ -8,14 +8,17 @@ interface Config {
|
||||
public function set_int($name, $value);
|
||||
public function set_string($name, $value);
|
||||
public function set_bool($name, $value);
|
||||
public function set_array($name, $value);
|
||||
|
||||
public function set_default_int($name, $value);
|
||||
public function set_default_string($name, $value);
|
||||
public function set_default_bool($name, $value);
|
||||
public function set_default_array($name, $value);
|
||||
|
||||
public function get_int($name, $default=null);
|
||||
public function get_string($name, $default=null);
|
||||
public function get_bool($name, $default=null);
|
||||
public function get_array($name, $default=array());
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +41,11 @@ abstract class BaseConfig implements Config {
|
||||
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N');
|
||||
$this->save($name);
|
||||
}
|
||||
public function set_array($name, $value) {
|
||||
assert(is_array($value));
|
||||
$this->values[$name] = implode(",", $value);
|
||||
$this->save($name);
|
||||
}
|
||||
|
||||
public function set_default_int($name, $value) {
|
||||
if(is_null($this->get($name))) {
|
||||
@ -54,6 +62,12 @@ abstract class BaseConfig implements Config {
|
||||
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N');
|
||||
}
|
||||
}
|
||||
public function set_default_array($name, $value) {
|
||||
assert(is_array($value));
|
||||
if(is_null($this->get($name))) {
|
||||
$this->values[$name] = implode(",", $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_int($name, $default=null) {
|
||||
return (int)($this->get($name, $default));
|
||||
@ -64,6 +78,9 @@ abstract class BaseConfig implements Config {
|
||||
public function get_bool($name, $default=null) {
|
||||
return ($this->get($name, $default) == 'Y');
|
||||
}
|
||||
public function get_array($name, $default=array()) {
|
||||
return explode(",", $this->get($name, ""));
|
||||
}
|
||||
|
||||
private function get($name, $default=null) {
|
||||
if(isset($this->values[$name])) {
|
||||
|
@ -132,6 +132,26 @@ class SetupBlock extends Block {
|
||||
|
||||
$this->body .= $html;
|
||||
}
|
||||
|
||||
public function add_multichoice_option($name, $options, $label=null) {
|
||||
global $config;
|
||||
$current = $config->get_array($name);
|
||||
|
||||
if(!is_null($label)) {
|
||||
$this->body .= "<label for='$name'>$label</label>";
|
||||
}
|
||||
$html = "<select id='$name' name='_config_{$name}[]' multiple size='5'>";
|
||||
foreach($options as $optname => $optval) {
|
||||
if(in_array($optval, $current)) $selected=" selected";
|
||||
else $selected="";
|
||||
$html .= "<option value='$optval'$selected>$optname</option>\n";
|
||||
}
|
||||
$html .= "</select>";
|
||||
$this->body .= "<input type='hidden' name='_type_$name' value='array'>\n";
|
||||
$this->body .= "<!--<br><br><br><br>-->\n"; // setup page auto-layout counts <br> tags
|
||||
|
||||
$this->body .= $html;
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
@ -225,6 +245,7 @@ class Setup extends SimpleExtension {
|
||||
$sb->add_text_option("main_page", "<br>Main page: ");
|
||||
$sb->add_text_option("contact_link", "<br>Contact URL: ");
|
||||
$sb->add_choice_option("theme", $themes, "<br>Theme: ");
|
||||
//$sb->add_multichoice_option("testarray", array("a" => "b", "c" => "d"), "<br>Test Array: ");
|
||||
$sb->add_bool_option("nice_urls", "<br>Nice URLs: ");
|
||||
$sb->add_label("<span id='nicetest'>(Javascript inactive, can't test!)</span>$nicescript");
|
||||
$event->panel->add_block($sb);
|
||||
@ -241,6 +262,7 @@ class Setup extends SimpleExtension {
|
||||
case "string": $config->set_string($name, $value); break;
|
||||
case "int": $config->set_int($name, $value); break;
|
||||
case "bool": $config->set_bool($name, $value); break;
|
||||
case "array": $config->set_array($name, $value); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user