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