|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Alliance\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use Stu\Orm\Entity\Alliance; |
|
9
|
|
|
use Stu\Orm\Entity\AllianceJob; |
|
10
|
|
|
use Stu\Orm\Entity\AllianceMemberJob; |
|
11
|
|
|
use Stu\Orm\Entity\User; |
|
12
|
|
|
use Stu\Orm\Repository\AllianceMemberJobRepositoryInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class AllianceJobManager implements AllianceJobManagerInterface |
|
15
|
|
|
{ |
|
16
|
1 |
|
public function __construct( |
|
17
|
|
|
private AllianceMemberJobRepositoryInterface $allianceMemberJobRepository |
|
18
|
1 |
|
) {} |
|
19
|
|
|
|
|
20
|
|
|
#[Override] |
|
21
|
|
|
public function assignUserToJob(User $user, AllianceJob $job): void |
|
22
|
|
|
{ |
|
23
|
|
|
$existing = $this->allianceMemberJobRepository->getByUserAndJob($user, $job->getId()); |
|
24
|
|
|
|
|
25
|
|
|
if ($existing !== null) { |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$assignment = $this->allianceMemberJobRepository->prototype(); |
|
30
|
|
|
$assignment->setUser($user); |
|
31
|
|
|
$assignment->setJob($job); |
|
32
|
|
|
|
|
33
|
|
|
$this->allianceMemberJobRepository->save($assignment); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
#[Override] |
|
37
|
|
|
public function removeUserFromJob(User $user, AllianceJob $job): void |
|
38
|
|
|
{ |
|
39
|
|
|
$assignment = $this->allianceMemberJobRepository->getByUserAndJob($user, $job->getId()); |
|
40
|
|
|
|
|
41
|
|
|
if ($assignment === null) { |
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->allianceMemberJobRepository->delete($assignment); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
#[Override] |
|
49
|
|
|
public function removeUserFromAllJobs(User $user, Alliance $alliance): void |
|
50
|
|
|
{ |
|
51
|
|
|
$assignments = $this->allianceMemberJobRepository->getByUser($user->getId()); |
|
52
|
|
|
|
|
53
|
|
|
foreach ($assignments as $assignment) { |
|
54
|
|
|
if ($assignment->getJob()->getAlliance()->getId() === $alliance->getId()) { |
|
55
|
|
|
$this->allianceMemberJobRepository->delete($assignment); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
#[Override] |
|
61
|
|
|
public function hasUserJob(User $user, Alliance $alliance): bool |
|
62
|
|
|
{ |
|
63
|
|
|
$assignments = $this->allianceMemberJobRepository->getByUser($user->getId()); |
|
64
|
|
|
|
|
65
|
|
|
foreach ($assignments as $assignment) { |
|
66
|
|
|
if ($assignment->getJob()->getAlliance()->getId() === $alliance->getId()) { |
|
67
|
|
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
9 |
|
#[Override] |
|
75
|
|
|
public function getUserJobs(User $user, Alliance $alliance): array |
|
76
|
|
|
{ |
|
77
|
9 |
|
$assignments = $this->allianceMemberJobRepository->getByUser($user->getId()); |
|
78
|
9 |
|
$jobs = []; |
|
79
|
|
|
|
|
80
|
9 |
|
foreach ($assignments as $assignment) { |
|
81
|
9 |
|
if ($assignment->getJob()->getAlliance()->getId() === $alliance->getId()) { |
|
82
|
9 |
|
$jobs[] = $assignment->getJob(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
9 |
|
return $jobs; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
9 |
|
#[Override] |
|
90
|
|
|
public function hasUserFounderPermission(User $user, Alliance $alliance): bool |
|
91
|
|
|
{ |
|
92
|
9 |
|
$jobs = $this->getUserJobs($user, $alliance); |
|
93
|
|
|
|
|
94
|
9 |
|
foreach ($jobs as $job) { |
|
95
|
9 |
|
if ($job->hasFounderPermission()) { |
|
96
|
9 |
|
return true; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return false; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
#[Override] |
|
104
|
|
|
public function hasUserSuccessorPermission(User $user, Alliance $alliance): bool |
|
105
|
|
|
{ |
|
106
|
|
|
$jobs = $this->getUserJobs($user, $alliance); |
|
107
|
|
|
|
|
108
|
|
|
foreach ($jobs as $job) { |
|
109
|
|
|
if ($job->hasSuccessorPermission()) { |
|
110
|
|
|
return true; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return false; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
#[Override] |
|
118
|
|
|
public function hasUserDiplomaticPermission(User $user, Alliance $alliance): bool |
|
119
|
|
|
{ |
|
120
|
2 |
|
$jobs = $this->getUserJobs($user, $alliance); |
|
121
|
|
|
|
|
122
|
2 |
|
foreach ($jobs as $job) { |
|
123
|
2 |
|
if ($job->hasDiplomaticPermission()) { |
|
124
|
|
|
return true; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
2 |
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths