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