1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\ORM\Mapping\Column; |
10
|
|
|
use Doctrine\ORM\Mapping\Entity; |
11
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
12
|
|
|
use Doctrine\ORM\Mapping\Id; |
13
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
14
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
15
|
|
|
use Doctrine\ORM\Mapping\OneToMany; |
16
|
|
|
use Doctrine\ORM\Mapping\Table; |
17
|
|
|
use Stu\Component\Alliance\AllianceEnum; |
18
|
|
|
use Stu\Component\Alliance\Exception\AllianceFounderNotSetException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @Entity(repositoryClass="Stu\Orm\Repository\AllianceRepository") |
22
|
|
|
* @Table( |
23
|
|
|
* name="stu_alliances", |
24
|
|
|
* indexes={ |
25
|
|
|
* } |
26
|
|
|
* ) |
27
|
|
|
**/ |
28
|
|
|
class Alliance implements AllianceInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @Id |
32
|
|
|
* @Column(type="integer") |
33
|
|
|
* @GeneratedValue(strategy="IDENTITY") |
34
|
|
|
* |
35
|
|
|
*/ |
36
|
|
|
private int $id; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @Column(type="string") |
40
|
|
|
* |
41
|
|
|
*/ |
42
|
|
|
private string $name = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @Column(type="text") |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
private string $description = ''; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @Column(type="string") |
52
|
|
|
* |
53
|
|
|
*/ |
54
|
|
|
private string $homepage = ''; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Column(type="integer") |
58
|
|
|
* |
59
|
|
|
*/ |
60
|
|
|
private int $date = 0; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Column(type="integer", nullable=true) |
64
|
|
|
* |
65
|
|
|
*/ |
66
|
|
|
private ?int $faction_id = null; |
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @Column(type="boolean") |
70
|
|
|
* |
71
|
|
|
*/ |
72
|
|
|
private bool $accept_applications = false; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @Column(type="string", length=32) |
76
|
|
|
* |
77
|
|
|
*/ |
78
|
|
|
private string $avatar = ''; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Column(type="string", length=7) |
82
|
|
|
* |
83
|
|
|
*/ |
84
|
|
|
private string $rgb_code = ''; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* |
88
|
|
|
* @ManyToOne(targetEntity="Faction") |
89
|
|
|
* @JoinColumn(name="faction_id", referencedColumnName="id") |
90
|
|
|
*/ |
91
|
|
|
private ?FactionInterface $faction = null; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var ArrayCollection<int, UserInterface> |
95
|
|
|
* |
96
|
|
|
* @OneToMany(targetEntity="User", mappedBy="alliance") |
97
|
|
|
*/ |
98
|
|
|
private Collection $members; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var ArrayCollection<int, AllianceJobInterface> |
102
|
|
|
* |
103
|
|
|
* @OneToMany(targetEntity="AllianceJob", mappedBy="alliance", indexBy="type") |
104
|
|
|
*/ |
105
|
|
|
private Collection $jobs; |
106
|
|
|
|
107
|
|
|
public function __construct() |
108
|
|
|
{ |
109
|
|
|
$this->members = new ArrayCollection(); |
110
|
|
|
$this->jobs = new ArrayCollection(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getId(): int |
114
|
|
|
{ |
115
|
|
|
return $this->id; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getName(): string |
119
|
|
|
{ |
120
|
|
|
return $this->name; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setName(string $name): AllianceInterface |
124
|
|
|
{ |
125
|
|
|
$this->name = $name; |
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getDescription(): string |
130
|
|
|
{ |
131
|
|
|
return $this->description; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function setDescription(string $description): AllianceInterface |
135
|
|
|
{ |
136
|
|
|
$this->description = $description; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function getHomepage(): string |
141
|
|
|
{ |
142
|
|
|
return $this->homepage; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function setHomepage(string $homepage): AllianceInterface |
146
|
|
|
{ |
147
|
|
|
$this->homepage = $homepage; |
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function getDate(): int |
152
|
|
|
{ |
153
|
|
|
return $this->date; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function setDate(int $date): AllianceInterface |
157
|
|
|
{ |
158
|
|
|
$this->date = $date; |
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function getFaction(): ?FactionInterface |
163
|
|
|
{ |
164
|
|
|
return $this->faction; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function setFaction(?FactionInterface $faction): AllianceInterface |
168
|
|
|
{ |
169
|
|
|
$this->faction = $faction; |
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function getAcceptApplications(): bool |
174
|
|
|
{ |
175
|
|
|
return $this->accept_applications; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function setAcceptApplications(bool $acceptApplications): AllianceInterface |
179
|
|
|
{ |
180
|
|
|
$this->accept_applications = $acceptApplications; |
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function hasAvatar(): bool |
185
|
|
|
{ |
186
|
|
|
return strlen($this->getAvatar()) > 0; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function getAvatar(): string |
190
|
|
|
{ |
191
|
|
|
return $this->avatar; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function setAvatar(string $avatar): AllianceInterface |
195
|
|
|
{ |
196
|
|
|
$this->avatar = $avatar; |
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function getRgbCode(): string |
201
|
|
|
{ |
202
|
|
|
return $this->rgb_code; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function setRgbCode(string $rgbCode): AllianceInterface |
206
|
|
|
{ |
207
|
|
|
$this->rgb_code = $rgbCode; |
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @throws AllianceFounderNotSetException |
213
|
|
|
*/ |
214
|
|
|
public function getFounder(): AllianceJobInterface |
215
|
|
|
{ |
216
|
|
|
$job = $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_FOUNDER); |
217
|
|
|
if ($job === null) { |
218
|
|
|
// alliance without founder? this should not happen |
219
|
|
|
throw new AllianceFounderNotSetException(); |
220
|
|
|
} |
221
|
|
|
return $job; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function getSuccessor(): ?AllianceJobInterface |
225
|
|
|
{ |
226
|
|
|
return $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_SUCCESSOR); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function getDiplomatic(): ?AllianceJobInterface |
230
|
|
|
{ |
231
|
|
|
return $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_DIPLOMATIC); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function getMembers(): Collection |
235
|
|
|
{ |
236
|
|
|
return $this->members; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
public function isNpcAlliance(): bool |
240
|
|
|
{ |
241
|
|
|
$founder = $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_FOUNDER); |
242
|
|
|
|
243
|
|
|
if ($founder === null) { |
244
|
|
|
return false; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return $founder->getUser()->isNpc(); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function getJobs(): Collection |
251
|
|
|
{ |
252
|
|
|
return $this->jobs; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public function __toString(): string |
256
|
|
|
{ |
257
|
|
|
return $this->getName(); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
public function hasTranslation(): bool |
261
|
|
|
{ |
262
|
|
|
$text = $this->getDescription(); |
263
|
|
|
return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|