tonystore/laravel-round-robin

Laravel 包,用于使用轮询算法生成抽奖活动。

v0.1.1 2022-03-27 01:56 UTC

This package is auto-updated.

Last update: 2024-09-27 08:49:32 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

Laravel 包,用于使用轮询算法生成抽奖活动。支持任意数量的队伍,只要它们大于配置文件中指定的最小值。使用 Laravel Collections 构建以更好地处理数组。

要求

通过 Composer 安装

步骤 1: Composer

在控制台运行以下命令。

composer require tonystore/laravel-round-robin

步骤 2: 发布配置文件

发布配置文件

php artisan vendor:publish --provider="Tonystore\LaravelRoundRobin\LaravelRoundRobinProvider" --tag=round-robin

在您的配置文件中,您可以定义以下内容

<?php

return [
     /**
     *----------------------------------------------------------------------
     * Minimum number of teams to generate a schedule
     *----------------------------------------------------------------------
     */
    'min_teams' => 2,
    /**
     *----------------------------------------------------------------------
     * Custom name for the first phase of the schedule.
     *----------------------------------------------------------------------
     */
    'one_phase' => 'one',
    /**
     *----------------------------------------------------------------------
     * Custom name for the return phase of the schedule.
     *----------------------------------------------------------------------
     */
    'way_phase' => 'way',
]

使用方法

如果您传递一个设备数组,它将返回一个数组,其中包含一个对象数组。对于每个对象,您将拥有主队、客队以及它所属的轮次

['BSC','CSE','LDU','IDV'];

[
  [
    {
      "phase": "one",
      "round": 1,
      "local": "BSC",
      "visitor": "IDV"
    },
    {
      "phase": "one",
      "round": 1,
      "local": "LDU",
      "visitor": "CSE"
    }
  ],
  [
    {
      "phase": "one",
      "round": 2,
      "local": "IDV",
      "visitor": "LDU"
    },
    {
      "phase": "one",
      "round": 2,
      "local": "BSC",
      "visitor": "CSE"
    }
  ],
  [
    {
      "phase": "one",
      "round": 3,
      "local": "CSE",
      "visitor": "IDV"
    },
    {
      "phase": "one",
      "round": 3,
      "local": "BSC",
      "visitor": "LDU"
    }
  ],
]

您可以使用此包的几种方式

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = new RoundRobin($teams);
$schedule->schedule();

使用静态函数

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::addTeams($teams)->schedule();

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::makeSchedule($teams, null, true, null, false);

使用辅助函数

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

schedule($teams, null, true, null, false);

生成不重新排列队伍的赛程

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::addTeams($teams)->doNotShuffle()->schedule();

使用种子重新排列队伍以生成日历

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::addTeams($teams)->shuffle(12)->schedule();

任何可用选项都将生成一组现成的轮次,您可以任意操作。

生成不重新排列队伍的赛程

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::addTeams($teams)->schedule();

$schedule->first(); //It will return the first round available on the connection.

$schedule->last(); //It will return the last round available on the connection.

您还可以使用 Laravel Collections 中的所有可用选项。此外,我们添加了一个将轮次转换为对象的集合,您可以使用以下方式使用它。

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::addTeams($teams)->schedule()->toObject();

$schedule[0][0]->local; //It will return the name of the home team, of the first game, of the first available round.

还有生成往返轮次选项。示例

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::addTeams($teams)->doubleRound()->schedule();

您可以按可用阶段过滤日历。示例

$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE'];

$schedule = RoundRobin::addTeams($teams)->doubleRound()->schedule(); 

$firstLeg = $schedule->firstLeg(); //Will return only for the first leg.

$secondLeg = $schedule->secondLeg(); //Will return only for the second leg.

即将推出:Laravel 锦标赛