1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oc\GeoCache\Persistence\GeoCacheLog; |
4
|
|
|
|
5
|
|
|
use Oc\Repository\Exception\RecordNotFoundException; |
6
|
|
|
use Oc\Repository\Exception\RecordsNotFoundException; |
7
|
|
|
|
8
|
|
|
class GeoCacheLogService |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var GeoCacheLogRepository |
|
|
|
|
12
|
|
|
*/ |
13
|
|
|
private $geoCacheRepository; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param GeoCacheLogRepository $geoCacheRepository |
|
|
|
|
17
|
|
|
*/ |
18
|
|
|
public function __construct(GeoCacheLogRepository $geoCacheRepository) |
19
|
|
|
{ |
20
|
|
|
$this->geoCacheRepository = $geoCacheRepository; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Fetches all GeoCacheLogs. |
25
|
|
|
* |
26
|
|
|
* @return GeoCacheLogEntity[] |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
public function fetchAll() |
29
|
|
|
{ |
30
|
|
|
try { |
31
|
|
|
$result = $this->geoCacheRepository->fetchAll(); |
32
|
|
|
} catch (RecordsNotFoundException $e) { |
33
|
|
|
$result = []; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $result; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Fetches the latest geo cache log for given user id. |
41
|
|
|
* |
42
|
|
|
* @param int $userId |
43
|
|
|
* |
44
|
|
|
* @return GeoCacheLogEntity|null |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function getLatestUserLog($userId) |
47
|
|
|
{ |
48
|
|
|
try { |
49
|
|
|
$result = $this->geoCacheRepository->getLatestUserLog($userId); |
50
|
|
|
} catch (RecordNotFoundException $e) { |
51
|
|
|
$result = null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $result; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Creates a GeoCacheLog in the database. |
59
|
|
|
* |
60
|
|
|
* @param GeoCacheLogEntity $entity |
|
|
|
|
61
|
|
|
* |
62
|
|
|
* @return GeoCacheLogEntity |
|
|
|
|
63
|
|
|
*/ |
64
|
|
|
public function create(GeoCacheLogEntity $entity) |
65
|
|
|
{ |
66
|
|
|
return $this->geoCacheRepository->create($entity); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Update a GeoCacheLog in the database. |
71
|
|
|
* |
72
|
|
|
* @param GeoCacheLogEntity $entity |
|
|
|
|
73
|
|
|
* |
74
|
|
|
* @return GeoCacheLogEntity |
|
|
|
|
75
|
|
|
*/ |
76
|
|
|
public function update(GeoCacheLogEntity $entity) |
77
|
|
|
{ |
78
|
|
|
return $this->geoCacheRepository->update($entity); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Removes a GeoCacheLog from the database. |
83
|
|
|
* |
84
|
|
|
* @param GeoCacheLogEntity $entity |
|
|
|
|
85
|
|
|
* |
86
|
|
|
* @return GeoCacheLogEntity |
|
|
|
|
87
|
|
|
*/ |
88
|
|
|
public function remove(GeoCacheLogEntity $entity) |
89
|
|
|
{ |
90
|
|
|
return $this->geoCacheRepository->remove($entity); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|