/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TeamCoach::find(); $teamCoachTable = TeamCoach::tableName(); $coachTable = Coach::tableName(); $teamTable = Team::tableName(); $seasonTable = Season::tableName(); $query->joinWith(['coach' => function ($query) use($coachTable) { $query->from(['coach' => $coachTable]); }]); $query->joinWith(['team' => function ($query) use($teamTable) { $query->from(['team' => $teamTable]); }]); $query->joinWith(['season' => function ($query) use($seasonTable) { $query->from(['season' => $seasonTable]); }]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $addSortAttributes = ["coach.name", "team.name", "season.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(["{$teamCoachTable}.id" => $this->id, 'team_id' => $this->team_id, 'season_id' => $this->season_id, 'coach_id' => $this->coach_id, 'is_main' => $this->is_main]); $query->andFilterWhere(['like', 'coach.name', $this->getAttribute('coach.name')])->andFilterWhere(['like', 'team.name', $this->getAttribute('team.name')])->andFilterWhere(['like', 'season.name', $this->getAttribute('season.name')]); return $dataProvider; }
/** * Url: /info|composition|achievements|record-holders/{$id} * @param $tab string Team id * @param bool|int $id int Team id * @return mixed * @throws NotFoundHttpException */ public function actionTeam($tab, $id = false) { if ($id === false) { $id = Team::TEAM_DK_FIRST_FULL_NAME; } $team = Team::findOne($id); $tabs = ['info', 'composition', 'achievements', 'record-holders']; if (!isset($team) || !in_array($tab, $tabs)) { throw new NotFoundHttpException('The requested page does not exist.'); } if ($tab == 'composition') { $availableTeams = [Team::TEAM_DK_FIRST_FULL_NAME => Team::findOne(Team::TEAM_DK_FIRST_FULL_NAME), Team::TEAM_DK_M => Team::findOne(Team::TEAM_DK_M), Team::TEAM_DK2 => Team::findOne(Team::TEAM_DK2), Team::TEAM_U19 => Team::findOne(Team::TEAM_U19)]; $seasonTable = Season::tableName(); $availableSeasons = Season::find()->innerJoinWith('contracts')->where(['window' => Season::WINDOW_WINTER])->andWhere(["command_id" => $id])->orderBy(["{$seasonTable}.id" => SORT_DESC])->all(); $availableSeasonsIds = []; foreach ($availableSeasons as $season) { $availableSeasonsIds[] = $season->id; } if (isset($_GET['season']) && in_array($_GET['season'], $availableSeasonsIds)) { $activeSeason = $_GET['season']; } else { $activeSeason = $availableSeasonsIds[0]; } $composition = Contract::find()->where(['is_active' => 1, 'season_id' => $activeSeason, 'command_id' => $team->id])->orderBy(['amplua_id' => SORT_ASC])->all(); $mainCoach = TeamCoach::find()->where(['is_main' => 1, 'season_id' => $activeSeason, 'team_id' => $id])->one(); $teamCoaches = TeamCoach::find()->where(['season_id' => $activeSeason, 'team_id' => $id, 'is_main' => 0])->all(); $data = ['teamModel' => $team, 'availableSeasons' => $availableSeasons, 'activeSeason' => $activeSeason, 'availableTeams' => $availableTeams, 'activeTeam' => $team->id, 'composition' => $composition, 'mainCoach' => $mainCoach, 'teamCoaches' => $teamCoaches]; } else { $information = MainInfo::find()->all(); $info = []; foreach ($information as $data) { $info[$data->name] = $data; } $data = compact('team', 'info'); } return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $team->name, 'columnFirst' => ['nav-bar' => ['view' => '@frontend/views/team/menu', 'data' => compact('team', 'tab')], 'content' => ['view' => '@frontend/views/team/tab-' . $tab, 'data' => $data]], 'columnSecond' => ['tournament' => SiteBlock::getshortNews(50), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]]); }