|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TournamentGenerator; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use JsonSerializable; |
|
9
|
|
|
use TournamentGenerator\Containers\HierarchyContainer; |
|
10
|
|
|
use TournamentGenerator\Export\ExporterInterface; |
|
11
|
|
|
use TournamentGenerator\Interfaces\Exportable; |
|
12
|
|
|
use TournamentGenerator\Interfaces\WithGames as WithGamesInterface; |
|
13
|
|
|
use TournamentGenerator\Interfaces\WithTeams as WithTeamsInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class HierarchyBase |
|
17
|
|
|
* |
|
18
|
|
|
* Extended base for hierarchy objects (Tournament, Category, Round, Group). |
|
19
|
|
|
* |
|
20
|
|
|
* @package TournamentGenerator |
|
21
|
|
|
* @author Tomáš Vojík <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class HierarchyBase extends Base implements Exportable, JsonSerializable |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
protected HierarchyContainer $container; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get the hierarchy container |
|
30
|
|
|
* |
|
31
|
|
|
* @return HierarchyContainer |
|
32
|
|
|
*/ |
|
33
|
191 |
|
public function getContainer() : HierarchyContainer { |
|
34
|
191 |
|
return $this->container; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Insert into hierarchical container |
|
39
|
|
|
* |
|
40
|
|
|
* @param Base $object |
|
41
|
|
|
* |
|
42
|
|
|
* @post Object is added to hierarchy |
|
43
|
|
|
* @post If the object has teams -> add other team container to hierarchy |
|
44
|
|
|
* @post If the object has games -> add other game container to hierarchy |
|
45
|
|
|
* |
|
46
|
|
|
* @return $this |
|
47
|
|
|
* @throws Exception |
|
48
|
|
|
*/ |
|
49
|
178 |
|
public function insertIntoContainer(Base $object) : Base { |
|
50
|
178 |
|
$this->container->insert($object); |
|
51
|
178 |
|
if ($this instanceof WithGamesInterface && $object instanceof WithGamesInterface) { |
|
52
|
178 |
|
$this->addGameContainer($object->getGameContainer()); |
|
53
|
|
|
} |
|
54
|
178 |
|
if ($this instanceof WithTeamsInterface && $object instanceof WithTeamsInterface) { |
|
55
|
178 |
|
$this->addTeamContainer($object->getTeamContainer()); |
|
56
|
|
|
} |
|
57
|
178 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Prepares a general hierarchy exporter for this hierarchy class |
|
62
|
|
|
* |
|
63
|
|
|
* @return ExporterInterface |
|
64
|
|
|
*/ |
|
65
|
9 |
|
public function export() : ExporterInterface { |
|
66
|
9 |
|
return Export\Hierarchy\Exporter::start($this); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |