/** * 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 = Tournament::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'course_id' => $this->course_id, 'holes' => $this->holes, 'rule_id' => $this->rule_id, 'start_date' => $this->start_date, 'registration_begin' => $this->registration_begin, 'registration_end' => $this->registration_end, 'handicap_min' => $this->handicap_min, 'handicap_max' => $this->handicap_max, 'age_min' => $this->age_min, 'age_max' => $this->age_max, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'competition_type', $this->competition_type])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'gender', $this->gender])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TournamentModel::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'date' => $this->date, 'winning_team_id' => $this->winning_team_id, 'runner_up_id' => $this->runner_up_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'country_id', $this->country_id]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getTournaments() { return $this->hasMany(Tournament::className(), ['command_id' => 'id']); }
/** * find a document instance and returns it property typed. * * @return app\models\{Document,Bid,Order,Bill} the document */ public static function findCompetition($id) { $model = Competition::findOne($id); if ($model) { switch ($model->competition_type) { case self::TYPE_MATCH: return Match::findOne($id); break; case self::TYPE_TOURNAMENT: return Tournament::findOne($id); break; case self::TYPE_SEASON: return Season::findOne($id); break; } } return null; }
/** * Finds the Tournament model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tournament the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tournament::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getTournament() { return $this->hasOne(Tournament::className(), ['id' => 'parent_id']); }
/** * @return \yii\db\ActiveQuery */ public function getTournaments() { return $this->hasMany(Tournament::className(), ['championship_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getTournaments0() { return $this->hasMany(Tournament::className(), ['winning_team_id' => 'id']); }
/** * Get block with last 50 news * @return array Data */ public static function getTournamentTable() { $lastSeason = Tournament::find()->max("season_id"); $teams = Tournament::find()->where(['season_id' => $lastSeason])->orderBy(['points' => SORT_DESC])->all(); $block = ['view' => '@frontend/views/blocks/tournament_block', 'data' => ['teams' => $teams]]; return $block; }
/** * 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); }