예제 #1
0
파일: Option.php 프로젝트: Penton/MoBlog
 /**
  * 获取网站配置数组
  * @return array
  */
 public static function getOptions()
 {
     if (self::$_options == null) {
         $options = \common\models\Option::find()->asArray()->all();
         self::$_options = yii\helpers\ArrayHelper::map($options, 'name', 'value');
     }
     return self::$_options;
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = OptionModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'group', $this->group]);
     return $dataProvider;
 }
예제 #3
0
파일: Option.php 프로젝트: tampaphp/app-cms
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = OptionModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'option_name', $this->option_name])->andFilterWhere(['like', 'option_value', $this->option_value])->andFilterWhere(['like', 'option_label', $this->option_label])->andFilterWhere(['like', 'option_group', $this->option_group]);
     return $dataProvider;
 }
예제 #4
0
 /**
  * @param null $template_id
  * @return array
  */
 public static function getAll($template_id = null)
 {
     $options = [];
     if ($template_id) {
         $model = Option::find()->where(['template_id' => $template_id])->all();
     } else {
         $model = Option::find()->all();
     }
     if ($model) {
         foreach ($model as $m) {
             $options[$m->id] = $m->name;
         }
     }
     return $options;
 }
예제 #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $this->scenario = 'search';
     $query = Option::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'template_id' => $this->template_id, 'multiple' => $this->multiple, 'require' => $this->require, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
예제 #6
0
 /**
  * @return array|\yii\db\ActiveRecord[]
  */
 public function getOptions()
 {
     $options = Option::find()->where(['template_id' => $this->template_id])->orderBy('id')->all();
     return $options;
 }
예제 #7
0
 /**
  * Finds the Option models based on their group.
  * If the models are not found, a 404 HTTP exception will be thrown.
  *
  * @param string $id
  *
  * @return Option the loaded model
  * @throws NotFoundHttpException if the models cannot be found
  */
 protected function findModelByGroup($id)
 {
     if ($model = Option::find()->where(['option_group' => $id])->indexBy('option_name')->all()) {
         return $model;
     }
     throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
 }
예제 #8
0
 /**
  * Render option page for specific group of option.
  * It will use group file if exist.
  *
  * @param string $id group name
  *
  * @return string|\yii\web\Response
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionGroup($id)
 {
     $model = Option::find()->where(['option_group' => $id])->indexBy('option_name')->all();
     if ($options = Yii::$app->request->post('Option')) {
         foreach ($options as $option_name => $option) {
             Option::up($option_name, $option['option_value']);
         }
         Yii::$app->getSession()->setFlash('success', Yii::t('writesdown', 'Settings successfully saved.'));
         return $this->redirect(['group', 'id' => $id]);
     }
     if ($model) {
         if (is_file($viewFile = $this->getViewPath() . '/' . strtolower($id) . '.php')) {
             return $this->render(strtolower($id), ['model' => (object) $model, 'group' => $id]);
         } else {
             return $this->redirect(['index']);
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }