bristol-su /
control
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace BristolSU\ControlDB\Observers\NotifyObservers; |
||
| 4 | |||
| 5 | use BristolSU\ControlDB\Contracts\Models\Group as GroupModel; |
||
| 6 | use BristolSU\ControlDB\Contracts\Repositories\Group as GroupRepository; |
||
| 7 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\Notifier; |
||
| 8 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\ObserverStore; |
||
| 9 | use Illuminate\Support\Collection; |
||
| 10 | |||
| 11 | class GroupNotifier extends Notifier implements GroupRepository |
||
|
0 ignored issues
–
show
|
|||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
|
0 ignored issues
–
show
|
|||
| 15 | * @var GroupRepository |
||
| 16 | */ |
||
| 17 | private $groupRepository; |
||
|
0 ignored issues
–
show
|
|||
| 18 | |||
| 19 | 36 | public function __construct(GroupRepository $groupRepository, ObserverStore $observerStore) |
|
|
0 ignored issues
–
show
|
|||
| 20 | { |
||
| 21 | 36 | parent::__construct($observerStore, GroupRepository::class); |
|
| 22 | 36 | $this->groupRepository = $groupRepository; |
|
| 23 | 36 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * Get a group by ID |
||
| 27 | * |
||
| 28 | * @param int $id ID of the group |
||
| 29 | * @return GroupModel |
||
|
0 ignored issues
–
show
|
|||
| 30 | */ |
||
| 31 | 27 | public function getById(int $id): GroupModel |
|
| 32 | { |
||
| 33 | 27 | return $this->groupRepository->getById($id); |
|
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get a group by its data provider ID |
||
| 38 | * |
||
| 39 | * @param int $dataProviderId |
||
|
0 ignored issues
–
show
|
|||
| 40 | * @return GroupModel |
||
|
0 ignored issues
–
show
|
|||
| 41 | */ |
||
| 42 | 2 | public function getByDataProviderId(int $dataProviderId): GroupModel |
|
| 43 | { |
||
| 44 | 2 | return $this->groupRepository->getByDataProviderId($dataProviderId); |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get all groups |
||
| 49 | * |
||
| 50 | * @return Collection|GroupModel[] |
||
| 51 | */ |
||
| 52 | 1 | public function all(): Collection |
|
| 53 | { |
||
| 54 | 1 | return $this->groupRepository->all(); |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Create a new group |
||
| 59 | * |
||
| 60 | * @param int $dataProviderId |
||
|
0 ignored issues
–
show
|
|||
| 61 | * @return GroupModel |
||
|
0 ignored issues
–
show
|
|||
| 62 | */ |
||
| 63 | 2 | public function create(int $dataProviderId): GroupModel |
|
| 64 | { |
||
| 65 | 2 | $groupModel = $this->groupRepository->create($dataProviderId); |
|
| 66 | 2 | $this->notify('create', $groupModel); |
|
| 67 | 2 | return $groupModel; |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Delete a group by ID |
||
| 72 | * |
||
| 73 | * @param int $id |
||
|
0 ignored issues
–
show
|
|||
| 74 | */ |
||
|
0 ignored issues
–
show
|
|||
| 75 | 1 | public function delete(int $id): void |
|
| 76 | { |
||
| 77 | 1 | $groupModel = $this->getById($id); |
|
| 78 | 1 | $this->groupRepository->delete($id); |
|
| 79 | 1 | $this->notify('delete', $groupModel); |
|
| 80 | 1 | } |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Update the group model |
||
| 84 | * |
||
| 85 | * @param int $id |
||
|
0 ignored issues
–
show
|
|||
| 86 | * @param int $dataProviderId New data provider ID |
||
| 87 | * @return GroupModel |
||
|
0 ignored issues
–
show
|
|||
| 88 | */ |
||
| 89 | 1 | public function update(int $id, int $dataProviderId): GroupModel |
|
| 90 | { |
||
| 91 | 1 | $oldGroupModel = $this->getById($id); |
|
| 92 | 1 | $newGroupModel = $this->groupRepository->update($id, $dataProviderId); |
|
| 93 | 1 | $this->notify('update', $oldGroupModel, $newGroupModel); |
|
| 94 | 1 | return $newGroupModel; |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Paginate through all the groups |
||
| 99 | * |
||
| 100 | * @param int $page The page number to return |
||
|
0 ignored issues
–
show
|
|||
| 101 | * @param int $perPage The number of results to return per page |
||
| 102 | * |
||
| 103 | * @return Collection|GroupModel[] |
||
| 104 | */ |
||
| 105 | 2 | public function paginate(int $page, int $perPage): Collection |
|
| 106 | { |
||
| 107 | 2 | return $this->groupRepository->paginate($page, $perPage); |
|
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Get the number of groups |
||
| 112 | * |
||
| 113 | * @return int |
||
| 114 | */ |
||
| 115 | 2 | public function count(): int |
|
| 116 | { |
||
| 117 | 2 | return $this->groupRepository->count(); |
|
| 118 | } |
||
| 119 | } |