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