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