2017 © Pedro Peláez
 

library laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

image

xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  • Thursday, May 3, 2018
  • by xoco
  • Repository
  • 10 Watchers
  • 125 Stars
  • 20,976 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 20 Forks
  • 7 Open issues
  • 26 Versions
  • 1 % Grown

The README.md


Laravel Tournaments
Laravel Tournaments

A Laravel plugin that generate tournaments out of the box

Latest Stable Version Total Downloads Scrutinizer Code Quality Build Status Code Coverage , (*1)


Laravel Tournaments Demo

Features

  • Single Elimination Trees Generation
  • Single Elimination with Preliminary Round Generation
  • Playoff Generation
  • Third place fight
  • List of Fights Generation
  • Customize Preliminary Round Size
  • Customize area number (1,2,4,8)
  • Modify Single Elimination Tree generation on the fly
  • Use teams instead of competitors

Installation

NOTE: Depending on your version of Laravel, you should install a different version of the package:, (*2)

Laravel Version Laravel Tournament Version
8 0.17
5.8 -> 7 0.16
5.7 0.15
5.6 0.14
5.5 0.13

First, you'll need to install the package via Composer:, (*3)

composer require "xoco70/laravel-tournaments"

Finally, from the command line again, publish the default configuration file:, (*4)

php artisan vendor:publish --tag=laravel-tournaments --force

Demo

To run the demo, you need to generate Tournaments, Championships, Users, Competitors and Settings, (*5)

Run Migrations:, (*6)

php artisan migrate
composer dump-autoload

Seed dummy data:, (*7)

php artisan db:seed --class=LaravelTournamentSeeder

WARNING: Don't do this in production, it would wipe all your data. Use this line for demo purpose only, (*8)

Add TreeController ( you can find it in demo repository), (*9)

Add your custom routes, (*10)

Route::get('/', 'App\Http\Controllers\TreeController@index')->name('tree.index');
Route::post('/championships/{championship}/trees', 'App\Http\Controllers\TreeController@store')->name('tree.store');
Route::put('/championships/{championship}/trees', 'App\Http\Controllers\TreeController@update')->name('tree.update');
php artisan db:seed --class=LaravelTournamentSeeder

You will be able to access the demo at http://yourdomain.com/, (*11)

Usage

// Create a tournament

$tournament = factory(Tournament::class)->create(['user_id' => Auth::user()->id]);

$championsip = factory(Championship::class)->create(['$tournament_id' => $tournament->id]);

// Optional, if not defined, it will take default in ChampionshipSettings

$settings = factory(ChampionshipSettings::class)->create(['championship_id' => $championship->id]);

// Add competitors to championship

$competitors = factory(\App\Competitor::class,10)->create([
    'championship_id' => $championship->id,
     'user_id' => factory(User::class)->create()->id
]);

// Define strategy to generate

$generation = $championship->chooseGenerationStrategy();

// Generate everything

$generation->run();

// Just generate Tree

$this->generateAllTrees();

// Just generate Fight List

$this->generateAllFights();

Data model

Database Model, (*12)

Models

Tournament

$tournament->owner; // get owner
$tournament->venue; // get venue
$tournament->championships; // get championships 

Check tournament type:, (*13)

$tournament->isOpen()
$tournament->needsInvitation()

Check tournament level:, (*14)

$tournament ->isInternational()
$tournament->isNational() 
$tournament->isRegional()
$tournament->isEstate()
$tournament->isMunicipal()
$tournament->isDistrictal()
$tournament->isLocal()
$tournament->hasNoLevel()

Championship

$championship->competitors; // Get competitors
$championship->teams; // Get teams
$championship->fighters; // Get fighters
$championship->category; // Get category
$championship->tournament; // Get tournament
$championship->users; // Get users
$championship->settings; // Get settings
$championship->fightersGroups; // Get groups 
$championship->groupsByRound($numRound = 1); // Get groups for a specific round
$championship->groupsFromRound($numRound = 1); // Get groups from a specific round
$championship->fights; // Get fights
$championship->firstRoundFights; // Get fights for the first round only ( Useful when has preliminary )
$championship->fights($numRound = 1); // Get fights for a specific round

NOTE: $fighter can be an instance of Team or Competitor, (*15)

Determine strategy:, (*16)

$championship->isPlayoffCompetitor()
$championship->isPlayoffTeam()
$championship->isSingleEliminationCompetitor()
$championship->isSingleEliminationTeam()

Determine group size:, (*17)

$championship->getGroupSize()

Determine championship type:, (*18)

$championship->hasPreliminary()
$championship->isPlayOffType()
$championship->isSingleEliminationType()

FightersGroup

$group->championship; // Get championship
$group->fights; // Get fights
$group->fighters; // Get fighters
$group->teams; // Get teams
$group->competitors; // Get competitors
$group->users; // Get users

NOTE: $fighter can be an instance of Team or Competitor, (*19)

To get the instance name:, (*20)

$group->getFighterType() // Should return Team::class or Competitor::class

NOTE: This plugin use laravel-nestedset. This means you can navigate with $group->children() or $group->parent() or use any methods available in this great plugin., (*21)

Competitor

$competitor->user; // Get user

Team

// Create a team

$team = factory(Team::class)
    ->create([ championship_id' => $championship->id]);
// Add competitor to team 

$team->competitors()->attach($competitor->id);

// Remove competitor from a team 

$team->competitors()->detach($competitor->id);

Fight

$fight->group; // Get group
$fight->competitor1; // Get competitor1
$fight->competitor2; // Get competitor2
$fight->team1; // Get team1
$fight->team2; // Get team2

Views

Preliminary tree, (*22)

@include('laravel-tournaments::partials.tree.preliminary') // Preliminary table

Single Elimination tree, (*23)

@include('laravel-tournaments::partials.tree.singleElimination', ['hasPreliminary' => 0]) 

Fight List, (*24)

@include('laravel-tournaments::partials.fights')

Run Functional Tests

vendor/bin/phpunit tests, (*25)

Limitations

This is a work in progress, and tree creation might be very complex, so there is a bunch of things to achieve., (*26)

  • Seed fighter
  • Manage more than 1 fighter out of preliminary round
  • Modify Preliminary Round generation on the fly
  • Use any number of area ( restricted to 1,2,4,8)
  • Manage n+1 case : When for instance, there is 17 competitors in a direct elimination tree, there will have 15 BYES. We can improve that making the first match with 3 competitors.
  • Double elimination

Troubleshooting

Specified key was too long error

For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations: As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:, (*27)

use Illuminate\Support\Facades\Schema;

public function boot()
{
Schema::defaultStringLength(191);
}

With this configuration, you must have at least...

This error means you don't have enough competitors / teams to create given tree Try to increase competitor number, decrease areas or preliminary group size, if preliminary round is active, (*28)

ChangeLog:

  • v0.17: Update to Laravel 8
  • v0.16: Update to Laravel 5.8
  • v0.15: Update to Laravel 5.7
  • v0.14: Update to Laravel 5.6 / PHP 7.2 support
  • v0.13: Manage third place fight
  • v0.12: Update to Laravel 5.5
  • v0.11: Initial Version

The Versions

03/05 2018

dev-master

9999999-dev https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

MIT Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

02/04 2018

dev-analysis-q1e9W5

dev-analysis-q1e9W5 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

MIT

The Requires

 

The Development Requires

by juliatzin

02/04 2018

dev-analysis-XVWJD3

dev-analysis-XVWJD3 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

MIT

The Requires

 

The Development Requires

by juliatzin

01/04 2018

dev-analysis-zEd3ay

dev-analysis-zEd3ay https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

MIT

The Requires

 

The Development Requires

by juliatzin

01/04 2018

dev-analysis-8KWb92

dev-analysis-8KWb92 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

MIT

The Requires

 

The Development Requires

by juliatzin

01/04 2018

0.13.3

0.13.3.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

31/03 2018

0.13.2

0.13.2.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

07/11 2017

dev-analysis-qr05WQ

dev-analysis-qr05WQ https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

07/11 2017

0.13.1

0.13.1.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

21/09 2017

dev-develop

dev-develop https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

10/09 2017
10/09 2017

dev-thirdPlace

dev-thirdPlace https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

09/09 2017

0.12.5

0.12.5.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

08/09 2017

0.12.4

0.12.4.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

08/09 2017

0.12.3

0.12.3.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

02/09 2017

dev-winners

dev-winners https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

02/09 2017

0.12.2

0.12.2.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

02/09 2017

0.12.1

0.12.1.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

01/09 2017

dev-laravel54

dev-laravel54 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

01/09 2017

0.11.19

0.11.19.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

01/09 2017

dev-larave55

dev-larave55 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

01/09 2017
01/09 2017

0.11.x-dev

0.11.9999999.9999999-dev https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin

27/08 2017

0.11.18

0.11.18.0 https://github.com/xoco70/laravel-tournaments

A Laravel 5.4+ Package that allows you to generate Tournaments tree

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

by juliatzin