Inheritance: extends Illuminate\Database\Eloquent\Model
Exemplo n.º 1
0
 public function create()
 {
     if ($this->validate()) {
         $tournament = new Tournament($this->toArray());
         if ($tournament->save()) {
             return $tournament;
         }
     }
     return null;
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 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();
             }
         }
     }
 }
Exemplo n.º 8
0
 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');
 }
Exemplo n.º 9
0
 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');
 }
Exemplo n.º 10
0
 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}");
 }
Exemplo n.º 11
0
 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));
 }
Exemplo n.º 13
0
 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();
 }
Exemplo n.º 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'));
 }
Exemplo n.º 18
0
 public function run()
 {
     Tournament::create(['id' => '1', 'name' => 'Friendly', 'team_id' => 1]);
 }
Exemplo n.º 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);
Exemplo n.º 20
0
 public function getTournament()
 {
     return $this->hasOne(Tournament::className(), ['id' => 'tournament_id']);
 }
Exemplo n.º 21
0
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     Tournament::observe(new TournamentObserver());
     TournamentTeam::observe(new TournamentTeamObserver());
     Match::observe(new MatchObserver());
 }
Exemplo n.º 22
0
 public function actionView($tournament)
 {
     $tournament = Tournament::findOne($tournament);
     return $this->render('/champ', ['tournament' => $tournament]);
 }
Exemplo n.º 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);
     });
 }