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\GameInterface; |
17
|
|
|
use Tfboe\FmLib\Entity\Helpers\ResultEntity; |
18
|
|
|
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyInterface; |
19
|
|
|
use Tfboe\FmLib\Entity\PhaseInterface; |
20
|
|
|
use Tfboe\FmLib\Entity\Ranking; |
21
|
|
|
use Tfboe\FmLib\Helpers\Level; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Trait Match |
25
|
|
|
* @package Tfboe\FmLib\Entity\Traits |
26
|
|
|
*/ |
27
|
|
|
trait Match |
28
|
|
|
{ |
29
|
|
|
use ResultEntity; |
30
|
|
|
|
31
|
|
|
//<editor-fold desc="Fields"> |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\ManyToOne(targetEntity="\Tfboe\FmLib\Entity\PhaseInterface", inversedBy="matches") |
35
|
|
|
* @var PhaseInterface |
36
|
|
|
*/ |
37
|
|
|
private $phase; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\ManyToMany(targetEntity="\Tfboe\FmLib\Entity\Ranking", indexBy="uniqueRank") |
41
|
|
|
* @ORM\JoinTable(name="relation__match_rankingA") |
42
|
|
|
* @var Collection|Ranking |
43
|
|
|
*/ |
44
|
|
|
private $rankingsA; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @ORM\ManyToMany(targetEntity="\Tfboe\FmLib\Entity\Ranking", indexBy="uniqueRank") |
48
|
|
|
* @ORM\JoinTable(name="relation__match_rankingB") |
49
|
|
|
* @var Collection|Ranking |
50
|
|
|
*/ |
51
|
|
|
private $rankingsB; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @ORM\Column(type="integer") |
55
|
|
|
* @var int |
56
|
|
|
*/ |
57
|
|
|
private $matchNumber; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\GameInterface", mappedBy="match", indexBy="gameNumber") |
61
|
|
|
* @var Collection|GameInterface[] |
62
|
|
|
*/ |
63
|
|
|
private $games; |
64
|
|
|
//</editor-fold desc="Fields"> |
65
|
|
|
|
66
|
|
|
//<editor-fold desc="Public Methods"> |
67
|
|
|
/** |
68
|
|
|
* @inheritDoc |
69
|
|
|
*/ |
70
|
|
|
public function getChildren(): Collection |
71
|
|
|
{ |
72
|
|
|
return $this->getGames(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return GameInterface[]|Collection |
77
|
|
|
*/ |
78
|
|
|
public function getGames() |
79
|
|
|
{ |
80
|
|
|
return $this->games; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritDoc |
85
|
|
|
*/ |
86
|
|
|
public function getLevel(): int |
87
|
|
|
{ |
88
|
|
|
return Level::MATCH; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritDoc |
93
|
|
|
*/ |
94
|
|
|
public function getLocalIdentifier() |
95
|
|
|
{ |
96
|
|
|
return $this->getMatchNumber(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return int |
101
|
|
|
*/ |
102
|
|
|
public function getMatchNumber(): int |
103
|
|
|
{ |
104
|
|
|
return $this->matchNumber; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritDoc |
109
|
|
|
*/ |
110
|
|
|
public function getParent(): ?TournamentHierarchyInterface |
111
|
|
|
{ |
112
|
|
|
return $this->phase; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return PhaseInterface |
117
|
|
|
*/ |
118
|
|
|
public function getPhase(): PhaseInterface |
119
|
|
|
{ |
120
|
|
|
return $this->phase; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return Ranking|Collection |
125
|
|
|
*/ |
126
|
|
|
public function getRankingsA() |
127
|
|
|
{ |
128
|
|
|
return $this->rankingsA; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return Ranking|Collection |
133
|
|
|
*/ |
134
|
|
|
public function getRankingsB() |
135
|
|
|
{ |
136
|
|
|
return $this->rankingsB; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Match constructor. |
141
|
|
|
*/ |
142
|
|
|
public function init() |
143
|
|
|
{ |
144
|
|
|
$this->rankingsA = new ArrayCollection(); |
145
|
|
|
$this->rankingsB = new ArrayCollection(); |
146
|
|
|
$this->games = new ArrayCollection(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param int $matchNumber |
151
|
|
|
*/ |
152
|
|
|
public function setMatchNumber(int $matchNumber) |
153
|
|
|
{ |
154
|
|
|
$this->matchNumber = $matchNumber; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param PhaseInterface $phase |
159
|
|
|
*/ |
160
|
|
|
public function setPhase(PhaseInterface $phase) |
161
|
|
|
{ |
162
|
|
|
if ($this->phase !== null) { |
163
|
|
|
$this->phase->getMatches()->remove($this->getMatchNumber()); |
164
|
|
|
} |
165
|
|
|
$this->phase = $phase; |
166
|
|
|
$phase->getMatches()->set($this->getMatchNumber(), $this); |
167
|
|
|
} |
168
|
|
|
//</editor-fold desc="Public Methods"> |
169
|
|
|
} |