public function actionIndex() { //没登录就回到主页 if (Yii::$app->user->isGuest) { return $this->render('/site/index'); } //没加入队伍就到/team/error页面 if (User::findByUsername(Yii::$app->user->identity->username)->teamname == "") { return $this->render('/team/error', ['message' => '<h2>你还没有加入任何一个战队呢!</h2>']); } $myteamname = User::findByUsername(Yii::$app->user->identity->username)->teamname; $myteam = Team::findOne(['teamname' => $myteamname]); //上传文件 $model = new UploadForm(); if (Yii::$app->request->isPost) { if ($myteam->uploaded_time < 50) { $model->sourcecode = UploadedFile::getInstance($model, 'sourcecode'); if ($id = $model->upload()) { $myteam->uploaded_time++; $myteam->save(false); //上传成功就render到uploadsuccess页面 return $this->render('uploadsuccess', ['id' => $id]); } } } //上传文件$model, return $this->render('index', ['model' => $model, 'myteam' => $myteam]); //,'indexs'=>$indexs]); }
public function actionIndex() { //没登录就回到主页 if (Yii::$app->user->isGuest) { return $this->render('/site/index'); } //没加入队伍就到/team/error页面 if (User::findByUsername(Yii::$app->user->identity->username)->teamname == "") { return $this->render('/team/error', ['message' => '<h2>你还没有加入任何一个战队呢!</h2>']); } $myteamname = User::findByUsername(Yii::$app->user->identity->username)->teamname; $myteam = Team::findOne(['teamname' => $myteamname]); //上传文件 $model = new UploadForm(); if (Yii::$app->request->isPost) { if ($myteam->uploaded_time < 50) { $model->sourcecode = UploadedFile::getInstance($model, 'sourcecode'); if ($id = $model->upload_first_round()) { return $this->render('uploadsuccess'); } } } $alreadysubmit = Firstroundcodes::find()->where(array('teamid' => $myteam->id))->exists(); //上传文件$model, return $this->render('index', ['model' => $model, 'alreadysubmit' => $alreadysubmit, 'myteam' => $myteam]); //,'indexs'=>$indexs]); }
/** * Обновление дедлайнов турнира */ public function actionDeadlines() { $tournaments = Tournament::find()->all(); $month = ['января' => 1, 'февраля' => 2, 'марта' => 3, 'апреля' => 4, 'мая' => 5, 'июня' => 6, 'июля' => 7, 'августа' => 8, 'сентября' => 9, 'октября' => 10, 'ноября' => 11, 'декабря' => 12]; foreach ($tournaments as $tournament) { $team = Team::findOne(['tournament_id' => $tournament->id]); if ($team !== null) { $dom = Html::load($team->url); $tables = $dom->getElementsByTagName('table'); foreach ($tables as $table) { if ($table->getAttribute('class') == 'profile-table') { $trs = $table->getElementsByTagName('tr'); foreach ($trs as $tr) { if ($tr->getElementsByTagName('th')->item(0)->nodeValue == 'Дедлайн') { $deadline = $tr->getElementsByTagName('td')->item(0)->nodeValue; $deadline = str_replace(['|', ':'], ' ', $deadline); $deadline = explode(' ', $deadline); if (count($deadline) == 4) { $year = date('Y'); $time = mktime($deadline[2], $deadline[3], 0, $month[$deadline[1]], $deadline[0], $year); $now = time(); if ($time < $now) { $year++; $time = mktime($deadline[2], $deadline[3], 0, $month[$deadline[1]], $deadline[0], $year); } $deadline = date('Y-m-d H:i:s', $time); } } elseif ($tr->getElementsByTagName('th')->item(0)->nodeValue == 'Трансферы в туре') { $transfers = $tr->getElementsByTagName('td')->item(0)->nodeValue; } } } } if ($tournament->deadline != $deadline) { $tournament->deadline = $deadline; if (isset($transfers)) { $tournament->checked = false; $tournament->transfers = $transfers; } else { $tournament->checked = true; } $tournament->save(); } } } }
/** * Обновляет список команд пользователя */ 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 upload_final_round() { if ($this->validate()) { $newcode = new Finalroundcodes(); $user = User::findByUsername(Yii::$app->user->identity->username); $myteam = Team::findOne(['teamname' => $user->teamname]); $newcode->teamid = $myteam->id; $newcode->teamname = $myteam->teamname; $newcode->uploaded_by = $user->username; $newcode->uploaded_at = date("Y/m/d H:i:s"); if ($newcode->save()) { //以队伍编号命名文件 $this->sourcecode->saveAs('ts17webhhh_final_round_codes_hhh/' . $newcode->teamid . '.cpp'); return $newcode->id; } } else { return false; } return false; }
/** * Finds the Team model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Team the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Team::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionIndex() { //没登录就回到主页 if (Yii::$app->user->isGuest) { return $this->render('/site/index'); } $myteamname = User::findByUsername(Yii::$app->user->identity->username)->teamname; //没加入队伍就到/team/error页面 if ($myteamname == "") { return $this->render('/team/error', ['message' => '<h2>你还没有加入任何一个战队呢!</h2>']); } //$myteam = Team::findByTeamname($myteamname); $myteam = Team::findOne(['teamname' => $myteamname]); //我已上传成功的代码 $mycodes = Sourcecodes::find()->where(['team' => $myteamname])->orderBy('uploaded_at DESC')->all(); $mycodes2 = $mycodes; foreach ($mycodes2 as $mycode) { $mycode->uploaded_at = $mycode->id . '号,上传于' . $mycode->uploaded_at; } //已上传代码的队伍,除掉自己所在的队伍 $teamnames = Sourcecodes::find()->select('team')->where("team<>'{$myteamname}'")->distinct()->orderBy('uploaded_at DESC'); $teams = Team::find()->where(['teamname' => $teamnames])->all(); //别的队伍的代码 $otherscodes = Sourcecodes::find()->where("team<>'{$myteamname}'")->select('uploaded_at')->orderBy('uploaded_at DESC')->column(); //对战结果 $results1 = Battleresult::find(); //对战结果分页器 $pagination = new Pagination(['defaultPageSize' => 20, 'totalCount' => $results1->count()]); $results = $results1->orderBy('battle_at DESC')->offset($pagination->offset)->limit($pagination->limit)->all(); //表单 $model = new BattleForm(); //上传文件$model, if ($model->load(Yii::$app->request->post())) { if ($myteam->battled_time < 200) { //如果对战次数还没到10次 $myteam->battled_time++; $myteam->save(false); $model->myteam = $myteam->id; //我方代码编号 $model->mycode = $_POST['BattleForm']['mycode']; //敌方队伍名称 $model->enemyteam = $_POST['BattleForm']['enemyteam']; //敌方代码编号 $model->enemycode = $_POST['BattleForm']['enemycode']; $result = new Battleresult(); $result->team1 = $myteamname; $result->ai1 = $model->mycode; $result->team2 = Team::findOne(['id' => $model->enemyteam])->teamname; $result->ai2 = $model->enemycode; date_default_timezone_set('PRC'); $result->battle_at = date("Y-m-d H:i:s"); $result->result = '对战中'; $result->save(); $model->id = $result->id; $re = $model->battle(); return $this->redirect(['index']); } else { print "哥们你对战太多次了<br>明天再来吧~"; } die; } return $this->render('index', ['model' => $model, 'myteam' => $myteam, 'mycodes' => $mycodes2, 'teams' => $teams, 'otherscodes' => $otherscodes, 'results' => $results, 'pagination' => $pagination]); }