xoco70 / kendo-tournaments
一个 Laravel 5.4+ 包,允许您生成锦标赛树
Requires
- php: >=7.4
- kalnoy/nestedset: ^6.0
- laravel/legacy-factories: ^1.3
Requires (Dev)
- fzaninotto/faker: 1.*
- laravel/browser-kit-testing: ^6.0
- orchestra/database: ~6.1
- orchestra/testbench-browser-kit: ~6.0
- phpunit/phpunit: ^8.5
- symfony/var-dumper: ~5.0
- dev-master
- 0.17
- 0.16
- 0.15
- 0.14.3
- 0.14.2
- 0.14.1
- 0.14.0
- 0.13.3
- 0.13.2
- 0.13.1
- 0.13
- 0.12.5
- 0.12.4
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12
- 0.11.19
- 0.11.18
- dev-laravel8
- dev-dependabot/composer/league/flysystem-1.1.4
- dev-dependabot/composer/laravel/framework-7.30.3
- dev-dependabot/composer/symfony/http-kernel-5.1.5
- dev-laravel7
- dev-dependabot/composer/symfony/http-foundation-4.4.7
- dev-develop
This package is auto-updated.
Last update: 2024-09-19 11:34:28 UTC
README
Laravel Tournaments
一个一键生成锦标赛的 Laravel 插件
特性
- 单淘汰树生成
- 带有预选赛的单淘汰赛生成
- 淘汰赛生成
- 季军赛
- 比赛列表生成
- 自定义预选赛规模
- 自定义区域数量(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();
数据模型
模型
锦标赛
$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 可以是
Team
或Competitor
的实例
确定策略
$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 可以是
Team
或Competitor
的实例
获取实例名称
$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); }
使用此配置,您至少需要...
此错误意味着您没有足够的竞争者/队伍来创建给定的树。尝试增加竞争者数量,减少区域或预选组大小,如果预选赛是激活的
变更日志
- v0.17: 升级到 Laravel 8
- v0.16: 升级到 Laravel 5.8
- v0.15: 升级到 Laravel 5.7
- v0.14: 升级至 Laravel 5.6 / PHP 7.2 支持
- v0.13: 管理第三场战斗
- v0.12: 升级至 Laravel 5.5
- v0.11: 初版