|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\ControlDB\Observers\NotifyObservers\Pivots; |
|
4
|
|
|
|
|
5
|
|
|
use BristolSU\ControlDB\Contracts\Models\Group; |
|
6
|
|
|
use BristolSU\ControlDB\Contracts\Models\User; |
|
7
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Pivots\UserGroup as UserGroupRepository; |
|
8
|
|
|
use BristolSU\ControlDB\Observers\NotifyObservers\Framework\Notifier; |
|
9
|
|
|
use BristolSU\ControlDB\Observers\NotifyObservers\Framework\ObserverStore; |
|
10
|
|
|
use Illuminate\Support\Collection; |
|
11
|
|
|
|
|
12
|
|
|
class UserGroupNotifier extends Notifier implements UserGroupRepository |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
|
|
|
|
|
16
|
|
|
* @var UserGroupRepository |
|
17
|
|
|
*/ |
|
18
|
|
|
private $userGroupRepository; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
21 |
|
public function __construct(UserGroupRepository $userGroupRepository, ObserverStore $observerStore) |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
21 |
|
parent::__construct($observerStore, UserGroupRepository::class); |
|
23
|
21 |
|
$this->userGroupRepository = $userGroupRepository; |
|
24
|
21 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get all users who are members of a group |
|
28
|
|
|
* |
|
29
|
|
|
* @param Group $group |
|
|
|
|
|
|
30
|
|
|
* @return User[]|Collection Users who are members of the group |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
3 |
|
public function getUsersThroughGroup(Group $group): Collection |
|
33
|
|
|
{ |
|
34
|
3 |
|
return $this->userGroupRepository->getUsersThroughGroup($group); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get all groups a user belongs to |
|
39
|
|
|
* |
|
40
|
|
|
* @param User $user |
|
|
|
|
|
|
41
|
|
|
* @return Group[]|Collection Groups the user is a member of |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
3 |
|
public function getGroupsThroughUser(User $user): Collection |
|
44
|
|
|
{ |
|
45
|
3 |
|
return $this->userGroupRepository->getGroupsThroughUser($user); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Add a user to a group |
|
50
|
|
|
* |
|
51
|
|
|
* @param User $user User to add to the group |
|
|
|
|
|
|
52
|
|
|
* @param Group $group Group to add the user to |
|
53
|
|
|
* @return void |
|
|
|
|
|
|
54
|
|
|
*/ |
|
55
|
11 |
|
public function addUserToGroup(User $user, Group $group): void |
|
56
|
|
|
{ |
|
57
|
11 |
|
$this->userGroupRepository->addUserToGroup($user, $group); |
|
58
|
11 |
|
$this->notify('addUserToGroup', $user, $group); |
|
59
|
11 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Remove a user from a group |
|
63
|
|
|
* @param User $user User to remove from the group |
|
|
|
|
|
|
64
|
|
|
* @param Group $group Group to remove the user from |
|
65
|
|
|
* @return void |
|
|
|
|
|
|
66
|
|
|
*/ |
|
67
|
4 |
|
public function removeUserFromGroup(User $user, Group $group): void |
|
68
|
|
|
{ |
|
69
|
4 |
|
$this->userGroupRepository->removeUserFromGroup($user, $group); |
|
70
|
4 |
|
$this->notify('removeUserFromGroup', $user, $group); |
|
71
|
|
|
} |
|
72
|
|
|
} |