xoco70/laravel-tournaments

一个 Laravel 5.4+ 的包,允许您生成锦标赛树

0.17 2023-09-19 09:17 UTC

README


Laravel Tournaments
Laravel Tournaments

一个生成即用的 Laravel 插件,用于生成锦标赛

Latest Stable Version Total Downloads Scrutinizer Code Quality Build Status Code Coverage


Laravel Tournaments Demo

功能

  • 单淘汰树生成
  • 带预选赛的单淘汰生成
  • 季后赛生成
  • 季军争夺战
  • 比赛列表生成
  • 自定义预选赛大小
  • 自定义区域数量(1、2、4、8)
  • 动态修改单淘汰树生成
  • 使用队伍而非竞争者

安装

注意:根据您的 Laravel 版本,您应该安装不同版本的包

首先,您需要通过 Composer 安装包

composer require "xoco70/laravel-tournaments"

最后,再次从命令行发布默认配置文件

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

演示

要运行演示,您需要生成锦标赛、锦标赛、用户、竞争者和设置

运行迁移

php artisan migrate
composer dump-autoload

播种模拟数据

php artisan db:seed --class=LaravelTournamentSeeder

警告:不要在生产环境中做这件事,它将清除所有数据。仅限演示使用此行

添加 TreeController(您可以在 演示仓库 中找到)

添加自定义路由

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

您可以在 http://yourdomain.com/ 访问演示

用法

// 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();

数据模型

Database Model

模型

锦标赛

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

检查锦标赛类型

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

检查锦标赛级别

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

锦标赛

$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

注意:$fighter 可以是 TeamCompetitor 的实例

确定策略

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

确定小组规模

$championship->getGroupSize()

确定锦标赛类型

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

竞争者组

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

注意:$fighter 可以是 TeamCompetitor 的实例

获取实例名称

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

注意:此插件使用 laravel-nestedset。这意味着您可以使用 $group->children()$group->parent() 或使用此插件中提供的任何方法进行导航。

竞争者

$competitor->user; // Get user

队伍

// 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->group; // Get group
$fight->competitor1; // Get competitor1
$fight->competitor2; // Get competitor2
$fight->team1; // Get team1
$fight->team2; // Get team2

视图

预选树

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

单淘汰树

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

战斗列表

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

运行功能测试

vendor/bin/phpunit tests

限制

这是一个进行中的项目,创建树可能非常复杂,因此还有很多事情要做。

  • 播种竞争者
  • 管理预选赛外的多个竞争者
  • 动态修改预选赛生成
  • 使用任意数量的区域(限于1、2、4、8)
  • 管理 n+1 的情况:当在直接淘汰树中有17名竞争者时,将有15名 BYES。我们可以通过使第一场比赛有3名竞争者来改进这一点。
  • 双淘汰

故障排除

指定的键太长错误

对于运行 MariaDB 或 MySQL 较旧版本的您,在尝试运行迁移时可能会遇到此错误:如 迁移指南 中所述,要修复此问题,您只需编辑您的 AppServiceProvider.php 文件,并在 boot 方法中设置默认字符串长度

use Illuminate\Support\Facades\Schema;

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

使用此配置,您至少需要...

此错误表示您没有足够的竞争者/队伍来创建给定的树。尝试增加竞争者数量,减少区域或预选小组规模,如果预选赛处于活动状态。

变更日志

  • 0.17版本:升级到Laravel 8
  • 0.16版本:升级到Laravel 5.8
  • 0.15版本:升级到Laravel 5.7
  • 0.14版本:更新到Laravel 5.6 / 支持 PHP 7.2
  • 0.13版本:管理第三名争夺战
  • 0.12版本:升级到Laravel 5.5
  • 0.11版本:初始版本