Inheritance: extends Illuminate\Database\Eloquent\Model
 public function create()
 {
     if ($this->validate()) {
         $tournament = new Tournament($this->toArray());
         if ($tournament->save()) {
             return $tournament;
         }
     }
     return null;
 }
Exemple #2
0
 public function updating(Tournament $model)
 {
     $dirtyStatus = array_get($model->getDirty(), 'status');
     if (Tournament::STATUS_STARTED === $dirtyStatus && 1 > $model->matches()->getResults()->count()) {
         Log::debug('Tournament ' . $model->name . ' was started');
         event(new TournamentWasStarted($model));
     }
     if (Tournament::STATUS_DRAFT === $dirtyStatus) {
         Log::debug('Tournament ' . $model->name . ' was reset');
         event(new TournamentWasReset($model));
     }
 }
Exemple #3
0
 /**
  * Handle the event.
  *
  * @param  Events $event
  * @return void
  */
 public function handle(TournamentWasStarted $event)
 {
     $this->setTournament($event->tournament);
     if (Tournament::MIN_TEAMS_AMOUNT > count($this->teams)) {
         throw new \UnexpectedValueException('Tournament should have at least 2 teams.');
     }
     /**
      * @var $matches Collection
      */
     $matches = $this->tournament->matches()->getResults();
     if (0 < $matches->count()) {
         throw new \UnexpectedValueException('Tournament draw has been already done.');
     }
     $this->draw();
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('tournaments', function (Blueprint $table) {
         $table->enum('type', Tournament::getAvailableTypes())->default(Tournament::TYPE_LEAGUE);
         $table->enum('membersType', Tournament::getAvailableMembersType())->default(Tournament::MEMBERS_TYPE_SINGLE);
     });
 }
 /**
  * Tests if the remove tournament method
  * works as expected.
  */
 public function testRepoRemoveTournamentRemovalSuccess()
 {
     $tournament = Factory::create('App\\Models\\Tournament');
     $result = $this->repository->removeTournament(Administrator::find($tournament->created_by), $tournament->name);
     $this->assertTrue($result);
     $this->assertNull(Tournament::find($tournament->id));
 }
 public function index()
 {
     $team = Team::find(config('mls.team_id'));
     $gameList = GameRepository::getListByTeamId($team->id);
     $tournamentList = Tournament::all();
     $tournamentList = $tournamentList->lists('name', 'id');
     return view('frontend.game.list')->with('team', $team)->with('gameList', $gameList)->with('tournamentList', $tournamentList);
 }
Exemple #7
0
 /**
  * Обновляет список команд пользователя
  */
 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 add(AddTeam $request)
 {
     $tournament = Tournament::findOrFail($request->input('team.tournament'));
     if (Tournament::STATUS_DRAFT !== $tournament->status) {
         throw new LogicException('Team can be assigned only to tournament with draft status.');
     }
     $team = TournamentTeam::create($request->input('team'));
     return $this->response->collection(TournamentTeam::where(['id' => $team->id])->get(), new TournamentTeamTransformer(), 'teams');
 }
 public function update($tournamentId)
 {
     /**
      * @var Tournament $tournament
      */
     $tournament = Tournament::findOrFail($tournamentId);
     $tournament->update(['name' => Input::get('tournament.name'), 'type' => Input::get('tournament.type'), 'status' => Input::get('tournament.status'), 'membersType' => Input::get('tournament.membersType'), 'description' => Input::get('tournament.description')]);
     return $this->response->collection(Tournament::where(['id' => $tournamentId])->get(), new TournamentTransformer(), 'tournaments');
 }
 public function register($id)
 {
     $tournament = Tournament::findOrFail($id);
     $user = Auth::user();
     if (!$tournament->isRegistrationOpen()) {
         return error_popup('registrations are closed!');
     }
     if (!$tournament->isValidRank($user)) {
         return error_popup('invalid rank!');
     }
     $tournament->register($user);
     return ujs_redirect("/tournaments/{$id}");
 }
 public function edit(Game $game)
 {
     return view('backend.games.edit')->with('game', $game)->with('homeList', Game::getHomeList())->with('statusList', Game::getStatusList())->with('tournamentList', Tournament::lists('name', 'id'));
 }
 /**
  * Tests if the remove rankings works
  * correclty.
  */
 public function testRepoRemoveRankingRemovalSuccess()
 {
     $ranking = Factory::create('App\\Models\\Ranking');
     $admin = Administrator::find(Tournament::find($ranking->tournament_id)->created_by);
     $result = $this->repository->removeRanking($admin, $ranking->id);
     $this->assertTrue($result);
     $this->assertNull(Ranking::find($ranking->id));
 }
 public static function getListByTeamId($teamId)
 {
     return Tournament::whereNotNull('link')->where('team_id', $teamId)->get();
 }
 /**
  * Проверка замен перед дедлайном
  */
 public function actionCheck()
 {
     $bot = new BotApi(Yii::$app->params['token']);
     $time = time() + 2 * 60 * 60;
     $tournaments = Tournament::find()->where(['checked' => false])->andWhere(['<', 'deadline', date('Y-m-d H:i:s', $time)])->all();
     foreach ($tournaments as $tournament) {
         foreach ($tournament->teams as $team) {
             if ($team->user->notification) {
                 $transfers = $team->getTransfers();
                 if ($transfers == $tournament->transfers) {
                     $message = 'Ты ещё не сделал замены, скоро дедлайн:';
                     $date = new DateTime($tournament->deadline, new DateTimeZone(Yii::$app->timeZone));
                     $message .= "\n" . $date->format('H:i') . '  ' . $tournament->name;
                     try {
                         $bot->sendMessage($team->user->chat_id, $message);
                     } catch (Exception $e) {
                         Yii::info($e->getMessage(), 'send');
                     }
                 }
             }
         }
         $tournament->checked = true;
         $tournament->save();
     }
 }
 /**
  * Method responsible for getting
  * the desired tournament.
  *
  * @param Administrator $admin
  * @param str $name
  *
  * @throws Illuminate\Database\Eloquent\ModelNotFoundException
  *
  * @return Tournament
  */
 private function retrieveTournament(Administrator $admin, $name)
 {
     return Tournament::where('name', $name)->where('created_by', $admin->id)->firstOrFail();
 }
Exemple #16
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     Tournament::create(Request::all());
     return redirect('tournament');
 }
 public function destroy(Tournament $tournament)
 {
     $tournament->delete();
     Flash::success(trans('general.delete_msg'));
     return redirect(route('admin.tournaments'));
 }
 public function run()
 {
     Tournament::create(['id' => '1', 'name' => 'Friendly', 'team_id' => 1]);
 }
Exemple #19
0
<?php

require __DIR__ . '/../../bootstrap/autoload.php';
$app = (require_once __DIR__ . '/../../bootstrap/app.php');
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
use App;
$response = $kernel->handle($request = Illuminate\Http\Request::capture());
$tournament = App\Models\Tournament::find(1);
App\Models\Match::where(['tournamentId' => $tournament->id])->delete();
$event = new App\Events\TournamentWasStarted($tournament);
$handler = new App\Listeners\Tournament\DrawLeague();
$handler->handle($event);
Exemple #20
0
 public function getTournament()
 {
     return $this->hasOne(Tournament::className(), ['id' => 'tournament_id']);
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     Tournament::observe(new TournamentObserver());
     TournamentTeam::observe(new TournamentTeamObserver());
     Match::observe(new MatchObserver());
 }
 public function actionView($tournament)
 {
     $tournament = Tournament::findOne($tournament);
     return $this->render('/champ', ['tournament' => $tournament]);
 }
Exemple #23
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     return ['tournament.name' => 'required', 'tournament.description' => '', 'tournament.type' => 'in:' . join(',', Tournament::getAvailableTypes()), 'tournament.membersType' => 'in:' . join(',', Tournament::getAvailableMembersType())];
 }
 /**
  * Validates the Player and the
  * Tournament relashionships
  *
  * @param Tournament $tournament
  * @param Player $player
  *
  * @throws Illuminate\Database\Eloquent\ModelNotFoundException
  */
 private function validatePlayer(Tournament $tournament, Player $player)
 {
     $tournament->players()->where('player_id', $player->id)->firstOrFail();
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('tournaments', function (Blueprint $table) {
         $table->enum('status', Tournament::getAvailableStatuses())->default(Tournament::STATUS_DRAFT);
     });
 }