public static function requireUpdateModuleSettings($module = P) { $settings = new CustomSettingRepository(); $settings->setWhereModule(P); $to_unset = $settings->getPairs('key'); // Update (create) settings foreach ($_POST as $k => $v) { // Check existing /** @var CustomSetting $setting */ $setting = CustomSettingRepository::findOneEntityByCriteria(['module' => $module, 'key' => $k]); if (!$setting) { $setting = new CustomSetting(); $setting->setModule($module); $setting->setKey($k); } // Set 1 for checkboxes if ($setting->getInputType() == 'checkbox' && !$v) { $v = 1; } $setting->setValue($v); $setting->save(); unset($to_unset[$setting->getId()]); } // Set 0 for unset checkboxes foreach ($to_unset as $unset_id => $unset_key) { $setting = new CustomSetting($unset_id); $setting->setValue(0); $setting->save(); } if (IS_AJAX_REQUEST) { die('1'); } back(); }
public function _setting_options_edit() { $id = abs((int) $_GET['id']); if (!$id) { return; } $option = new CustomSettingOption($id); $option->loadDataFromArray($_POST); $option->save(); $setting = new CustomSetting($option->getSettingId()); App::add('Custom Setting Option "' . $option->getOptionName() . '" edited'); Messages::sendMessage('Setting Option updated'); go('?p=' . P . '&do=setting_options&id=' . $setting->getId() . '&highlight=' . $id); }