bristol-su /
control
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace BristolSU\ControlDB\Observers; |
||
| 4 | |||
| 5 | use BristolSU\ControlDB\Cache\Pivots\Tags\UserUserTag; |
||
| 6 | use BristolSU\ControlDB\Contracts\Models\User; |
||
| 7 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserGroup; |
||
| 8 | use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserRole; |
||
| 9 | |||
| 10 | class UserObserverCascadeDelete |
||
|
0 ignored issues
–
show
|
|||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
|
0 ignored issues
–
show
|
|||
| 14 | * @var UserGroup |
||
| 15 | */ |
||
| 16 | private $userGroup; |
||
|
0 ignored issues
–
show
|
|||
| 17 | /** |
||
|
0 ignored issues
–
show
|
|||
| 18 | * @var UserUserTag |
||
| 19 | */ |
||
| 20 | private $userUserTag; |
||
|
0 ignored issues
–
show
|
|||
| 21 | /** |
||
|
0 ignored issues
–
show
|
|||
| 22 | * @var UserRole |
||
| 23 | */ |
||
| 24 | private $userRole; |
||
|
0 ignored issues
–
show
|
|||
| 25 | |||
| 26 | 4 | public function __construct(UserGroup $userGroup, UserRole $userRole, UserUserTag $userUserTag) |
|
|
0 ignored issues
–
show
|
|||
| 27 | { |
||
| 28 | 4 | $this->userGroup = $userGroup; |
|
| 29 | 4 | $this->userUserTag = $userUserTag; |
|
| 30 | 4 | $this->userRole = $userRole; |
|
| 31 | 4 | } |
|
| 32 | |||
| 33 | 1 | public function delete(User $user) |
|
|
0 ignored issues
–
show
|
|||
| 34 | { |
||
| 35 | 1 | $this->removeGroups($user); |
|
| 36 | 1 | $this->removeTags($user); |
|
| 37 | 1 | $this->removeRoles($user); |
|
| 38 | 1 | } |
|
| 39 | |||
| 40 | 1 | private function removeGroups(User $user) |
|
|
0 ignored issues
–
show
|
|||
| 41 | { |
||
| 42 | 1 | foreach($this->userGroup->getGroupsThroughUser($user) as $group) { |
|
|
0 ignored issues
–
show
|
|||
| 43 | $this->userGroup->removeUserFromGroup($user, $group); |
||
| 44 | } |
||
| 45 | 1 | } |
|
| 46 | |||
| 47 | 1 | private function removeTags(User $user) |
|
|
0 ignored issues
–
show
|
|||
| 48 | { |
||
| 49 | 1 | foreach($this->userUserTag->getTagsThroughUser($user) as $tag) { |
|
|
0 ignored issues
–
show
|
|||
| 50 | $this->userUserTag->removeTagFromUser($tag, $user); |
||
| 51 | } |
||
| 52 | 1 | } |
|
| 53 | |||
| 54 | 1 | private function removeRoles(User $user) |
|
|
0 ignored issues
–
show
|
|||
| 55 | { |
||
| 56 | 1 | foreach($this->userRole->getRolesThroughUser($user) as $role) { |
|
|
0 ignored issues
–
show
|
|||
| 57 | $this->userRole->removeUserFromRole($user, $role); |
||
| 58 | } |
||
| 59 | 1 | } |
|
| 60 | |||
| 61 | } |