Exemplo n.º 1
0
 public function actionSave()
 {
     if (User::isAdmin(Yii::$app->user->identity->username)) {
         $model = new Answers();
         if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
             if ($model->save()) {
                 return $this->redirect('/answers/view');
             }
         }
         return $this->render('save', compact('model'));
     } else {
         throw new ForbiddenHttpException('У вас нет прав администратора!', 404);
     }
 }
Exemplo n.º 2
0
 /**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = Answers::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, 'answer_num' => $this->answer_num, 'question' => $this->question, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'answer', $this->answer]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Answers::find();
     // 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, 'questions_id' => $this->questions_id, 'how_many' => $this->how_many]);
     $query->andFilterWhere(['like', 'answer', $this->answer]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 /**
  * Finds the Answers model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Answers the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Answers::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 5
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $data['questions'] = Questions::find()->where(['status' => 'on'])->orderBy('id DESC')->one();
     $data['answerPoll'] = AnswersPoll::find()->where(['quest_id' => $data['questions']->id, 'ip' => $_SERVER['REMOTE_ADDR']])->one();
     if (!empty($_POST)) {
         $model = new AnswersPoll();
         $dataPost = Yii::$app->request->post();
         $model->quest_id = $dataPost['question_id'];
         $model->answer_id = $dataPost['answer_id'];
         $model->ip = $_SERVER['REMOTE_ADDR'];
         $check = AnswersPoll::find()->where(['quest_id' => $model->quest_id, 'ip' => $model->ip])->one();
         $model->date = time();
         $alertMessage = '';
         if ($model->save() && is_null($check)) {
             $modelAnswer = Answers::findOne($dataPost['answer_id']);
             $modelAnswer->how_many = $modelAnswer->how_many + 1;
             $modelAnswer->save();
             $data['answerPoll'] = AnswersPoll::find()->where(['quest_id' => $data['questions']->id, 'ip' => $_SERVER['REMOTE_ADDR']])->one();
         } else {
             $alertMessage = Alert::widget(['options' => ['class' => 'alert-danger'], 'body' => '<b>Ошибка!</b> Ответ не был записан.']);
         }
         return $this->render('_poll', ['answersData' => $data['questions']->answers, 'questions' => $data['questions'], 'answerPoll' => $data['answerPoll'], 'alertMessage' => $alertMessage]);
     }
     $dataProvider['news'] = new ActiveDataProvider(['query' => News::find()->where(['status_id' => 'on'])->orderBy('date_create DESC, id DESC')->limit(10), 'pagination' => ['pageSize' => 11]]);
     $data['mainTeam'] = Teams::find()->where(['name' => Yii::$app->params['main-team']])->one();
     //        $CId = [2];
     $CId = [3];
     $allCoaches = CoachingStaff::find()->where(['teams_id' => $data['mainTeam']->id])->andWhere(['in', 'id', $CId])->all();
     $PlId = [28, 4, 20, 17];
     $allPlayers = Players::find()->where(['teams_id' => $data['mainTeam']->id])->andWhere(['in', 'id', $PlId])->all();
     $data['allPlayers'] = [];
     foreach ($allPlayers as $item) {
         //            $allPlayers[$item->id] = $item;
         if ($item->id == 28) {
             $data['allPlayers'][1] = $item;
         }
         if ($item->id == 4) {
             $data['allPlayers'][2] = $item;
         }
         if ($item->id == 20) {
             $data['allPlayers'][3] = $item;
         }
         if ($item->id == 17) {
             $data['allPlayers'][4] = $item;
         }
     }
     foreach ($allCoaches as $item) {
         $data['allCoaches'][0] = $item;
     }
     ksort($data['allPlayers']);
     //        ksort($data['allCoaches']);
     //        $data['allPlayers'] = ksort($data['allPlayers']);
     //        var_dump($data['allPlayers']);
     //        var_dump(krsort($data['allPlayers']));
     //        $data['allPlayers'][0] = $allPlayers[2];
     //        var_dump($allPlayers);
     //        die;
     //        $data['allPlayers'][1] = $allPlayers[28];
     //        $data['allPlayers'][2] = $allPlayers[4];
     //        $data['allPlayers'][3] = $allPlayers[20];
     //        $data['allPlayers'][4] = $allPlayers[17];
     //        CaseMaster::find()->where(["DATE_FORMAT( FROM_UNIXTIME( i_date ),'%d-%m-%Y' )"=>date('d-m-Y')])->all();
     //        DATE_FORMAT("2008-11-19",'%d.%m.%Y');
     //        $sorted_articles=[];
     //        foreach($articles as $article){
     //            $dt=date('d.m.Y',$article->sort_date);
     //            $sorted_articles[$dt][]=$article;
     //        }
     //        $data['allPlayers'] = [];
     //        foreach($data['allPlayers'] as $item) {
     //            var_dump(date('d.m.Y', $item->date));
     ////            var_dump($item['date_new']);
     ////            $item['new_date'] = $item->date;
     ////            $item->date = date('d.m', $item->date);
     ////            $dt = date('d.m', $item->date);
     //            $data['allPlayers'][] = $item;
     //        }
     //        var_dump($data['allPlayers']);
     $data['seasonDetails'] = $data['mainTeam']->lastSeasonDetails;
     $data['season'] = $data['seasonDetails']->season;
     $dataProvider['standings'] = new ActiveDataProvider(['query' => SeasonDetails::find()->where(['season_id' => $data['season']->id])->orderBy('spectacles DESC')->limit(20), 'pagination' => false]);
     $data['gameLast'] = Games::find()->where(['home_id' => $data['mainTeam']->id])->orWhere(['guest_id' => $data['mainTeam']->id])->orderBy('date')->one();
     $data['gameFirst'] = Games::find()->where(['home_id' => $data['mainTeam']->id])->orWhere(['guest_id' => $data['mainTeam']->id])->orderBy('date DESC')->one();
     $data['gamesLast'] = Games::find()->where(['home_id' => $data['mainTeam']->id])->orWhere(['guest_id' => $data['mainTeam']->id])->andWhere(['<', 'date', time()])->orderBy('date DESC')->limit(3)->all();
     $data['gamesFirst'] = Games::find()->where(['home_id' => $data['mainTeam']->id])->orWhere(['guest_id' => $data['mainTeam']->id])->andWhere(['>', 'date', time()])->orderBy('date')->limit(3)->all();
     $model = new AnswersPoll();
     return $this->render('index', ['dataProvider' => $dataProvider, 'data' => $data, 'model' => $model]);
 }
Exemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAnswer()
 {
     return $this->hasOne(Answers::className(), ['id' => 'answer_id']);
 }
Exemplo n.º 7
0
 /**
  * Displays a single Results model.
  * @param integer $id
  *
  * @return mixed
  */
 public function actionResults($id)
 {
     if ($id === '4') {
         return $this->redirect(['more']);
     }
     $resultsPage = $this->findResultsPageModel($id);
     $resultsFrom = $resultsPage->getResultFroms()->all();
     $results = $resultsPage->getResults()->all();
     // Get all the Answer IDs from which we can retrieve results
     $answerIds = [];
     foreach ($resultsFrom as $fromPart) {
         $questions = $fromPart->getPart0()->one()->getQuestions()->all();
         foreach ($questions as $question) {
             $answers = $question->getAnswers()->all();
             foreach ($answers as $answer) {
                 $answerIds[] = $answer->id;
             }
         }
     }
     // Get all the answers provided by the user for this result
     $answersUsers = AnswersUsers::find()->where(['answer' => $answerIds, 'created_by' => Yii::$app->getUser()->id])->select('answer')->all();
     // Provide the mostly A's, B's etc. or just the selected answer
     switch ($id) {
         case 1:
             $options = [0, 0, 0, 0];
             foreach ($answersUsers as $answerUser) {
                 switch (Answers::findOne($answerUser->answer)->answer_num) {
                     case 1:
                         $options[0]++;
                         break;
                     case 2:
                         $options[1]++;
                         break;
                     case 3:
                         $options[2]++;
                         break;
                     case 4:
                         $options[3]++;
                         break;
                 }
             }
             $selected = array_search(max($options), $options, null);
             break;
             // Get the first answer of the 3rd Part !!HARDCODED!! (bad)
         // Get the first answer of the 3rd Part !!HARDCODED!! (bad)
         case 2:
             $selected = Answers::findOne($answersUsers[0]->answer)->answer_num;
             break;
             // Get the second answer of the 3rd Part !!HARDCODED!! (bad)
         // Get the second answer of the 3rd Part !!HARDCODED!! (bad)
         case 3:
             $selectedName = Answers::findOne($answersUsers[1]->answer)->answer;
             foreach ($results as $key => $result) {
                 if ($result->name === $selectedName) {
                     $selected = $key;
                 }
             }
             break;
     }
     return $this->render('results' . $id, ['resultsPage' => $resultsPage, 'resultsFrom' => $resultsFrom, 'results' => $results, 'selected' => $selected, 'id' => $id]);
 }
Exemplo n.º 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAnswers()
 {
     return $this->hasMany(Answers::className(), ['question' => 'id']);
 }
Exemplo n.º 9
0
 /**
  * Вывод новостей
  * @return string
  */
 public function actionIndex()
 {
     $news = Answers::find()->all();
     return $this->render('index', compact('news'));
 }