예제 #1
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]);
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = GuestBook::find()->orderBy('date 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', 'body', $this->body])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
예제 #3
0
 /**
  * Finds the GuestBook model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return GuestBook the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GuestBook::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 /**
  * Lists all GuestBook models.
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new GuestBook();
     if ($model->load(Yii::$app->request->post())) {
         //            $url ='http://freegeoip.net/json/';
         //            $ch = curl_init();
         //            // Disable SSL verification
         //            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         //            // Will return the response, if false it print the response
         //            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         //            // Set the url
         //            curl_setopt($ch, CURLOPT_URL,$url);
         //            // Execute
         //            $result=curl_exec($ch);
         //            // Closing
         //            curl_close($ch);
         //            // Will dump a beauty json :3
         //            $ipDetails = json_decode($result, true);
         //            $ipDetails = $_SERVER["REMOTE_ADDR"];
         //            if (!is_null($ipDetails)) {
         //                $model->ip = $ipDetails['ip'];
         //            } else {
         //                $model->ip = 'NULL';
         //            }
         $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]);
         }
         //            $query->one();
         $blacklistedCheck = $query->one();
         if (is_null($blacklistedCheck)) {
             //            $blacklistedCheck = BlackList::find()
             //                ->where(['email'=>$model->email])
             //                ->orWhere(['ip'=>$model->ip])
             //                ->orWhere(['user_id'=>$model->ip])
             //                ->one();
             $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 GuestBook();
                 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' => GuestBook::find()->where(['status' => 'on'])->orderBy('date DESC'), 'pagination' => ['pageSize' => 20]]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]);
 }