Skip to content

Commit

Permalink
✨ Custom points for progressions
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Vojík <vojik@wboy.cz>
  • Loading branch information
Heroyt committed Apr 29, 2023
1 parent 6adba7f commit 464f46a
Show file tree
Hide file tree
Showing 9 changed files with 950 additions and 869 deletions.
Binary file modified build/coverage.serialized
Binary file not shown.
926 changes: 479 additions & 447 deletions build/coverage.xml

Large diffs are not rendered by default.

456 changes: 227 additions & 229 deletions src/TournamentGenerator/Export/Hierarchy/SetupExporter.php

Large diffs are not rendered by default.

53 changes: 31 additions & 22 deletions src/TournamentGenerator/Import/ImportValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,21 @@ class ImportValidator
'default' => 0,
],
'groups' => [
'type' => 'array',
'subtype' => 'id',
'reference' => 'groups',
],
],
],
'progressed' => [
'type' => 'bool',
'default' => false,
],
],
'type' => 'array',
'subtype' => 'id',
'reference' => 'groups',
],
],
],
'progressed' => [
'type' => 'bool',
'default' => false,
],
'points' => [
'type' => ['int', 'null'],
'default' => null,
],
],
],
'teams' => [
'type' => 'array',
Expand Down Expand Up @@ -542,17 +546,22 @@ public static function validateType($var, array $keys, string ...$types) : void
return;
}
break;
case 'id':
if (is_int($var) || is_string($var)) {
return;
}
break;
case 'bool':
if (is_bool($var)) {
return;
}
break;
}
case 'id':
if (is_int($var) || is_string($var)) {
return;
}
break;
case 'bool':
if (is_bool($var)) {
return;
}
break;
case 'null':
if (is_null($var)) {
return;
}
break;
}
}
throw new InvalidImportDataException('Invalid data type for: '.implode('->', $keys).'. Expected '.implode('|', $types).'.');
}
Expand Down
22 changes: 13 additions & 9 deletions src/TournamentGenerator/Import/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,21 @@ protected static function createProgressions(array $progressions, array $allGrou
$filterSetting = (array) $filterSetting;

self::$groups = array_map(static function($groupId) use ($allGroups) {
return $allGroups[$groupId] ?? null;
}, $filterSetting['groups'] ?? []);
return $allGroups[$groupId] ?? null;
}, $filterSetting['groups'] ?? []);

$filter = new TeamFilter($filterSetting['what'] ?? 'points', $filterSetting['how'] ?? '>', $filterSetting['val'] ?? 0, self::$groups);
$progression->addFilter($filter);
}
$filter = new TeamFilter($filterSetting['what'] ?? 'points', $filterSetting['how'] ?? '>', $filterSetting['val'] ?? 0, self::$groups);
$progression->addFilter($filter);
}

if (isset($setting['progressed'])) {
$progression->setProgressed($setting['progressed']);
}
}
if (isset($setting['progressed'])) {
$progression->setProgressed($setting['progressed']);
}

if (isset($settings['points'])) {
$progression->setPoints($settings['points']);
}
}
}
}

Expand Down
84 changes: 53 additions & 31 deletions src/TournamentGenerator/Progression.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@ class Progression

/** @var Group What group to progress from */
protected Group $from;
/** @var Group What group to progress to */
protected Group $to;
/** @var int Offset to start picking teams */
protected int $start;
/** @var int|null Maximum number of teams to progress */
protected ?int $len;
/** @var TeamFilter[] Filters to use */
protected array $filters = [];
/** @var bool If the progression was already called */
protected bool $progressed = false;

/**
* Progression constructor.
*
* @param Group $from What group to progress from
* @param Group $to What group to progress to
* @param int $start Offset to start picking teams
* @param int|null $len Maximum number of teams to progress
*/
public function __construct(Group $from, Group $to, int $start = 0, ?int $len = null) {
/** @var Group What group to progress to */
protected Group $to;
/** @var int Offset to start picking teams */
protected int $start;
/** @var int|null Maximum number of teams to progress */
protected ?int $len;
/** @var TeamFilter[] Filters to use */
protected array $filters = [];
/** @var bool If the progression was already called */
protected bool $progressed = false;

/**
* @var int|null Custom points for progression
* @package TournamentGenerator
*/
protected ?int $points = null;

/**
* Progression constructor.
*
* @param Group $from What group to progress from
* @param Group $to What group to progress to
* @param int $start Offset to start picking teams
* @param int|null $len Maximum number of teams to progress
*/
public function __construct(Group $from, Group $to, int $start = 0, ?int $len = null) {
$this->from = $from;
$this->to = $to;
$this->start = $start;
Expand Down Expand Up @@ -102,7 +108,7 @@ public function progress(bool $blank = false) : Progression {
$this->to->addTeam(new BlankTeam($this.' - '.$i++, $team, $this->from, $this));
}
else {
$team->addPoints($this->from->getProgressPoints());
$team->addPoints($this->points ?? $this->from->getProgressPoints());
}
}

Expand Down Expand Up @@ -176,15 +182,31 @@ public function setFilters(array $filters) : Progression {
/**
* @return bool
*/
public function isProgressed() : bool {
return $this->progressed;
}

/**
* @param bool $progressed
*/
public function setProgressed(bool $progressed) : void {
$this->progressed = $progressed;
}
public function isProgressed(): bool {
return $this->progressed;
}

/**
* @param bool $progressed
*/
public function setProgressed(bool $progressed): void {
$this->progressed = $progressed;
}

/**
* @return int|null
*/
public function getPoints(): ?int {
return $this->points;
}

/**
* @param int|null $points
* @return Progression
*/
public function setPoints(?int $points): Progression {
$this->points = $points;
return $this;
}

}
66 changes: 35 additions & 31 deletions tests/Export/Hierarchy/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,37 +247,41 @@ private function tournamentSetup(bool $withSecondRound = false, bool $withScores
],
'progressions' => [
(object) [
'from' => 1,
'to' => 3,
'offset' => 0,
'length' => 2,
'progressed' => false,
'filters' => [],
],
(object) [
'from' => 1,
'to' => 4,
'offset' => -2,
'length' => null,
'progressed' => false,
'filters' => [],
],
(object) [
'from' => 2,
'to' => 3,
'offset' => 0,
'length' => 2,
'progressed' => false,
'filters' => [],
],
(object) [
'from' => 2,
'to' => 4,
'offset' => -2,
'length' => null,
'progressed' => false,
'filters' => [],
],
'from' => 1,
'to' => 3,
'offset' => 0,
'length' => 2,
'progressed' => false,
'filters' => [],
'points' => null,
],
(object)[
'from' => 1,
'to' => 4,
'offset' => -2,
'length' => null,
'progressed' => false,
'filters' => [],
'points' => null,
],
(object)[
'from' => 2,
'to' => 3,
'offset' => 0,
'length' => 2,
'progressed' => false,
'filters' => [],
'points' => null,
],
(object)[
'from' => 2,
'to' => 4,
'offset' => -2,
'length' => null,
'progressed' => false,
'filters' => [],
'points' => null,
],
],
];

Expand Down
Loading

0 comments on commit 464f46a

Please sign in to comment.