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