|
1
|
|
|
<?php |
|
2
|
|
|
/** @noinspection PhpDocFieldTypeMismatchInspection */ |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
namespace TournamentGenerator\Export\Hierarchy; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use TournamentGenerator\Export\Export; |
|
9
|
|
|
use TournamentGenerator\Export\ExportBase; |
|
10
|
|
|
use TournamentGenerator\Export\Modifiers\WithScoresModifier; |
|
11
|
|
|
use TournamentGenerator\Export\Single\TeamExporter; |
|
12
|
|
|
use TournamentGenerator\HierarchyBase; |
|
13
|
|
|
use TournamentGenerator\Interfaces\WithId; |
|
14
|
|
|
use TournamentGenerator\Interfaces\WithTeams; |
|
15
|
|
|
use TournamentGenerator\Team; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Exporter for teams |
|
19
|
|
|
* |
|
20
|
|
|
* A specific exporter for teams and their related data. Exports all teams from a hierarchy object. |
|
21
|
|
|
* |
|
22
|
|
|
* @package TournamentGenerator\Export |
|
23
|
|
|
* @author Tomáš Vojík <[email protected]> |
|
24
|
|
|
* @since 0.5 |
|
25
|
|
|
*/ |
|
26
|
|
|
class TeamsExporter extends ExportBase |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
/** @var WithTeams */ |
|
30
|
|
|
protected WithId $object; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* TeamExporter constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param HierarchyBase $object |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(HierarchyBase $object) { |
|
38
|
|
|
if (!$object instanceof WithTeams) { |
|
39
|
|
|
throw new InvalidArgumentException('Object must be instance of WithTeams.'); |
|
40
|
|
|
} |
|
41
|
|
|
parent::__construct($object); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Simple export query without any modifiers |
|
46
|
|
|
* |
|
47
|
|
|
* @param HierarchyBase $object |
|
48
|
|
|
* |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function export(WithId $object) : array { |
|
52
|
|
|
return self::start($object)->get(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Start an export query |
|
57
|
|
|
* |
|
58
|
|
|
* @param HierarchyBase $object |
|
59
|
|
|
* |
|
60
|
|
|
* @return Export |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function start(WithId $object) : Export { |
|
63
|
|
|
return new self($object); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Gets the basic unmodified data |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getBasic() : array { |
|
72
|
|
|
return array_map(static function(Team $team) { |
|
73
|
|
|
return (object) TeamExporter::exportBasic($team); |
|
74
|
|
|
}, $this->object->getTeams()); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @defgroup TeamExporterQueryModifiers Query modifiers |
|
79
|
|
|
* @brief Modifier methods for the query |
|
80
|
|
|
*/ |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Include team scores in the result set |
|
84
|
|
|
* |
|
85
|
|
|
* @return TeamsExporter |
|
86
|
|
|
* @ingroup TeamExporterQueryModifiers |
|
87
|
|
|
*/ |
|
88
|
|
|
public function withScores() : TeamsExporter { |
|
89
|
|
|
$this->modifiers[] = WithScoresModifier::class; |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
} |