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