|
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\Enum\AllianceJobTypeEnum; |
|
18
|
|
|
use Stu\Orm\Attribute\TruncateOnGameReset; |
|
19
|
|
|
use Stu\Orm\Repository\AllianceJobRepository; |
|
20
|
|
|
|
|
21
|
|
|
#[Table(name: 'stu_alliances_jobs')] |
|
22
|
|
|
#[Entity(repositoryClass: AllianceJobRepository::class)] |
|
23
|
|
|
#[TruncateOnGameReset] |
|
24
|
|
|
class AllianceJob |
|
25
|
|
|
{ |
|
26
|
|
|
#[Id] |
|
27
|
|
|
#[Column(type: 'integer')] |
|
28
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
|
29
|
|
|
private int $id; |
|
30
|
|
|
|
|
31
|
|
|
#[ManyToOne(targetEntity: Alliance::class, inversedBy: 'jobs')] |
|
32
|
|
|
#[JoinColumn(name: 'alliance_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
|
33
|
|
|
private Alliance $alliance; |
|
34
|
|
|
|
|
35
|
|
|
#[Column(type: 'integer', nullable: true)] |
|
36
|
|
|
private ?int $user_id = null; |
|
37
|
|
|
|
|
38
|
|
|
#[Column(type: 'smallint', enumType: AllianceJobTypeEnum::class, nullable: true)] |
|
39
|
|
|
private ?AllianceJobTypeEnum $type = null; |
|
40
|
|
|
|
|
41
|
|
|
#[Column(type: 'string', nullable: true)] |
|
42
|
|
|
private ?string $title = null; |
|
43
|
|
|
|
|
44
|
|
|
#[Column(type: 'integer', nullable: true)] |
|
45
|
|
|
private ?int $sort = null; |
|
46
|
|
|
|
|
47
|
|
|
#[Column(type: 'boolean', options: ['default' => false])] |
|
48
|
|
|
private bool $is_founder_permission = false; |
|
49
|
|
|
|
|
50
|
|
|
#[Column(type: 'boolean', options: ['default' => false])] |
|
51
|
|
|
private bool $is_successor_permission = false; |
|
52
|
|
|
|
|
53
|
|
|
#[Column(type: 'boolean', options: ['default' => false])] |
|
54
|
|
|
private bool $is_diplomatic_permission = false; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var ArrayCollection<int, AllianceMemberJob> |
|
58
|
|
|
*/ |
|
59
|
|
|
#[OneToMany(targetEntity: AllianceMemberJob::class, mappedBy: 'job', cascade: ['remove'])] |
|
60
|
|
|
private Collection $memberAssignments; |
|
61
|
|
|
|
|
62
|
|
|
public function __construct() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->memberAssignments = new ArrayCollection(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
public function getId(): int |
|
68
|
|
|
{ |
|
69
|
1 |
|
return $this->id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
9 |
|
public function getAlliance(): Alliance |
|
73
|
|
|
{ |
|
74
|
9 |
|
return $this->alliance; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function setAlliance(Alliance $alliance): AllianceJob |
|
78
|
|
|
{ |
|
79
|
|
|
$this->alliance = $alliance; |
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
2 |
|
public function getTitle(): ?string |
|
84
|
|
|
{ |
|
85
|
2 |
|
return $this->title; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function setTitle(string $title): AllianceJob |
|
89
|
|
|
{ |
|
90
|
|
|
$this->title = $title; |
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
3 |
|
public function getSort(): ?int |
|
95
|
|
|
{ |
|
96
|
3 |
|
return $this->sort; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function setSort(?int $sort): AllianceJob |
|
100
|
|
|
{ |
|
101
|
|
|
$this->sort = $sort; |
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getOldUserId(): ?int |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->user_id; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getOldType(): ?AllianceJobTypeEnum |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->type; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
9 |
|
public function hasFounderPermission(): bool |
|
116
|
|
|
{ |
|
117
|
9 |
|
return $this->is_founder_permission; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function setIsFounderPermission(bool $isFounderPermission): AllianceJob |
|
121
|
|
|
{ |
|
122
|
|
|
$this->is_founder_permission = $isFounderPermission; |
|
123
|
|
|
return $this; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
1 |
|
public function hasSuccessorPermission(): bool |
|
127
|
|
|
{ |
|
128
|
1 |
|
return $this->is_successor_permission; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function setIsSuccessorPermission(bool $isSuccessorPermission): AllianceJob |
|
132
|
|
|
{ |
|
133
|
|
|
$this->is_successor_permission = $isSuccessorPermission; |
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
3 |
|
public function hasDiplomaticPermission(): bool |
|
138
|
|
|
{ |
|
139
|
3 |
|
return $this->is_diplomatic_permission; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function setIsDiplomaticPermission(bool $isDiplomaticPermission): AllianceJob |
|
143
|
|
|
{ |
|
144
|
|
|
$this->is_diplomatic_permission = $isDiplomaticPermission; |
|
145
|
|
|
return $this; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return Collection<int, AllianceMemberJob> |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getMemberAssignments(): Collection |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->memberAssignments; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return array<User> |
|
158
|
|
|
*/ |
|
159
|
1 |
|
public function getUsers(): array |
|
160
|
|
|
{ |
|
161
|
1 |
|
return array_map( |
|
162
|
1 |
|
fn(AllianceMemberJob $assignment) => $assignment->getUser(), |
|
163
|
1 |
|
$this->memberAssignments->toArray() |
|
164
|
1 |
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
1 |
|
public function hasUser(User $user): bool |
|
168
|
|
|
{ |
|
169
|
1 |
|
foreach ($this->memberAssignments as $assignment) { |
|
170
|
1 |
|
if ($assignment->getUser()->getId() === $user->getId()) { |
|
171
|
1 |
|
return true; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
1 |
|
return false; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
1 |
|
public function getUser(): ?User |
|
178
|
|
|
{ |
|
179
|
1 |
|
$first = $this->memberAssignments->first(); |
|
180
|
1 |
|
return $first !== false ? $first->getUser() : null; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
1 |
|
public function getUserId(): ?int |
|
184
|
|
|
{ |
|
185
|
1 |
|
$user = $this->getUser(); |
|
186
|
1 |
|
return $user !== null ? $user->getId() : null; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|