/**
  * 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;
 }
 /**
  * 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'));
 }