1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 12/4/17 |
7
|
|
|
* Time: 10:49 PM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Entity\Traits; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
14
|
|
|
use Doctrine\Common\Collections\Collection; |
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
16
|
|
|
use Tfboe\FmLib\Entity\Helpers\ResultEntity; |
17
|
|
|
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyInterface; |
18
|
|
|
use Tfboe\FmLib\Entity\MatchInterface; |
19
|
|
|
use Tfboe\FmLib\Entity\Player; |
20
|
|
|
use Tfboe\FmLib\Helpers\Level; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Trait Game |
25
|
|
|
* @package Tfboe\FmLib\Entity\Traits |
26
|
|
|
*/ |
27
|
|
|
trait Game |
28
|
|
|
{ |
29
|
|
|
use ResultEntity; |
30
|
|
|
|
31
|
|
|
//<editor-fold desc="Fields"> |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\ManyToOne(targetEntity="\Tfboe\FmLib\Entity\MatchInterface", inversedBy="games") |
35
|
|
|
* @var MatchInterface |
36
|
|
|
*/ |
37
|
|
|
private $match; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\ManyToMany(targetEntity="\Tfboe\FmLib\Entity\Player", indexBy="id") |
41
|
|
|
* @ORM\JoinTable(name="relation__game_playersA", |
42
|
|
|
* joinColumns={@ORM\JoinColumn(name="game_id", referencedColumnName="id")}, |
43
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="player_id", referencedColumnName="player_id")}) |
44
|
|
|
* @var Collection|Player |
45
|
|
|
*/ |
46
|
|
|
private $playersA; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @ORM\ManyToMany(targetEntity="\Tfboe\FmLib\Entity\Player", indexBy="id") |
50
|
|
|
* @ORM\JoinTable(name="relation__game_playersB", |
51
|
|
|
* joinColumns={@ORM\JoinColumn(name="game_id", referencedColumnName="id")}, |
52
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="player_id", referencedColumnName="player_id")}) |
53
|
|
|
* @var Collection|Player |
54
|
|
|
*/ |
55
|
|
|
private $playersB; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @ORM\Column(type="integer") |
59
|
|
|
* @var int |
60
|
|
|
*/ |
61
|
|
|
private $gameNumber; |
62
|
|
|
//</editor-fold desc="Fields"> |
63
|
|
|
|
64
|
|
|
//<editor-fold desc="Public Methods"> |
65
|
|
|
/** |
66
|
|
|
* @inheritDoc |
67
|
|
|
*/ |
68
|
|
|
public function getChildren(): Collection |
69
|
|
|
{ |
70
|
|
|
return new ArrayCollection(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
|
|
public function getGameNumber(): int |
77
|
|
|
{ |
78
|
|
|
return $this->gameNumber; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @inheritDoc |
83
|
|
|
*/ |
84
|
|
|
public function getLevel(): int |
85
|
|
|
{ |
86
|
|
|
return Level::GAME; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritDoc |
91
|
|
|
*/ |
92
|
|
|
public function getLocalIdentifier() |
93
|
|
|
{ |
94
|
|
|
return $this->getGameNumber(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return MatchInterface |
99
|
|
|
*/ |
100
|
|
|
public function getMatch(): MatchInterface |
101
|
|
|
{ |
102
|
|
|
return $this->match; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritDoc |
107
|
|
|
*/ |
108
|
|
|
public function getParent(): ?TournamentHierarchyInterface |
109
|
|
|
{ |
110
|
|
|
return $this->getMatch(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return Player[]|Collection |
115
|
|
|
*/ |
116
|
|
|
public function getPlayersA() |
117
|
|
|
{ |
118
|
|
|
return $this->playersA; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return Player[]|Collection |
123
|
|
|
*/ |
124
|
|
|
public function getPlayersB() |
125
|
|
|
{ |
126
|
|
|
return $this->playersB; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Match constructor. |
131
|
|
|
*/ |
132
|
|
|
public function init() |
133
|
|
|
{ |
134
|
|
|
$this->playersA = new ArrayCollection(); |
135
|
|
|
$this->playersB = new ArrayCollection(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param int $gameNumber |
140
|
|
|
*/ |
141
|
|
|
public function setGameNumber(int $gameNumber) |
142
|
|
|
{ |
143
|
|
|
$this->gameNumber = $gameNumber; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param MatchInterface $match |
148
|
|
|
*/ |
149
|
|
|
public function setMatch(MatchInterface $match) |
150
|
|
|
{ |
151
|
|
|
if ($this->match !== null) { |
152
|
|
|
$this->match->getGames()->remove($this->getGameNumber()); |
153
|
|
|
} |
154
|
|
|
$this->match = $match; |
155
|
|
|
$match->getGames()->set($this->getGameNumber(), $this); |
156
|
|
|
} |
157
|
|
|
//</editor-fold desc="Public Methods"> |
158
|
|
|
} |