1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace BristolSU\ControlDB\Observers\NotifyObservers; |
||
4 | |||
5 | use BristolSU\ControlDB\Contracts\Repositories\DataPosition as DataPositionRepository; |
||
6 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\Notifier; |
||
7 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\ObserverStore; |
||
8 | use Illuminate\Support\Collection; |
||
9 | |||
10 | class DataPositionNotifier extends Notifier implements DataPositionRepository |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | |||
13 | /** |
||
0 ignored issues
–
show
|
|||
14 | * @var DataPositionRepository |
||
15 | */ |
||
16 | private $dataPositionRepository; |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | 13 | public function __construct(DataPositionRepository $dataPositionRepository, ObserverStore $observerStore) |
|
0 ignored issues
–
show
|
|||
19 | { |
||
20 | 13 | parent::__construct($observerStore, DataPositionRepository::class); |
|
21 | 13 | $this->dataPositionRepository = $dataPositionRepository; |
|
22 | 13 | } |
|
23 | |||
24 | /** |
||
25 | * Get a data position by ID |
||
26 | * |
||
27 | * @param int $id |
||
0 ignored issues
–
show
|
|||
28 | * @return \BristolSU\ControlDB\Contracts\Models\DataPosition |
||
0 ignored issues
–
show
|
|||
29 | */ |
||
30 | 13 | public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataPosition |
|
31 | { |
||
32 | 13 | return $this->dataPositionRepository->getById($id); |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * Get a data position where the given attributes match, including additional attributes. |
||
37 | * |
||
38 | * @param array $attributes |
||
0 ignored issues
–
show
|
|||
39 | * @return \BristolSU\ControlDB\Contracts\Models\DataPosition |
||
0 ignored issues
–
show
|
|||
40 | */ |
||
41 | public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataPosition |
||
42 | { |
||
43 | return $this->dataPositionRepository->getWhere($attributes); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get all data positions where the given attributes match, including additional attributes. |
||
48 | * |
||
49 | * @param array $attributes |
||
0 ignored issues
–
show
|
|||
50 | * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataPosition[] |
||
0 ignored issues
–
show
|
|||
51 | */ |
||
52 | public function getAllWhere($attributes = []): Collection |
||
53 | { |
||
54 | return $this->dataPositionRepository->getAllWhere($attributes); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Create a data position with the given attributes |
||
59 | * |
||
60 | * @param string|null $name Name of the position |
||
0 ignored issues
–
show
|
|||
61 | * @param string|null $description Description of the position |
||
62 | * @return \BristolSU\ControlDB\Contracts\Models\DataPosition |
||
0 ignored issues
–
show
|
|||
63 | */ |
||
64 | 2 | public function create(?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition |
|
65 | { |
||
66 | 2 | $dataPosition = $this->dataPositionRepository->create($name, $description); |
|
67 | 2 | $this->notify('create', $dataPosition); |
|
68 | 2 | return $dataPosition; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Update a data position with the given attributes |
||
73 | * |
||
74 | * @param int $id |
||
0 ignored issues
–
show
|
|||
75 | * @param string|null $name Name of the position |
||
0 ignored issues
–
show
|
|||
76 | * @param string|null $description Description of the position |
||
77 | * @return \BristolSU\ControlDB\Contracts\Models\DataPosition |
||
0 ignored issues
–
show
|
|||
78 | */ |
||
79 | 4 | public function update(int $id, ?string $name = null, ?string $description = null): \BristolSU\ControlDB\Contracts\Models\DataPosition |
|
80 | { |
||
81 | 4 | $oldDataPosition = $this->getById($id); |
|
82 | 4 | $newDataPosition = $this->dataPositionRepository->update($id, $name, $description); |
|
83 | 4 | $this->notify('update', $oldDataPosition, $newDataPosition); |
|
84 | 4 | return $newDataPosition; |
|
85 | } |
||
86 | } |