Load/Save settings

- renamed all settings with dot syntax
- refactored Menu->settings()
- changed schema of settings table to allow longer setting name and value
- added getAll() static method on Setting Model to fetch all settings (with proper unserialize of value)
This commit is contained in:
Jonathan Labreuille
2015-10-15 14:22:27 +02:00
parent c8c3f09fb2
commit 34c237ce8e
14 changed files with 282 additions and 244 deletions

View File

@ -9,20 +9,24 @@ class Settings {
}
function get() {
$settings = Setting::find_array();
$settings = Setting::getAll();
wp_send_json($settings);
}
function set($args) {
$save = function($setting) {
Setting::createOrUpdate($setting);
};
$results = array_map($save, $args);
wp_send_json(in_array(false, $results));
}
function save($data = array()) {
// TODO
function set($settings = array()) {
if(empty($settings)) {
wp_send_json(false);
} else {
foreach($settings as $name => $value) {
if(is_array($value)) {
$value = serialize($value);
}
Setting::createOrUpdate(array(
'name' => $name,
'value' => $value
));
}
wp_send_json(true);
}
}
}