コード例 #1
0
 /**
  * Lists all ClubQuestionsSearch models.
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new ClubQuestions();
     $data['mainTeam'] = Teams::find()->where(['name' => Yii::$app->params['main-team']])->with('players')->with('coachingStaff')->one();
     if ($model->load(Yii::$app->request->post())) {
         //            var_dump($model);die;
         $ip = $_SERVER['REMOTE_ADDR'];
         if (isset($ip)) {
             $model->ip = $ip;
         } else {
             $model->ip = 'NULL';
         }
         //            $query = BlackList::find()->where(['email'=>$model->email])->orWhere(['ip'=>$model->ip]);
         //            if (!Yii::$app->user->isGuest) {
         //                $query->orWhere(['user_id'=>$model->ip]);
         //            }
         //            $blacklistedCheck = $query->one();
         //            if (is_null($blacklistedCheck)) {
         $model->date = time();
         $model->status = 'on';
         if (Yii::$app->user->isGuest) {
             $model->user_id = 0;
         } else {
             $model->user_id = Yii::$app->user->identity->id;
             $userDetails = User::findOne($model->user_id);
             $model->name = $userDetails['username'];
             $model->email = $userDetails['email'];
         }
         if ($model->save()) {
             //                    $model = new ClubQuestions();
             return Alert::widget(['options' => ['class' => 'alert-success'], 'body' => '<b>Успешно!</b> Ваша запись опубликованна.']);
         } else {
             var_dump($model->errors);
             exit;
         }
         //            } else {
         //                return Alert::widget([
         //                    'options' => [
         //                        'class' => 'alert-danger'
         //                    ],
         //                    'body' => '<b>Ошибка!</b> Вы в чёрном списке.'
         //                ]);
         //            }
     }
     $dataProvider = new ActiveDataProvider(['query' => ClubQuestions::find()->where(['status' => 'on'])->orderBy('date DESC'), 'pagination' => ['pageSize' => 20]]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model, 'data' => $data]);
 }
コード例 #2
0
 public function actionIndex()
 {
     $dataProvider = [];
     $dataProvider['guest-book'] = new ActiveDataProvider(['query' => GuestBook::find()->where(['status' => 'on'])->orderBy('date DESC')->limit(10), 'pagination' => false]);
     $dataProvider['club-questions'] = new ActiveDataProvider(['query' => ClubQuestions::find()->where(['status' => 'on'])->orderBy('date DESC')->limit(10), 'pagination' => false]);
     $dataProvider['news'] = new ActiveDataProvider(['query' => News::find()->orderBy('date_create DESC, date DESC')->limit(5), 'pagination' => false]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
コード例 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ClubQuestions::find()->orderBy('id DESC');
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'question', $this->question])->andFilterWhere(['like', 'answer', $this->answer])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
コード例 #4
0
 /**
  * Finds the ClubQuestions model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ClubQuestions the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ClubQuestions::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }