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