예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Contract::find();
     $contractTable = Contract::tableName();
     $playerTable = Player::tableName();
     $teamTable = Team::tableName();
     $seasonTable = Season::tableName();
     $ampluaTable = Amplua::tableName();
     $query->joinWith(['player' => function ($query) use($playerTable) {
         $query->from(['player' => $playerTable]);
     }]);
     $query->joinWith(['team' => function ($query) use($teamTable) {
         $query->from(['team' => $teamTable]);
     }]);
     $query->joinWith(['teamFrom' => function ($query) use($teamTable) {
         $query->from(['teamFrom' => $teamTable]);
     }]);
     $query->joinWith(['season' => function ($query) use($seasonTable) {
         $query->from(['season' => $seasonTable]);
     }]);
     $query->joinWith(['amplua' => function ($query) use($ampluaTable) {
         $query->from(['amplua' => $ampluaTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $addSortAttributes = ["player.lastname", "teamFrom.name", "team.name", "season.name", "amplua.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(["{$contractTable}.id" => $this->id, 'command_id' => $this->command_id, 'season_id' => $this->season_id, 'amplua_id' => $this->amplua_id, 'number' => $this->number, 'command_from_id' => $this->command_from_id, 'year_from' => $this->year_from, 'year_till' => $this->year_till, 'matches' => $this->matches, 'goals' => $this->goals, 'is_active' => $this->is_active, 'debut' => $this->debut, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'teamFrom.name', $this->getAttribute('teamFrom.name')])->andFilterWhere(['like', 'team.name', $this->getAttribute('team.name')])->andFilterWhere(['like', 'player.lastname', $this->getAttribute('player.lastname')])->andFilterWhere(['like', 'season.name', $this->getAttribute('season.name')])->andFilterWhere(['like', 'amplua.name', $this->getAttribute('amplua.name')]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContracts()
 {
     return $this->hasMany(Contract::className(), ['command_from_id' => 'id']);
 }
예제 #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContract()
 {
     if ($this->getContractType() == self::CONTRACT_TYPE) {
         return $this->hasOne(Contract::className(), ['id' => 'contract_id']);
     } elseif ($this->getContractType() == self::MEMBERSHIP_TYPE) {
         return $this->hasOne(Membership::className(), ['id' => 'contract_id']);
     } else {
         return null;
     }
 }
예제 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getNumber($seasonID = false)
 {
     if (!$seasonID) {
         $seasonID = Season::find()->where(['window' => Season::WINDOW_WINTER])->orderBy(['id' => SORT_DESC])->one();
     }
     $number = Contract::find()->where(['player_id' => $this->id])->andWhere(['season_id' => $seasonID->id])->one();
     return isset($number->number) ? $number->number : '-';
 }
예제 #5
0
 /**
  * Updates an existing Match model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->date = date('d.m.Y H:i', strtotime($model->date));
     // compositionForm
     $compositionForm = new CompositionForm();
     $compositionForm->match_id = $model->id;
     $compositionForm->initPlayers($model->command_home_id, $model->command_guest_id);
     $searchModel = new CompositionSearch();
     // homeCompositionDataProvider
     $params = ['CompositionSearch' => ['match_id' => $model->id, 'command_id' => $model->command_home_id]];
     $homeCompositionDataProvider = $searchModel->search($params);
     $homeCompositionDataProvider->setSort(['defaultOrder' => ['is_basis' => SORT_DESC, 'number' => SORT_ASC]]);
     // guestCompositionDataProvider
     $params = ['CompositionSearch' => ['match_id' => $model->id, 'command_id' => $model->command_guest_id]];
     $guestCompositionDataProvider = $searchModel->search($params);
     $guestCompositionDataProvider->setSort(['defaultOrder' => ['is_basis' => SORT_DESC, 'number' => SORT_ASC]]);
     $contractTeams = Team::getContractTeams();
     // homeComposition
     if (in_array($model->command_home_id, $contractTeams)) {
         $homeContractType = CompositionForm::CONTRACT_TYPE;
         $homeCompositionData = Contract::find()->where(['command_id' => $model->command_home_id, 'season_id' => $model->season_id, 'is_active' => 1])->orderBy(['number' => SORT_ASC])->all();
     } else {
         $homeContractType = CompositionForm::MEMBERSHIP_TYPE;
         $homeCompositionData = Membership::find()->where(['command_id' => $model->command_home_id])->orderBy(['number' => SORT_ASC])->all();
     }
     $homeComposition = [];
     foreach ($homeCompositionData as $key => $data) {
         $homeComposition[$key]['id'] = $data->id;
         $homeComposition[$key]['name'] = "#" . $data->number . " " . $data->player->lastname . " " . $data->player->firstname;
     }
     // guestComposition
     if (in_array($model->command_guest_id, $contractTeams)) {
         $guestContractType = CompositionForm::CONTRACT_TYPE;
         $guestCompositionData = Contract::find()->where(['command_id' => $model->command_guest_id, 'season_id' => $model->season_id, 'is_active' => 1])->orderBy(['number' => SORT_ASC])->all();
     } else {
         $guestContractType = CompositionForm::MEMBERSHIP_TYPE;
         $guestCompositionData = Membership::find()->where(['command_id' => $model->command_guest_id])->orderBy(['number' => SORT_ASC])->all();
     }
     $guestComposition = [];
     foreach ($guestCompositionData as $key => $data) {
         $guestComposition[$key]['id'] = $data->id;
         $guestComposition[$key]['name'] = "#" . $data->number . " " . $data->player->lastname . " " . $data->player->firstname;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->date = date('Y-m-d H:i', strtotime($model->date));
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', compact('model', 'compositionForm', 'homeComposition', 'guestComposition', 'homeContractType', 'guestContractType', 'homeCompositionDataProvider', 'guestCompositionDataProvider'));
     }
 }
 /**
  * Finds the Contract model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Contract the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Contract::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContracts()
 {
     return $this->hasMany(Contract::className(), ['season_id' => 'id']);
 }
예제 #8
0
 /**
  * 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)]]);
 }