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