1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TournamentGenerator\Traits; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use TournamentGenerator\Containers\ContainerQuery; |
8
|
|
|
use TournamentGenerator\Interfaces\WithRounds as WithRoundsInterface; |
9
|
|
|
use TournamentGenerator\Interfaces\WithSkipSetters as WithSkipSettersInterface; |
10
|
|
|
use TournamentGenerator\Round; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Trait WithRounds |
14
|
|
|
* |
15
|
|
|
* @package TournamentGenerator\Traits |
16
|
|
|
* @author Tomáš Vojík <[email protected]> |
17
|
|
|
* @since 0.4 |
18
|
|
|
*/ |
19
|
|
|
trait WithRounds |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Adds round to the category |
24
|
|
|
* |
25
|
|
|
* @param Round ...$rounds One or more round objects |
26
|
|
|
* |
27
|
|
|
* @return $this |
28
|
|
|
*/ |
29
|
2 |
|
public function addRound(Round ...$rounds) : WithRoundsInterface { |
30
|
2 |
|
foreach ($rounds as $round) { |
31
|
2 |
|
$this->insertIntoContainer($round); |
32
|
|
|
} |
33
|
2 |
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Creates a new round and adds it to the category |
38
|
|
|
* |
39
|
|
|
* @param string $name Round name |
40
|
|
|
* @param string|int|null $id Round id - if omitted -> it is generated automatically as unique string |
41
|
|
|
* |
42
|
|
|
* @return Round The newly created round |
43
|
|
|
*/ |
44
|
96 |
|
public function round(string $name = '', $id = null) : Round { |
45
|
96 |
|
$r = new Round($name, $id); |
46
|
96 |
|
if ($this instanceof WithSkipSettersInterface) { |
47
|
96 |
|
$r->setSkip($this->getSkip()); |
48
|
|
|
} |
49
|
96 |
|
$this->insertIntoContainer($r); |
50
|
96 |
|
return $r; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get all rounds in this category |
55
|
|
|
* |
56
|
|
|
* @return Round[] |
57
|
|
|
*/ |
58
|
31 |
|
public function getRounds() : array { |
59
|
31 |
|
return $this->container->getHierarchyLevel(Round::class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get rounds container query |
64
|
|
|
* |
65
|
|
|
* @return ContainerQuery |
66
|
|
|
*/ |
67
|
3 |
|
public function queryRounds() : ContainerQuery { |
68
|
3 |
|
return $this->container->getHierarchyLevelQuery(Round::class); |
69
|
|
|
} |
70
|
|
|
} |