1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace BristolSU\ControlDB\Observers; |
||
4 | |||
5 | use BristolSU\ControlDB\Contracts\Models\Role; |
||
6 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\Tags\RoleRoleTag; |
||
7 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole; |
||
8 | |||
9 | class RoleObserverCascadeDelete |
||
0 ignored issues
–
show
|
|||
10 | { |
||
11 | |||
12 | /** |
||
0 ignored issues
–
show
|
|||
13 | * @var UserRole |
||
14 | */ |
||
15 | private $userRole; |
||
0 ignored issues
–
show
|
|||
16 | /** |
||
0 ignored issues
–
show
|
|||
17 | * @var RoleRoleTag |
||
18 | */ |
||
19 | private $roleRoleTag; |
||
0 ignored issues
–
show
|
|||
20 | |||
21 | 8 | public function __construct(UserRole $userRole, RoleRoleTag $roleRoleTag) |
|
0 ignored issues
–
show
|
|||
22 | { |
||
23 | 8 | $this->userRole = $userRole; |
|
24 | 8 | $this->roleRoleTag = $roleRoleTag; |
|
25 | 8 | } |
|
26 | |||
27 | 1 | public function delete(Role $role) |
|
0 ignored issues
–
show
|
|||
28 | { |
||
29 | 1 | $this->removeUsers($role); |
|
30 | 1 | $this->removeTags($role); |
|
31 | 1 | } |
|
32 | |||
33 | 1 | private function removeUsers(Role $role) |
|
0 ignored issues
–
show
|
|||
34 | { |
||
35 | 1 | foreach($this->userRole->getUsersThroughRole($role) as $user) { |
|
0 ignored issues
–
show
|
|||
36 | $this->userRole->removeUserFromRole($user, $role); |
||
37 | } |
||
38 | 1 | } |
|
39 | |||
40 | 1 | private function removeTags(Role $role) |
|
0 ignored issues
–
show
|
|||
41 | { |
||
42 | 1 | foreach($this->roleRoleTag->getTagsThroughRole($role) as $tag) { |
|
0 ignored issues
–
show
|
|||
43 | $this->roleRoleTag->removeTagFromRole($tag, $role); |
||
44 | } |
||
45 | 1 | } |
|
46 | |||
47 | } |