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\Repositories\DataUser as DataUserRepository; |
||
| 6 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\Notifier; |
||
| 7 | use BristolSU\ControlDB\Observers\NotifyObservers\Framework\ObserverStore; |
||
| 8 | use Illuminate\Support\Collection; |
||
| 9 | |||
| 10 | class DataUserNotifier extends Notifier implements DataUserRepository |
||
|
0 ignored issues
–
show
|
|||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
|
0 ignored issues
–
show
|
|||
| 14 | * @var DataUserRepository |
||
| 15 | */ |
||
| 16 | private $dataUserRepository; |
||
|
0 ignored issues
–
show
|
|||
| 17 | |||
| 18 | 20 | public function __construct(DataUserRepository $dataUserRepository, ObserverStore $observerStore) |
|
|
0 ignored issues
–
show
|
|||
| 19 | { |
||
| 20 | 20 | parent::__construct($observerStore, DataUserRepository::class); |
|
| 21 | 20 | $this->dataUserRepository = $dataUserRepository; |
|
| 22 | 20 | } |
|
| 23 | |||
| 24 | /** |
||
| 25 | * Get a data user by ID |
||
| 26 | * |
||
| 27 | * |
||
| 28 | * @param int $id |
||
|
0 ignored issues
–
show
|
|||
| 29 | * @return \BristolSU\ControlDB\Contracts\Models\DataUser |
||
|
0 ignored issues
–
show
|
|||
| 30 | */ |
||
| 31 | 20 | public function getById(int $id): \BristolSU\ControlDB\Contracts\Models\DataUser |
|
| 32 | { |
||
| 33 | 20 | return $this->dataUserRepository->getById($id); |
|
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get a data user where the given attributes match, including additional attributes. |
||
| 38 | * |
||
| 39 | * @param array $attributes |
||
|
0 ignored issues
–
show
|
|||
| 40 | * @return \BristolSU\ControlDB\Contracts\Models\DataUser |
||
|
0 ignored issues
–
show
|
|||
| 41 | */ |
||
| 42 | public function getWhere($attributes = []): \BristolSU\ControlDB\Contracts\Models\DataUser |
||
| 43 | { |
||
| 44 | return $this->dataUserRepository->getWhere($attributes); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get all data users where the given attributes match, including additional attributes. |
||
| 49 | * |
||
| 50 | * @param array $attributes |
||
|
0 ignored issues
–
show
|
|||
| 51 | * @return Collection|\BristolSU\ControlDB\Contracts\Models\DataUser[] |
||
|
0 ignored issues
–
show
|
|||
| 52 | */ |
||
| 53 | public function getAllWhere($attributes = []): Collection |
||
| 54 | { |
||
| 55 | return $this->dataUserRepository->getAllWhere($attributes); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Create a data user with the given attributes |
||
| 60 | * |
||
| 61 | * @param string|null $firstName First name of the user |
||
|
0 ignored issues
–
show
|
|||
| 62 | * @param string|null $lastName Last name of the user |
||
|
0 ignored issues
–
show
|
|||
| 63 | * @param string|null $email Email of the user |
||
|
0 ignored issues
–
show
|
|||
| 64 | * @param \DateTime|null $dob Date of birth of the user |
||
|
0 ignored issues
–
show
|
|||
| 65 | * @param string|null $preferredName Preferred name of the user |
||
|
0 ignored issues
–
show
|
|||
| 66 | * |
||
| 67 | * @return \BristolSU\ControlDB\Contracts\Models\DataUser |
||
| 68 | */ |
||
| 69 | 2 | public function create(?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser |
|
| 70 | { |
||
| 71 | 2 | $dataUser = $this->dataUserRepository->create($firstName, $lastName, $email, $dob, $preferredName); |
|
| 72 | 2 | $this->notify('create', $dataUser); |
|
| 73 | 2 | return $dataUser; |
|
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Update a data user |
||
| 78 | * |
||
| 79 | * @param int $id |
||
|
0 ignored issues
–
show
|
|||
| 80 | * @param string|null $firstName |
||
|
0 ignored issues
–
show
|
|||
| 81 | * @param string|null $lastName |
||
|
0 ignored issues
–
show
|
|||
| 82 | * @param string|null $email |
||
|
0 ignored issues
–
show
|
|||
| 83 | * @param \DateTime|null $dob |
||
|
0 ignored issues
–
show
|
|||
| 84 | * @param string|null $preferredName |
||
|
0 ignored issues
–
show
|
|||
| 85 | * @return \BristolSU\ControlDB\Contracts\Models\DataUser |
||
|
0 ignored issues
–
show
|
|||
| 86 | */ |
||
| 87 | 7 | public function update(int $id, ?string $firstName = null, ?string $lastName = null, ?string $email = null, ?\DateTime $dob = null, ?string $preferredName = null): \BristolSU\ControlDB\Contracts\Models\DataUser |
|
| 88 | { |
||
| 89 | 7 | $oldDataUser = $this->getById($id); |
|
| 90 | 7 | $newDataUser = $this->dataUserRepository->update($id, $firstName, $lastName, $email, $dob, $preferredName); |
|
| 91 | 7 | $this->notify('update', $oldDataUser, $newDataUser); |
|
| 92 | 7 | return $newDataUser; |
|
| 93 | } |
||
| 94 | } |