|
1
|
|
|
<?php |
|
2
|
|
|
/** @noinspection PhpDocFieldTypeMismatchInspection */ |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
namespace TournamentGenerator\Export\Single; |
|
6
|
|
|
|
|
7
|
|
|
use TournamentGenerator\Export\ExporterInterface; |
|
8
|
|
|
use TournamentGenerator\Export\Modifiers\WithScoresModifier; |
|
9
|
|
|
use TournamentGenerator\Export\SingleExporterBase; |
|
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 SingleExporterBase |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** @var Team */ |
|
26
|
|
|
protected WithId $object; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* SingleTeamExporter constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param Team $team |
|
32
|
|
|
* |
|
33
|
|
|
* @noinspection MagicMethodsValidityInspection |
|
34
|
|
|
* @noinspection PhpMissingParentConstructorInspection |
|
35
|
|
|
*/ |
|
36
|
30 |
|
public function __construct(Team $team) { |
|
37
|
30 |
|
$this->object = $team; |
|
38
|
30 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Simple export query without any modifiers |
|
42
|
|
|
* |
|
43
|
|
|
* @param Team $object |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
8 |
|
public static function export(WithId $object) : array { |
|
48
|
8 |
|
return self::start($object)->get(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Start an export query |
|
53
|
|
|
* |
|
54
|
|
|
* @param Team $object |
|
55
|
|
|
* |
|
56
|
|
|
* @return ExporterInterface |
|
57
|
|
|
*/ |
|
58
|
16 |
|
public static function start(WithId $object) : ExporterInterface { |
|
59
|
16 |
|
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
|
17 |
|
public static function exportBasic(WithId $object) : array { |
|
70
|
17 |
|
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
|
30 |
|
public function getBasic() : array { |
|
84
|
|
|
return [ |
|
85
|
30 |
|
'object' => $this->object, // Passed for reference in the modifier methods |
|
86
|
30 |
|
'id' => $this->object->getId(), |
|
87
|
30 |
|
'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
|
8 |
|
public function withScores() : TeamExporter { |
|
98
|
8 |
|
$this->modifiers[] = WithScoresModifier::class; |
|
99
|
8 |
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
} |