/** * Get groups array */ public function getGroups() { $groups = SettingCat::model()->byTitle()->findAll(); $_temp = array(); if (count($groups)) { foreach ($groups as $value) { $_temp[$value->id] = $value->title; } } return $_temp; }
/** * Edit setting action */ public function actioneditsetting() { // Check Access checkAccessThrowException('op_settings_edit_settings'); if (isset($_GET['id']) && ($setting = Setting::model()->findByPk($_GET['id']))) { $category = SettingCat::model()->findByPk($setting->category); if ($category) { $setting->category = $category->id; $this->title[] = at('Viewing Category "{name}"', array('{name}' => $category->title)); } // Make sure the setting is not protected as we can't edit protected settings if (!YII_DEBUG && $setting->is_protected) { // Log Message alog(at("Tried Editing Protected Setting '{name}'", array('{name}' => $setting->title))); ferror(at("Can't edit that setting as it's a protected setting.")); $this->redirect(getReferrer('setting/index')); } if (isset($_POST['Setting'])) { $setting->attributes = $_POST['Setting']; // Evaluate php code if ($setting->php) { $show = 0; $store = 0; $save = 1; eval($setting->php); } if ($setting->save()) { // Clear cache Yii::app()->settings->clearCache(); fok(at('Setting edited.')); // Log Message alog(at("Updated Setting '{name}'", array('{name}' => $setting->title))); $this->redirect(array('setting/viewgroup', 'id' => $setting->category)); } } // Add Breadcrumb $this->addBreadCrumb(at('Updating Setting')); $this->title[] = at('Updating Setting'); // Display form $this->render('setting_form', array('model' => $setting, 'label' => at('Editing Setting'))); } else { ferror(at('Could not find that ID.')); $this->redirect(array('setting/index')); } }
/** * Add the missing settings if we found one * */ protected function addMissingSetting($key, $default = null) { // Ignore if key is protected if (in_array($key, $this->protectedSettings)) { return; } // First make sure we haven't already added it // without looking in the db $missingSettings = Yii::app()->cache->get('missingSettings'); if ($missingSettings === false) { // Init $missingSettings = array(); } // Do we have that setting in the array if (!in_array($key, $missingSettings)) { // We don't so look up the db $settingExists = Setting::model()->find('settingkey=:key', array(':key' => $key)); if (!$settingExists) { // We didn't find anything so add it // Do we have the missing setting cat? $missingCat = SettingCat::model()->find('groupkey=:key', array(':key' => 'missing_settings')); if (!$missingCat) { $missingCat = new SettingCat(); $missingCat->title = 'Missing Settings'; $missingCat->description = 'Settings that were accessed but were not found in the db'; $missingCat->groupkey = 'missing_settings'; if (!$missingCat->save()) { alog('Could not create the missing setting category.'); } } // Add the new setting $newSetting = new Setting(); $newSetting->title = ucwords(str_replace('_', ' ', $key)); $newSetting->settingkey = $key; $newSetting->category = $missingCat->id; $newSetting->type = 'text'; $newSetting->default_value = $default ? $default : '0'; if (!$newSetting->save()) { alog(sprintf("Could not create a setting with the key '%s'", $key)); } } $missingSettigns[$key] = $key; // Save Yii::app()->cache->set('missing_settings', $missingSettigns); } $this->clearCache(); }