/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MatchEvent::find();
     $match = new Match();
     $matchEventTable = MatchEvent::tableName();
     $matchTable = Match::tableName();
     $query->joinWith(['match' => function ($query) use($matchTable) {
         $query->from(['match' => $matchTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 100]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$matchEventTable}.id" => $this->id, 'match_id' => $this->match_id, 'match_event_type_id' => $this->match_event_type_id, 'composition_id' => $this->composition_id, 'minute' => $this->minute, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'substitution_id' => $this->substitution_id, 'additional_minute' => $this->additional_minute, 'is_hidden' => $this->is_hidden, 'position' => $this->position]);
     $query->andFilterWhere(['like', "notes", $this->notes]);
     return $dataProvider;
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMatchEvents()
 {
     return $this->hasMany(MatchEvent::className(), ['match_id' => 'id']);
 }
 /**
  * Finds the MatchEvent model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MatchEvent the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MatchEvent::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Vote for selected float answer
  * @param $matchID int
  * @return mixed Json
  */
 public function actionAutogen($matchID)
 {
     $match = \common\models\Match::findOne($matchID);
     if (!isset($match)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     if (in_array($match->teamHome->id, \common\models\Team::getTeamsConstants())) {
         $ourTeam = $match->teamHome;
         $opponentTeam = $match->teamGuest;
     } else {
         $ourTeam = $match->teamGuest;
         $opponentTeam = $match->teamHome;
     }
     $basisPlayers = \common\models\Composition::find()->where(['match_id' => $match->id, 'command_id' => $ourTeam->id, 'is_basis' => 1])->all();
     $compositionTable = \common\models\Composition::tableName();
     $matchEventTable = \common\models\MatchEvent::tableName();
     $substitutionPlayers = \common\models\Composition::find()->innerJoin($matchEventTable, "{$matchEventTable}.substitution_id = {$compositionTable}.id")->where([$compositionTable . '.match_id' => $match->id, 'command_id' => $ourTeam->id])->all();
     $teamPlayers = array_merge($basisPlayers, $substitutionPlayers);
     $question = new Question();
     $question->title = 'Оценки игрокам ' . $ourTeam->name . ' в матче с ' . $opponentTeam->name;
     $question->voutes = 0;
     $question->is_active = 1;
     $question->is_float = 1;
     $question->is_multipart = 0;
     $question->mark = 0;
     if ($question->save()) {
         foreach ($teamPlayers as $teamPlayer) {
             $answer = new Question();
             $answer->parent_id = $question->id;
             $answer->title = $teamPlayer->name;
             $answer->mark = 0;
             $answer->save();
         }
     }
     return $this->redirect(['view', 'id' => $question->id]);
 }
 /**
  * Updates statistics of an existing Match model.
  * @param integer $id
  * @return mixed
  */
 public function actionEvents($id)
 {
     $model = $this->findModel($id);
     $matchEventModel = new MatchEvent();
     $matchEventModel->match_id = $model->id;
     $matchEventModelSearch = new MatchEventSearch();
     $params = ['MatchEventSearch' => ['match_id' => $model->id]];
     $matchEventDataProvider = $matchEventModelSearch->search($params);
     //        $totalCount = $matchEventDataProvider->getTotalCount();
     //        $matchEventDataProvider->pagination = ['defaultPageSize' => 60];
     $matchEventDataProvider->setSort(['defaultOrder' => ['minute' => SORT_DESC, 'additional_minute' => SORT_DESC]]);
     $matchEvents = MatchEventType::find()->all();
     $eventFilter = ArrayHelper::map($matchEvents, 'id', 'name');
     $searchModel = new CompositionSearch();
     // homeCompositionDataProvider
     $params = ['CompositionSearch' => ['match_id' => $model->id, 'command_id' => $model->command_home_id]];
     $homeCompositionDataProvider = $searchModel->search($params);
     $homeCompositionDataProvider->setSort(['defaultOrder' => ['is_basis' => SORT_DESC, 'number' => SORT_ASC]]);
     // guestCompositionDataProvider
     $params = ['CompositionSearch' => ['match_id' => $model->id, 'command_id' => $model->command_guest_id]];
     $guestCompositionDataProvider = $searchModel->search($params);
     $guestCompositionDataProvider->setSort(['defaultOrder' => ['is_basis' => SORT_DESC, 'number' => SORT_ASC]]);
     if ($matchEventModel->load(Yii::$app->request->post()) && $matchEventModel->validate()) {
         $matchEventModel->save(false);
         $this->redirect(['match/events', 'id' => $model->id]);
     }
     return $this->render('match_events', compact('model', 'matchEventModel', 'matchEventModelSearch', 'matchEventDataProvider', 'eventFilter', 'homeCompositionDataProvider', 'guestCompositionDataProvider'));
 }
 /**
  * Url: /match/rss.xml
  * Rss output of last match events
  * @return mixed 
  */
 public function actionEventsRss()
 {
     Yii::$app->response->format = Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     $headers->add('Content-Type', 'text/xml; charset=utf-8');
     $matches = Match::find()->innerJoinWith('matchEvents')->orderBy(['date' => SORT_DESC])->groupBy(Match::tableName() . '.id')->limit(10)->all();
     $translations = [];
     $yandexSportAPI = file_get_contents("http://api.sport.yandex.ru/public/events.xml");
     foreach ($matches as $match) {
         $events = MatchEvent::find()->where(['not', ['is_hidden' => 1]])->andWhere(['match_id' => $match->id])->orderBy(['created_at' => SORT_DESC])->all();
         // yandexTeamId Dynamo 78662
         // competition_id Y 1999 D 2 Ukrainian Premier League
         // competition_id = 2004 D 12 UPL Supercup 2015
         // competition_id = 1998 D 5 UEFA Champions League
         // competition_id = 000000021099 D 20 European Championship Qualification
         if ($match->championship_id == 2) {
             $competition = 1999;
         } elseif ($match->championship_id == 12) {
             $competition = 2004;
         } elseif ($match->championship_id == 5) {
             $competition = 1998;
         } elseif ($match->championship_id == 20) {
             $competition = '000000021099';
         } else {
             $competition = 0;
         }
         if (!$competition) {
             continue;
         }
         $matches = [];
         $matchDate = date('Y-m-d', strtotime($match->date));
         $pattern = "@<event.*competition=\"{$competition}\".*id=\"(.*)\".*start_date=\"{$matchDate}.*/>@U";
         preg_match($pattern, $yandexSportAPI, $matches);
         $eventID = count($matches) && isset($matches[1]) ? $matches[1] : 0;
         $translation = ['link' => Url::to('/match/' . $match->id), 'id' => $match->id, 'competition_id' => $competition, 'event_id' => $eventID, 'comments' => []];
         $minute = 0;
         $comments = [];
         foreach ($events as $event) {
             $minute = $event->minute ? $event->minute : $minute;
             $comment = ['id' => $event->id, 'time' => $minute, 'text' => htmlspecialchars(strip_tags($event->notes, "<a><p><br>"))];
             $comments[] = (object) $comment;
         }
         $translation['comments'] = $comments;
         $translations[] = (object) $translation;
     }
     return $this->renderPartial('@frontend/views/site/translation_rss', compact('translations'));
 }