1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 1/2/18 |
7
|
|
|
* Time: 8:47 PM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Entity\Traits; |
11
|
|
|
|
12
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
13
|
|
|
use Doctrine\Common\Collections\Collection; |
14
|
|
|
use Doctrine\ORM\Mapping as ORM; |
15
|
|
|
use Tfboe\FmLib\Entity\Helpers\AutomaticInstanceGeneration; |
16
|
|
|
use Tfboe\FmLib\Entity\Helpers\NameEntity; |
17
|
|
|
use Tfboe\FmLib\Entity\Helpers\SubClassData; |
18
|
|
|
use Tfboe\FmLib\Entity\Helpers\TimestampableEntity; |
19
|
|
|
use Tfboe\FmLib\Entity\Helpers\UUIDEntity; |
20
|
|
|
use Tfboe\FmLib\Entity\RankingSystemListInterface; |
21
|
|
|
use Tfboe\FmLib\Entity\TournamentInterface; |
22
|
|
|
use Tfboe\FmLib\Exceptions\ValueNotValid; |
23
|
|
|
use Tfboe\FmLib\Helpers\Level; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Trait RankingSystem |
27
|
|
|
* @package Tfboe\FmLib\Entity\Traits |
28
|
|
|
*/ |
29
|
|
|
trait RankingSystem |
30
|
|
|
{ |
31
|
|
|
use SubClassData; |
32
|
|
|
use TimestampableEntity; |
33
|
|
|
use UUIDEntity; |
34
|
|
|
use NameEntity; |
35
|
|
|
|
36
|
|
|
//<editor-fold desc="Fields"> |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\Column(type="string") |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $serviceName; |
44
|
|
|
/** |
45
|
|
|
* @ORM\Column(type="smallint", nullable=true) |
46
|
|
|
* @var int|null |
47
|
|
|
*/ |
48
|
|
|
private $defaultForLevel; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @ORM\Column(type="integer") |
52
|
|
|
* @var int |
53
|
|
|
*/ |
54
|
|
|
private $generationInterval; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @ORM\ManyToMany( |
58
|
|
|
* targetEntity="\Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity", |
59
|
|
|
* mappedBy="rankingSystems", |
60
|
|
|
* indexBy="id" |
61
|
|
|
* ) |
62
|
|
|
* @ORM\JoinTable(name="relation__tournament_ranking_systems") |
63
|
|
|
* @var Collection|TournamentInterface[] |
64
|
|
|
*/ |
65
|
|
|
private $hierarchyEntries; |
66
|
|
|
/** |
67
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
68
|
|
|
* @var \DateTime|null |
69
|
|
|
*/ |
70
|
|
|
private $openSyncFrom; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
74
|
|
|
* @var \DateTime|null |
75
|
|
|
*/ |
76
|
|
|
private $openSyncFromInProcess; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\RankingSystemListInterface", mappedBy="rankingSystem", |
80
|
|
|
* indexBy="id") |
81
|
|
|
* @var Collection|RankingSystemListInterface[] |
82
|
|
|
*/ |
83
|
|
|
private $lists; |
84
|
|
|
//</editor-fold desc="Fields"> |
85
|
|
|
|
86
|
|
|
//<editor-fold desc="Constructor"> |
87
|
|
|
//</editor-fold desc="Constructor"> |
88
|
|
|
|
89
|
|
|
//<editor-fold desc="Public Methods"> |
90
|
|
|
/** |
91
|
|
|
* @return int|null |
92
|
|
|
*/ |
93
|
|
|
public function getDefaultForLevel(): ?int |
94
|
|
|
{ |
95
|
|
|
return $this->defaultForLevel; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return int |
100
|
|
|
*/ |
101
|
|
|
public function getGenerationInterval(): int |
102
|
|
|
{ |
103
|
|
|
return $this->generationInterval; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return TournamentInterface[]|Collection |
108
|
|
|
*/ |
109
|
|
|
public function getHierarchyEntries() |
110
|
|
|
{ |
111
|
|
|
return $this->hierarchyEntries; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return RankingSystemListInterface[]|Collection |
116
|
|
|
*/ |
117
|
|
|
public function getLists(): Collection |
118
|
|
|
{ |
119
|
|
|
return $this->lists; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return \DateTime|null |
124
|
|
|
*/ |
125
|
|
|
public function getOpenSyncFrom(): ?\DateTime |
126
|
|
|
{ |
127
|
|
|
return $this->openSyncFrom; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return \DateTime|null |
132
|
|
|
*/ |
133
|
|
|
public function getOpenSyncFromInProcess(): ?\DateTime |
134
|
|
|
{ |
135
|
|
|
return $this->openSyncFromInProcess; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
public function getServiceName(): string |
142
|
|
|
{ |
143
|
|
|
return $this->serviceName; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param int|null $defaultForLevel |
148
|
|
|
* @throws ValueNotValid |
149
|
|
|
*/ |
150
|
|
|
public function setDefaultForLevel(?int $defaultForLevel) |
151
|
|
|
{ |
152
|
|
|
if ($defaultForLevel !== null) { |
153
|
|
|
Level::ensureValidValue($defaultForLevel); |
154
|
|
|
} |
155
|
|
|
$this->defaultForLevel = $defaultForLevel; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param int $generationInterval |
160
|
|
|
* @throws \Tfboe\FmLib\Exceptions\ValueNotValid |
161
|
|
|
*/ |
162
|
|
|
public function setGenerationInterval(int $generationInterval) |
163
|
|
|
{ |
164
|
|
|
AutomaticInstanceGeneration::ensureValidValue($generationInterval); |
165
|
|
|
$this->generationInterval = $generationInterval; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param \DateTime|null $openSyncFrom |
170
|
|
|
*/ |
171
|
|
|
public function setOpenSyncFrom(?\DateTime $openSyncFrom) |
172
|
|
|
{ |
173
|
|
|
$this->openSyncFrom = $openSyncFrom; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param \DateTime|null $openSyncFromInProcess |
178
|
|
|
* @return $this|RankingSystem |
|
|
|
|
179
|
|
|
*/ |
180
|
|
|
public function setOpenSyncFromInProcess(?\DateTime $openSyncFromInProcess): RankingSystem |
181
|
|
|
{ |
182
|
|
|
$this->openSyncFromInProcess = $openSyncFromInProcess; |
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param string $serviceName |
188
|
|
|
*/ |
189
|
|
|
public function setServiceName(string $serviceName) |
190
|
|
|
{ |
191
|
|
|
$this->serviceName = $serviceName; |
192
|
|
|
} |
193
|
|
|
//</editor-fold desc="Public Methods"> |
194
|
|
|
|
195
|
|
|
//<editor-fold desc="Protected Final Methods"> |
196
|
|
|
/** |
197
|
|
|
* RankingSystem init |
198
|
|
|
* @param string[] $keys the keys of the subclass properties |
199
|
|
|
*/ |
200
|
|
|
protected final function init(array $keys) |
201
|
|
|
{ |
202
|
|
|
$this->initSubClassData($keys); |
203
|
|
|
$this->generationInterval = AutomaticInstanceGeneration::OFF; |
204
|
|
|
$this->defaultForLevel = null; |
205
|
|
|
$this->openSyncFrom = null; |
206
|
|
|
$this->lists = new ArrayCollection(); |
207
|
|
|
$this->hierarchyEntries = new ArrayCollection(); |
208
|
|
|
} |
209
|
|
|
//</editor-fold desc="Protected Final Methods"> |
210
|
|
|
} |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.