1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\ControlDB\Cache; |
4
|
|
|
|
5
|
|
|
use BristolSU\ControlDB\Contracts\Models\Position as PositionModel; |
6
|
|
|
use BristolSU\ControlDB\Contracts\Models\User as UserModel; |
7
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Position as PositionRepositoryContract; |
8
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Position as PositionRepository; |
9
|
|
|
use Illuminate\Contracts\Cache\Repository; |
10
|
|
|
use Illuminate\Support\Collection; |
11
|
|
|
|
12
|
|
|
class Position implements PositionRepository |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
|
|
|
|
15
|
|
|
* @var PositionRepositoryContract |
16
|
|
|
*/ |
17
|
|
|
private $positionRepository; |
|
|
|
|
18
|
|
|
/** |
|
|
|
|
19
|
|
|
* @var Repository |
20
|
|
|
*/ |
21
|
|
|
private $cache; |
|
|
|
|
22
|
|
|
|
23
|
35 |
|
public function __construct(PositionRepositoryContract $positionRepository, Repository $cache) |
|
|
|
|
24
|
|
|
{ |
25
|
35 |
|
$this->positionRepository = $positionRepository; |
26
|
35 |
|
$this->cache = $cache; |
27
|
35 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get a position by ID |
31
|
|
|
* |
32
|
|
|
* @param int $id ID of the position |
33
|
|
|
* @return PositionModel |
|
|
|
|
34
|
|
|
*/ |
35
|
19 |
|
public function getById(int $id): PositionModel |
36
|
|
|
{ |
37
|
|
|
return $this->cache->rememberForever(static::class . '@getById:' . $id, function() use ($id) { |
|
|
|
|
38
|
19 |
|
return $this->positionRepository->getById($id); |
39
|
19 |
|
}); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get a position by its data provider ID |
44
|
|
|
* |
45
|
|
|
* @param int $dataProviderId |
|
|
|
|
46
|
|
|
* @return PositionModel |
|
|
|
|
47
|
|
|
*/ |
48
|
3 |
|
public function getByDataProviderId(int $dataProviderId): PositionModel |
49
|
|
|
{ |
50
|
|
|
return $this->cache->rememberForever(static::class . '@getByDataProviderId:' . $dataProviderId, function() use ($dataProviderId) { |
|
|
|
|
51
|
3 |
|
return $this->positionRepository->getByDataProviderId($dataProviderId); |
52
|
3 |
|
}); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get all positions |
57
|
|
|
* |
58
|
|
|
* @return Collection|PositionModel[] |
59
|
|
|
*/ |
60
|
2 |
|
public function all(): Collection |
61
|
|
|
{ |
62
|
2 |
|
return $this->positionRepository->all(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Create a new position |
67
|
|
|
* |
68
|
|
|
* @param int $dataProviderId |
|
|
|
|
69
|
|
|
* @return PositionModel |
|
|
|
|
70
|
|
|
*/ |
71
|
3 |
|
public function create(int $dataProviderId): PositionModel |
72
|
|
|
{ |
73
|
3 |
|
return $this->positionRepository->create($dataProviderId); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Delete a position by ID |
78
|
|
|
* |
79
|
|
|
* @param int $id |
|
|
|
|
80
|
|
|
*/ |
|
|
|
|
81
|
2 |
|
public function delete(int $id): void |
82
|
|
|
{ |
83
|
2 |
|
$this->positionRepository->delete($id); |
84
|
2 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Paginate through all the positions |
88
|
|
|
* |
89
|
|
|
* @param int $page The page number to return |
|
|
|
|
90
|
|
|
* @param int $perPage The number of results to return per page |
91
|
|
|
* |
92
|
|
|
* @return Collection|PositionModel[] |
93
|
|
|
*/ |
94
|
3 |
|
public function paginate(int $page, int $perPage): Collection |
95
|
|
|
{ |
96
|
3 |
|
return $this->positionRepository->paginate($page, $perPage); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the number of positions |
101
|
|
|
* |
102
|
|
|
* @return int |
103
|
|
|
*/ |
104
|
3 |
|
public function count(): int |
105
|
|
|
{ |
106
|
|
|
return $this->cache->rememberForever(static::class . '@count', function() { |
|
|
|
|
107
|
3 |
|
return $this->positionRepository->count(); |
108
|
3 |
|
}); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Update the position model |
113
|
|
|
* |
114
|
|
|
* @param int $id |
|
|
|
|
115
|
|
|
* @param int $dataProviderId New data provider ID |
116
|
|
|
* @return PositionModel |
|
|
|
|
117
|
|
|
*/ |
118
|
2 |
|
public function update(int $id, int $dataProviderId): PositionModel |
119
|
|
|
{ |
120
|
2 |
|
return $this->positionRepository->update($id, $dataProviderId); |
121
|
|
|
} |
122
|
|
|
} |