/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tournament::find(); $tournamentTable = Tournament::tableName(); $teamTable = Team::tableName(); $leagueTable = League::tableName(); $championshipTable = Championship::tableName(); $seasonTable = Season::tableName(); $query->joinWith(['team' => function ($query) use($teamTable) { $query->from(['team' => $teamTable]); }]); $query->joinWith(['league' => function ($query) use($leagueTable) { $query->from(['league' => $leagueTable]); }]); $query->joinWith(['championship' => function ($query) use($championshipTable) { $query->from(['championship' => $championshipTable]); }]); $query->joinWith(['season' => function ($query) use($seasonTable) { $query->from(['season' => $seasonTable]); }]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['points' => SORT_DESC]]]); // enable sorting for the related columns $addSortAttributes = ["team.name", "league.name", "championship.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(["{$tournamentTable}id" => $this->id, 'command_id' => $this->command_id, 'championship_id' => $this->championship_id, 'season_id' => $this->season_id, 'played' => $this->played, 'won' => $this->won, 'draw' => $this->draw, 'lost' => $this->lost, 'goals_for' => $this->goals_for, 'goals_against' => $this->goals_against, 'points' => $this->points, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'fair_play' => $this->fair_play, 'league_id' => $this->league_id]); $query->andFilterWhere(['like', 'team.name', $this->getAttribute('team.name')]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = League::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])->andFilterWhere(['like', 'abr', $this->abr]); return $dataProvider; }
/** * Lists all Tournament models. * @return mixed */ public function actionIndex() { $searchModel = new TournamentSearch(); $tournamentTable = $searchModel::tableName(); $seasonTable = Season::tableName(); $seasons = Season::find()->innerJoin($tournamentTable, "{$tournamentTable}.season_id = {$seasonTable}.id")->orderBy(['name' => SORT_DESC])->all(); $availableSeasons = ArrayHelper::map($seasons, 'id', 'name'); $leagueTable = League::tableName(); $leagues = League::find()->innerJoin($tournamentTable, "{$tournamentTable}.league_id = {$leagueTable}.id")->all(); $availableLeagues = ArrayHelper::map($leagues, 'id', 'name'); $queryParams = Yii::$app->request->queryParams; if (count($queryParams) == 0) { $queryParams['TournamentSearch']['season_id'] = array_keys($availableSeasons)[0]; } $dataProvider = $searchModel->search($queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'availableSeasons' => $availableSeasons, 'availableLeagues' => $availableLeagues]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Career::find(); $team = new Team(); $league = new League(); $season = new Season(); $player = new Player(); $careerTable = Career::tableName(); $teamTable = Team::tableName(); $leagueTable = League::tableName(); $seasonTable = Season::tableName(); $playerTable = Player::tableName(); $query->joinWith(['team' => function ($query) use($teamTable) { $query->from(['team' => $teamTable]); }]); $query->joinWith(['league' => function ($query) use($leagueTable) { $query->from(['league' => $leagueTable]); }]); $query->joinWith(['player' => function ($query) use($playerTable) { $query->from(['player' => $playerTable]); }]); $query->joinWith(['season' => function ($query) use($seasonTable) { $query->from(['season' => $seasonTable]); }]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $addSortAttributes = ['team.name', 'player.lastname', 'league.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(["{$careerTable}.id" => $this->id, 'player_id' => $this->player_id, 'season_id' => $this->season_id, 'championship_matches' => $this->championship_matches, 'championship_goals' => $this->championship_goals, 'cup_matches' => $this->cup_matches, 'cup_goals' => $this->cup_goals, 'euro_matches' => $this->euro_matches, 'euro_goals' => $this->euro_goals, 'avg_mark' => $this->avg_mark, 'goal_passes' => $this->goal_passes]); $query->andFilterWhere(['like', "team.name", $this->getAttribute('team.name')])->andFilterWhere(['like', "player.lastname", $this->getAttribute('player.lastname')])->andFilterWhere(['like', "league.name", $this->getAttribute('league.name')])->andFilterWhere(['like', "season.name", $this->getAttribute('season.name')]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getLeague() { return $this->hasOne(League::className(), ['id' => 'league_id']); }
} 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) { if (strpos($season, '/') === false) { unset($seasons[$key]); } } echo $form->field($model, 'season_id')->widget(Select2::classname(), ['data' => $seasons, 'language' => 'ru', 'options' => ['placeholder' => 'Выберите сезон...'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> </div>
/** * Finds the League model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return League the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = League::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }