GithubHelp home page GithubHelp logo

xoco70 / laravel-tournaments Goto Github PK

View Code? Open in Web Editor NEW
228.0 17.0 52.0 3.37 MB

Laravel Package that allows you to generate customizable tournaments trees. - This project repo is no longer being maintained

License: GNU General Public License v3.0

PHP 86.76% CSS 1.91% Blade 11.34%
tournament laravel-5-package tree-structure laravel kendo generator sports php

laravel-tournaments's Introduction


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


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:

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:

composer require "xoco70/laravel-tournaments"

Finally, from the command line again, publish the default configuration file:

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

Demo

To run the demo, you need to generate Tournaments, Championships, Users, Competitors and Settings

Run Migrations:

php artisan migrate
composer dump-autoload

Seed dummy data:

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

Add TreeController ( you can find it in demo repository)

Add your custom routes

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/

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

Models

Tournament

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

Check tournament type:

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

Check tournament level:

$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

Determine strategy:

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

Determine group size:

$championship->getGroupSize()

Determine championship type:

$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

To get the instance name:

$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.

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

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

Single Elimination tree

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

Fight List

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

Run Functional Tests

vendor/bin/phpunit tests

Limitations

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

  • 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:

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

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

laravel-tournaments's People

Contributors

dependabot[bot] avatar jrhenderson1988 avatar romangorbatko avatar scrutinizer-auto-fixer avatar xoco70 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-tournaments's Issues

Error - Your requirements could not be resolved to an installable set of packages.

I tried installing this package using the latest version of Laravel 8.76.2 and also Laravel version 7.29. However, each time I try to install this package I get the following error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - kalnoy/nestedset[v4.3.5, ..., v4.x-dev] require illuminate/support ~5.7.0|~5.8.0 -> found illuminate/support[v5.7.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.
    - kalnoy/nestedset[v4.3.0, ..., v4.3.1] require illuminate/support 5.2 - 5.5 -> found illuminate/support[v5.2.0, ..., 5.5.x-dev] but these were not loaded, likely because it conflicts with another require.
    - kalnoy/nestedset v4.3.2 requires illuminate/support 5.2 - 5.6 -> found illuminate/support[v5.2.0, ..., 5.6.x-dev] but these were not loaded, likely because it conflicts with another require.
    - kalnoy/nestedset v4.3.3 requires illuminate/support 5.2 - 5.7 -> found illuminate/support[v5.2.0, ..., 5.7.x-dev] but these were not loaded, likely because it conflicts with another require.
    - kalnoy/nestedset v4.3.4 requires illuminate/support 5.2 - 5.8 -> found illuminate/support[v5.2.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.
    - xoco70/laravel-tournaments 0.16 requires kalnoy/nestedset ^4.3 -> satisfiable by kalnoy/nestedset[v4.3.0, ..., v4.x-dev].
    - Root composer.json requires xoco70/laravel-tournaments ^0.16.0 -> satisfiable by xoco70/laravel-tournaments[0.16].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require xoco70/laravel-tournaments:*" to figure out if any version is installable, or "composer require xoco70/laravel-tournaments:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

I'd appreciate some direction on have to resolve these errors.

Thank you.

Need For Laravel 7

I need to use it for the Laravel 7 version. Would you please upgrade the version!
Now, during installation, I am getting this error-
- Installation request for xoco70/laravel-tournaments ^0.16.0 -> satisfiable by xoco70/laravel-tournaments[0.16].

Demo site is down.

Noticed the Demo site is down. Saw issues a few issues about it from before aswell..

Any chance to get it up again?

Demo doesnt works

I tried to check your demo site here : https://demo.kendozone.com/laravel-tournaments

Then I gave this error :

ErrorException (E_ERROR) Undefined offset: 0 (View: /home/forge/demo.kendozone.com/vendor/xoco70/laravel-tournaments/resources/views/partials/tree/singleElimination.blade.php) (View: /home/forge/demo.kendozone.com/vendor/xoco70/laravel-tournaments/resources/views/partials/tree/singleElimination.blade.php)

Manage n+1 case

When there is, for instance, 17 competitors in a direct elimination tree, there will have 15 BYES. We can improve that making the first match with 3 competitors.

You can use this technique to decrease number of BYES on the tree.

Use any number of area ( restricted to 1,2,4,8)

Right now, you can only use 1,2,4,or 8 areas.

But in real life, it is possible to have a championship happening on 5 areas.

This complexifies pretty much how match are distributed among groups.

Bye group problem

image
When I try to make a tournament with only 3 competitors. The third user does not go up to final round automatically after tree generation. This only seems to happens when 2nd round is final round however every other cases are working fine. Please see the image I attached.

404 after install

Hello,

First of all thank you for all your effort :)

I followed the following instructions :

composer create-project laravel/laravel "My Web Dir" 5.8 --prefer-dist
++ Set the .env file DB and URL
php artisan key:generate
I have set IIS to have the home dir : MyWebDir/Public and if I request the page I get the Welcome screen

composer require "xoco70/laravel-tournaments"
php artisan vendor:publish --tag=laravel-tournaments --force
php artisan migrate
composer dump-autoload

Demo data : php artisan db:seed --class=LaravelTournamentSeeder (to get going)

Then I got to : http://url/laravel-tournaments and then I receive an 404 page not found.....

Feature: Seeds fighter

It would be great to be able to seed a list of fighters (2,4,8,16)

Seed should work following those rules:

  1. Spread seed over fight areas
  2. If numSeed > numAreas, spread seed inside one area
  3. Those rules should have priority over entities repartition ( club, region, country, etc )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.