/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Championship::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]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
<div class="col-sm-6"> <?php $availableTeams = []; if (!$model->isNewRecord) { $team = $model->team; if (isset($team->id)) { $availableTeams = [$team->id => $team->name]; } } echo $form->field($model, 'command_id')->widget(SelectizeDropDownList::classname(), ['loadUrl' => Url::to(['team/team-list']), 'items' => $availableTeams, 'options' => ['multiple' => false, 'placeholder' => 'Выберите команду...'], 'clientOptions' => ['valueField' => 'value', 'labelField' => 'text', 'persist' => false]]); ?> </div> <div class="col-sm-6"> <?php echo $form->field($model, 'championship_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Championship::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите чемпионат...'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> </div> <div class="row"> <div class="col-sm-6"> <?php echo $form->field($model, 'league_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(League::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите лигу...'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> <div class="col-sm-6"> <?php $seasons = ArrayHelper::map(Season::find()->where(['>', 'id', 42])->all(), 'id', 'name'); foreach ($seasons as $key => $season) {
/** * 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); }