/** * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Config::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['ID' => $this->ID]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** @inheritdoc */ public function bootstrap($app) { /** @var $module Module */ if ($app->hasModule('configmanager') && ($module = $app->getModule('configmanager')) instanceof Module) { $this->_modelMap = array_merge($this->_modelMap, $module->modelMap); foreach ($this->_modelMap as $name => $definition) { $class = "chd7well\\configmanager\\models\\" . $name; \Yii::$container->set($class, $definition); $modelName = is_array($definition) ? $definition['class'] : $definition; $module->modelMap[$name] = $modelName; if (in_array($name, ['Configmanager'])) { \Yii::$container->set($name . 'Query', function () use($modelName) { return $modelName::find(); }); } } } $app->get('i18n')->translations['configmanager*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages']; //Load parameters from database $parameters = Parameter::find()->where(['bootstrap' => '1'])->all(); //only on bootstrap are necessary foreach ($parameters as $para) { $this->setParameter($app, $para->parametername, $para->value); } $is_config_set = Parameter::findOne(['parametername' => 'chd7well/configmanager/config_set']); $is_user_config_set = Parameter::findOne(['parametername' => 'chd7well/configmanager/user_parameter']); if (get_class(\Yii::$app) === 'yii\\web\\Application') { if (isset($app->params['chd7well/configmanager/config_set']) && isset($app->params['chd7well/configmanager/user_parameter']) && $app->params['chd7well/configmanager/config_set'] == 1 && $app->params['chd7well/configmanager/user_parameter'] == 1 && isset(\Yii::$app->user->id)) { $configuser = ConfigUser::findOne(['user_ID' => \Yii::$app->user->id]); if (isset($configuser)) { $config = Config::findOne(['ID' => $configuser->config_ID]); $parent_parameters = ConfigParameter::find()->where(['config_ID' => $config->parent_ID])->all(); $user_parameters = ConfigParameter::find()->where(['config_ID' => $config->ID])->all(); foreach ($parent_parameters as $para) { $this->setParameter($app, $para->parameter->parametername, $para->value); } foreach ($user_parameters as $para) { $this->setParameter($app, $para->parameter->parametername, $para->value); } } } } }
/** * Finds the Parameter model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Config the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Config::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getConfig() { return $this->hasOne(Config::className(), ['ID' => 'config_ID']); }
/** * @return \yii\db\ActiveQuery */ public function getConfigs() { return $this->hasMany(Config::className(), ['parent_ID' => 'ID']); }
<?php use yii\helpers\ArrayHelper; use chd7well\configmanager\models\Config; /* * This file is part of the chd7well project. * * (c)2015 chd7well project <http://github.com/chd7well> * * For the full copyright and license information, please view the LICENSE.md * file that was distributed with this source code. */ /** * @var yii\widgets\ActiveForm $form * @var chd7well\user\models\Config $config */ ?> <?php echo $form->field($config, 'config_ID')->dropDownList(ArrayHelper::map(Config::find()->all(), 'ID', 'title'), ['prompt' => '---Select---']); ?>