/** * Creates a new Team model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { return $this->redirect(['index']); $searchModel = new TeamSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if (Yii::$app->user->identity->teamname != null) { //Èç¹û¸ÃÓû§¼ÓÈë¶ÓÎ飬Ôò·µ»ØÖ÷Ò³ // $team = team::findone(['teamname'=>Yii::$app->user->identity->teamname]); // return $this->render('index', [ // 'myTeamInfo' => $team, // 'searchModel' => $searchModel, // 'dataProvider' => $dataProvider]); return $this->render('error', ['message' => '你已经在某个队伍里面了']); } $model = new Team(); if ($model->load(Yii::$app->request->post())) { $user = User::findOne(['username' => Yii::$app->user->identity->username]); $model->leadername = $user->username; //¸ü¸ÄteamµÄleader $model->status = 1; $user->teamname = $model->teamname; //¸ü¸ÄuserµÄteam $user->updated_at = date("Y-m-d H:i:s"); //¸ü¸ÄuserµÄupdateʱ¼ä if ($model->save() && $user->save(false)) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('error', ['message' => '请检查你的队伍信息是否唯一且你没有在另外一支队伍里面']); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Team model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Team(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $team = new Team(); $team->NAZWA = $request->input("NAZWA"); $team->TRENER_ID_TRENER = $request->input("TRENER_ID_TRENER"); $team->BUDZET = $request->input("BUDZET"); $team->save(); return redirect()->route('teams.index')->with('message', 'Item created successfully.'); }
public function getApplication() { $application = Application::with('school', 'team', 'ratings', 'notes')->firstOrCreate(['user_id' => $this->id]); if (!$application->team_id) { //assign them to a team of 1 in lieu of no team $team = new Team(); $team->code = md5(Carbon::now() . getenv("APP_KEY")); $team->save(); $application->team_id = $team->id; } $application->save(); $application->teaminfo = $application->team; $application->schoolinfo = $application->school; return $application; }
/** * Обновляет список команд пользователя */ public function updateTeams() { if (!empty($this->profile_url)) { // Запоминаем старые команды $oldTeams = []; foreach ($this->teams as $team) { $oldTeams[] = $team->url; } // Получаем список новых команд $dom = Html::load($this->profile_url . 'fantasy/'); $divs = $dom->getElementsByTagName('div'); $host = 'https://www.sports.ru'; foreach ($divs as $div) { if ($div->getAttribute('class') == 'item user-league') { $links = $div->getElementsByTagName('a'); $tournamentUrl = $host . $links->item(1)->getAttribute('href'); if (preg_match('/.*\\/fantasy\\/football\\/.*/', $tournamentUrl)) { // Проверяем турнир к которому относится команда $tournament = Tournament::findOne(['url' => $tournamentUrl]); if ($tournament === null) { $tournament = new Tournament(['url' => $tournamentUrl, 'name' => $links->item(1)->nodeValue]); $tournament->save(); } // Добавляем команду $teamUrl = $host . $links->item(0)->getAttribute('href'); $teamUrl = str_replace('/football/team/', '/football/team/points/', $teamUrl); $team = Team::findOne(['url' => $teamUrl]); if ($team === null) { $team = new Team(['user_id' => $this->id, 'url' => $teamUrl, 'name' => $links->item(0)->nodeValue, 'tournament_id' => $tournament->id]); $team->save(); } else { $index = array_search($teamUrl, $oldTeams); array_splice($oldTeams, $index, 1); } } } } // Удаляем старые команды foreach ($oldTeams as $url) { $team = Team::findOne(['url' => $url]); if ($team !== null) { $team->delete(); } } } }
public function postCreateTeam(LoggedInRequest $request) { if (Team::where('abb', $request->input('teamAbb'))->first()) { $request->session()->flash('msg', 'That abbreviation has been taken!!'); return $this->getCreateTeam($request); } $hash = self::generateRandomInt(); while (Team::where('team_key', $hash)->first() != null) { $hash = self::generateRandomInt(); } $team = new Team(); $team->team_key = $hash; $team->name = $request->input('teamName'); $team->abb = strtoupper($request->input('teamAbb')); $team->save(); $request->session()->flash('msg', 'Team ' . $team->name . ' created!'); return $this->getEditTeam($request); }
/** * Заполнение таблицы команд */ public function actionFillFTeams() { $m = Matches::find()->select(['host, tournament, COUNT(*) as cnt'])->groupBy('host')->all(); foreach ($m as $h) { $team = new Team(); $tournament = explode(':', $h->tournament); $team->name = iconv_substr($h->host, 1, 80, 'UTF-8'); if (strripos($team->name, '(')) { $host = explode(' ', $team->name); array_pop($host); $team->adapt_name = trim(implode(' ', $host)); } $team->reg = isset($tournament[0]) ? $tournament[0] : ''; $team->save(false); } //var_dump($m); }
public function addToTeam(User $member, $parentUser) { $teamInvitation = TeamInvitation::where('accept_email', '=', $member->email)->where('request_id', '=', $parentUser)->first(); if (!$teamInvitation) { die("Something went wrong.You have no invitation"); } $userTeam = Team::where('member_id', '=', $parentUser)->first(); if (!$userTeam) { $userTeam = new Team(); $userTeam->member_id = $parentUser; $userTeam->status = 2; $userTeam->save(); $userTeam->team_id = $userTeam->id; $userTeam->save(); } $teamId = $userTeam->team_id; $teamInvitation->status = 1; $teamInvitation->save(); $team = new Team(); $team->team_id = $teamId; $team->member_id = $member->id; $team->status = 1; //user is not activated $team->save(); }