1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\ControlDB\Observers\NotifyObservers; |
4
|
|
|
|
5
|
|
|
use BristolSU\ControlDB\Contracts\Models\Role as RoleModel; |
6
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Role; |
7
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Role as RoleRepository; |
8
|
|
|
use BristolSU\ControlDB\Observers\NotifyObservers\Framework\Notifier; |
9
|
|
|
use BristolSU\ControlDB\Observers\NotifyObservers\Framework\ObserverStore; |
10
|
|
|
use Illuminate\Support\Collection; |
11
|
|
|
|
12
|
|
|
class RoleNotifier extends Notifier implements RoleRepository |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
|
|
|
|
16
|
|
|
* @var RoleRepository |
17
|
|
|
*/ |
18
|
|
|
private $roleRepository; |
|
|
|
|
19
|
|
|
|
20
|
48 |
|
public function __construct(RoleRepository $roleRepository, ObserverStore $observerStore) |
|
|
|
|
21
|
|
|
{ |
22
|
48 |
|
parent::__construct($observerStore, RoleRepository::class); |
23
|
48 |
|
$this->roleRepository = $roleRepository; |
24
|
48 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get a role by ID |
28
|
|
|
* |
29
|
|
|
* @param int $id |
|
|
|
|
30
|
|
|
* @return RoleModel |
|
|
|
|
31
|
|
|
*/ |
32
|
25 |
|
public function getById(int $id): RoleModel |
33
|
|
|
{ |
34
|
25 |
|
return $this->roleRepository->getById($id); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get all roles |
39
|
|
|
* |
40
|
|
|
* @return Collection|\BristolSU\ControlDB\Contracts\Models\Role[] |
41
|
|
|
*/ |
42
|
1 |
|
public function all(): Collection |
43
|
|
|
{ |
44
|
1 |
|
return $this->roleRepository->all(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get a role by data provider ID |
49
|
|
|
* |
50
|
|
|
* @param int $dataProviderId |
|
|
|
|
51
|
|
|
* @return RoleModel |
|
|
|
|
52
|
|
|
*/ |
53
|
2 |
|
public function getByDataProviderId(int $dataProviderId): RoleModel |
54
|
|
|
{ |
55
|
2 |
|
return $this->roleRepository->getByDataProviderId($dataProviderId); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create a new role |
60
|
|
|
* |
61
|
|
|
* @param int $positionId |
|
|
|
|
62
|
|
|
* @param int $groupId |
|
|
|
|
63
|
|
|
* @param int $dataProviderId |
|
|
|
|
64
|
|
|
* @return RoleModel |
|
|
|
|
65
|
|
|
*/ |
66
|
2 |
|
public function create(int $positionId, int $groupId, int $dataProviderId): RoleModel |
67
|
|
|
{ |
68
|
2 |
|
$roleModel = $this->roleRepository->create($positionId, $groupId, $dataProviderId); |
69
|
2 |
|
$this->notify('create', $roleModel); |
70
|
2 |
|
return $roleModel; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Delete a role |
75
|
|
|
* |
76
|
|
|
* @param int $id |
|
|
|
|
77
|
|
|
*/ |
|
|
|
|
78
|
1 |
|
public function delete(int $id): void |
79
|
|
|
{ |
80
|
1 |
|
$roleModel = $this->getById($id); |
81
|
1 |
|
$this->roleRepository->delete($id); |
82
|
1 |
|
$this->notify('delete', $roleModel); |
83
|
1 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Update the role model |
87
|
|
|
* |
88
|
|
|
* @param int $id |
|
|
|
|
89
|
|
|
* @param int $positionId |
|
|
|
|
90
|
|
|
* @param int $groupId |
|
|
|
|
91
|
|
|
* @param int $dataProviderId New data provider ID |
92
|
|
|
* @return RoleModel |
|
|
|
|
93
|
|
|
*/ |
94
|
5 |
|
public function update(int $id, int $positionId, int $groupId, int $dataProviderId): RoleModel |
95
|
|
|
{ |
96
|
5 |
|
$oldRoleModel = $this->getById($id); |
97
|
5 |
|
$newRoleModel = $this->roleRepository->update($id, $positionId, $groupId, $dataProviderId); |
98
|
5 |
|
$this->notify('update', $oldRoleModel, $newRoleModel); |
99
|
5 |
|
return $newRoleModel; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get all roles that belong to the given group |
104
|
|
|
* |
105
|
|
|
* @param \BristolSU\ControlDB\Contracts\Models\Group $group |
|
|
|
|
106
|
|
|
* @return Collection|RoleModel[] |
|
|
|
|
107
|
|
|
*/ |
108
|
4 |
|
public function allThroughGroup(\BristolSU\ControlDB\Contracts\Models\Group $group): Collection |
109
|
|
|
{ |
110
|
4 |
|
return $this->roleRepository->allThroughGroup($group); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get all roles that belong to the given position |
115
|
|
|
* @param \BristolSU\ControlDB\Contracts\Models\Position $position |
|
|
|
|
116
|
|
|
* @return Collection|RoleModel[] |
|
|
|
|
117
|
|
|
*/ |
118
|
4 |
|
public function allThroughPosition(\BristolSU\ControlDB\Contracts\Models\Position $position): Collection |
119
|
|
|
{ |
120
|
4 |
|
return $this->roleRepository->allThroughPosition($position); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Paginate through all the roles |
125
|
|
|
* |
126
|
|
|
* @param int $page The page number to return |
|
|
|
|
127
|
|
|
* @param int $perPage The number of results to return per page |
128
|
|
|
* |
129
|
|
|
* @return Collection|RoleModel[] |
130
|
|
|
*/ |
131
|
2 |
|
public function paginate(int $page, int $perPage): Collection |
132
|
|
|
{ |
133
|
2 |
|
return $this->roleRepository->paginate($page, $perPage); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get the number of roles |
138
|
|
|
* |
139
|
|
|
* @return int |
140
|
|
|
*/ |
141
|
2 |
|
public function count(): int |
142
|
|
|
{ |
143
|
2 |
|
return $this->roleRepository->count(); |
144
|
|
|
} |
145
|
|
|
} |