/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Forward::find(); $forwardTable = Forward::tableName(); $playerTable = Player::tableName(); $teamTable = Team::tableName(); $query->joinWith(['player' => function ($query) use($playerTable) { $query->from(['player' => $playerTable]); }]); $query->joinWith(['team' => function ($query) use($teamTable) { $query->from(['team' => $teamTable]); }]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50], 'sort' => ['defaultOrder' => ['goals' => SORT_DESC, 'penalty' => SORT_DESC]]]); // enable sorting for the related columns $addSortAttributes = ["player.lastname", "team.name"]; foreach ($addSortAttributes as $addSortAttribute) { $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]]; } if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(["{$forwardTable}id" => $this->id, 'goals' => $this->goals, 'penalty' => $this->penalty, 'matches' => $this->matches, 'team_id' => $this->team_id, 'player_id' => $this->player_id, 'season_id' => $this->season_id]); $query->andFilterWhere(['like', 'team.name', $this->getAttribute('team.name')])->andFilterWhere(['like', 'player.lastname', $this->getAttribute('player.lastname')]); return $dataProvider; }
/** * Url: /tournament * @return mixed */ public function actionTournament() { $tournamentTable = Tournament::tableName(); $championshipTable = Championship::tableName(); // championship type select $championships = Championship::find()->innerJoin($tournamentTable, "{$tournamentTable}.championship_id = {$championshipTable}.id")->orderBy(['id' => SORT_DESC])->all(); $firstChampionshipObj = array_values($championships)[0]; $firstChampionshipId = $firstChampionshipObj->id; $activeChampionship = $firstChampionshipId; if (isset($_GET['championship'])) { foreach ($championships as $championship) { if ($_GET['championship'] == $championship->id) { $activeChampionship = $_GET['championship']; } } } $championshipsData = []; foreach ($championships as $championship) { $championshipsData[$championship->id] = ['value' => $championship->id, 'text' => $championship->name, 'active' => false]; } $championshipsData[$activeChampionship]['active'] = true; foreach ($championshipsData as $key => $championship) { $championshipsData[$key] = (object) $championship; } // season select $seasons = Season::find()->innerJoinWith('tournaments')->orderBy(['id' => SORT_DESC])->all(); $firstSeasonObj = array_values($seasons)[0]; $firstSeasonId = $firstSeasonObj->id; $activeSeason = $firstSeasonId; if (isset($_GET['season'])) { foreach ($seasons as $season) { if ($_GET['season'] == $season->id) { $activeSeason = $_GET['season']; } } } $seasonsData = []; foreach ($seasons as $season) { $seasonName = $season->name; $seasonsData[$season->id] = ['value' => $season->id, 'text' => $seasonName, 'active' => false]; } $seasonsData[$activeSeason]['active'] = true; foreach ($seasonsData as $key => $season) { $seasonsData[$key] = (object) $season; } $tournamentData = Tournament::find()->where(['season_id' => $activeSeason, 'championship_id' => $activeChampionship])->orderBy(['points' => SORT_DESC])->all(); $tournamentData = Tournament::sort($tournamentData); $forwards = Forward::find()->where(['season_id' => $activeSeason])->orderBy(['goals' => SORT_DESC, 'penalty' => SORT_DESC])->all(); $options = ['templateType' => 'col2', 'title' => 'Dynamomania.com | Турнирная таблица', 'columnFirst' => ['tournament' => ['view' => '@frontend/views/tournament/tournament_full', 'data' => compact('tournamentData', 'championshipsData', 'seasonsData')]], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]; if (count($forwards) > 0) { $options['columnFirst']['forwards'] = ['view' => '@frontend/views/tournament/forwards', 'data' => compact('forwards')]; } return $this->render('@frontend/views/site/index', $options); }