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

@ -20,10 +20,29 @@ class Setting extends Model {
if($setting === false) {
return $default;
} else {
return $setting->value;
if(is_serialized($setting->value)) {
return unserialize($setting->value);
} else {
return $setting->value;
}
}
}
public static function getAll() {
$settingsCollection = self::findMany();
$settings = array();
if(!empty($settingsCollection)) {
foreach($settingsCollection as $setting) {
$value = (is_serialized($setting->value)
? unserialize($setting->value)
: $setting->value
);
$settings[$setting->name] = $value;
}
}
return $settings;
}
public static function createOrUpdate($model) {
$exists = self::where('name', $model['name'])
->find_one();