/** * Add setting group action */ public function actionaddgroup() { // Check Access checkAccessThrowException('op_settings_add_settings_groups'); $model = new SettingCat(); if (isset($_POST['SettingCat'])) { $model->attributes = $_POST['SettingCat']; if ($model->save()) { fok(at('Setting group added.')); // Log Message alog(at("Added New setting group '{name}'", array('{name}' => $model->title))); $this->redirect(array('setting/index')); } } // Add Breadcrumb $this->addBreadCrumb(at('Adding Setting Group')); $this->title[] = at('Adding Setting Group'); // Display form $this->render('group_form', array('model' => $model, 'label' => at('Adding Setting Group'))); }
/** * 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(); }