/** * Build flight and place registration in it. Create flight if necessary. * @return flight_id updated or created */ private function makeTeam($team_str) { $team_arr = explode('-', $team_str->id); // team-123 $team = Team::findOne($team_arr[1]); if (!$team) { // need to create it $team = new Team(); $team->name = $team_arr[1]; $team->save(); $team->refresh(); } $name = ''; foreach ($team_str->registrations as $registration_str) { $registration_arr = explode('-', $registration_str); // registration-456 if ($registration = Registration::findOne($registration_arr[1])) { $registration->team_id = $team->id; } $registration->save(); $name .= $registration->golfer->name . ' / '; } $name = rtrim($name, ' /'); $team->name = substr($name, 0, 80); $team->handicap = $team_str->handicap; $team->save(); return $team->id; }
protected function findModel($id) { if (($model = Team::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getTeam() { if ($this->_team === false) { $this->_team = Team::findOne($this->team_id); } if ($this->_team === null) { throw new NotFoundHttpException('The requested page does not exist.'); } return $this->_team; }
/** * Creates a new Composition model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($matchId = null, $teamId = null) { $model = new Composition(); if (!isset($matchId) || !isset($teamId)) { throw new \yii\web\BadRequestHttpException('Unidentified matchId and teamId'); } $match = Match::findOne($matchId); $team = Team::findOne($teamId); if (!isset($match) || !isset($team)) { throw new \yii\web\BadRequestHttpException('Unidentified match and team models'); } $model->command_id = $teamId; $model->match_id = $matchId; $model->is_basis = 1; $contractTeams = Team::getContractTeams(); if (in_array($teamId, $contractTeams)) { $model->contract_type = Composition::CONTRACT_TYPE; $contractModel = new Contract(); $contractModel->season_id = $match->season_id; $contractModel->is_active = 1; } else { $model->contract_type = Composition::MEMBERSHIP_TYPE; $contractModel = new Membership(); } $contractModel->command_id = $teamId; if ($model->load(Yii::$app->request->post()) && $contractModel->load(Yii::$app->request->post()) && $contractModel->validate()) { if ($contractModel->save(false)) { $model->contract_id = $contractModel->id; $model->number = $contractModel->number; $model->save(); } if (Yii::$app->request->isAjax) { $out = ['success' => 'true']; return Json::encode($out); } return $this->redirect(['view', 'id' => $model->id]); } else { if (Yii::$app->request->isAjax) { return $this->renderAjax('create', ['model' => $model, 'contractModel' => $contractModel]); } return $this->render('create', ['model' => $model, 'contractModel' => $contractModel]); } }
$availableTeams = []; if (!$model->isNewRecord) { $team = Team::findOne($model->command_home_id); if (isset($team->id)) { $availableTeams = [$team->id => $team->name]; } } echo $form->field($model, 'command_home_id')->widget(SelectizeDropDownList::classname(), ['loadUrl' => Url::to(['team/team-list']), 'items' => $availableTeams, 'options' => ['multiple' => false], 'clientOptions' => ['valueField' => 'value', 'labelField' => 'text', 'persist' => false]]); ?> </div> <div class="col-sm-6"> <?php $availableTeams = []; if (!$model->isNewRecord) { $team = Team::findOne($model->command_guest_id); if (isset($team->id)) { $availableTeams = [$team->id => $team->name]; } } echo $form->field($model, 'command_guest_id')->widget(SelectizeDropDownList::classname(), ['loadUrl' => Url::to(['team/team-list']), 'items' => $availableTeams, 'options' => ['multiple' => false], 'clientOptions' => ['valueField' => 'value', 'labelField' => 'text', 'persist' => false]]); ?> </div> </div> <div class="row"> <div class="col-sm-3 home-side"> <?php if (isset($model->command_home_id) && isset($model->season_id)) { ?> <?php
/** * Build flight and place registration in it. Create flight if necessary. * @return flight_id updated or created */ private function makeFlight($flight_str, $competition) { $competition_date = substr($competition->start_date, 0, 10); $flight_arr = explode('-', $flight_str->id); // flight-123 $flight = Flight::findOne($flight_arr[1]); if (!$flight) { // need to create it $flight = new Flight(); } else { // remove existings $flight->cleanRegistrations(); } $flight->position = $flight_str->position; Yii::trace($competition_date . ' ' . $flight_str->start_time . ':00', 'FlightController::makeFlight'); $flight->start_time = $competition_date . ' ' . $flight_str->start_time . ':00'; $flight->save(); // add currents if ($competition->isTeamCompetition()) { foreach ($flight_str->registrations as $registration_str) { $registration_arr = explode('-', $registration_str); // registration-456 $team = Team::findOne($registration_arr[1]); if ($team) { foreach ($team->getRegistrations()->each() as $registration) { $registration->flight_id = $flight->id; $registration->save(); } } } } else { foreach ($flight_str->registrations as $registration_str) { $registration_arr = explode('-', $registration_str); // registration-456 $registration = Registration::findOne($registration_arr[1]); if ($registration) { $registration->flight_id = $flight->id; $registration->save(); } } } return $flight->id; }
/** * 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)]]); }