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