|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
|
|
|
|
|
14
|
|
|
* @var DataUserRepository |
|
15
|
|
|
*/ |
|
16
|
|
|
private $dataUserRepository; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
20 |
|
public function __construct(DataUserRepository $dataUserRepository, ObserverStore $observerStore) |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
29
|
|
|
* @return \BristolSU\ControlDB\Contracts\Models\DataUser |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
40
|
|
|
* @return \BristolSU\ControlDB\Contracts\Models\DataUser |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
51
|
|
|
* @return Collection|\BristolSU\ControlDB\Contracts\Models\DataUser[] |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
62
|
|
|
* @param string|null $lastName Last name of the user |
|
|
|
|
|
|
63
|
|
|
* @param string|null $email Email of the user |
|
|
|
|
|
|
64
|
|
|
* @param \DateTime|null $dob Date of birth of the user |
|
|
|
|
|
|
65
|
|
|
* @param string|null $preferredName Preferred name of the user |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
80
|
|
|
* @param string|null $firstName |
|
|
|
|
|
|
81
|
|
|
* @param string|null $lastName |
|
|
|
|
|
|
82
|
|
|
* @param string|null $email |
|
|
|
|
|
|
83
|
|
|
* @param \DateTime|null $dob |
|
|
|
|
|
|
84
|
|
|
* @param string|null $preferredName |
|
|
|
|
|
|
85
|
|
|
* @return \BristolSU\ControlDB\Contracts\Models\DataUser |
|
|
|
|
|
|
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('create', $oldDataUser, $newDataUser); |
|
92
|
7 |
|
return $newDataUser; |
|
93
|
|
|
} |
|
94
|
|
|
} |