|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oc\FieldNotes\Form; |
|
4
|
|
|
|
|
5
|
|
|
use Oc\FieldNotes\Persistence\FieldNoteService; |
|
|
|
|
|
|
6
|
|
|
use DateTime; |
|
7
|
|
|
use Oc\GeoCache\Persistence\GeoCacheLog\GeoCacheLogService; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class UploadFormDataFactory |
|
11
|
|
|
* |
|
12
|
|
|
* @package Oc\FieldNotes\Form |
|
|
|
|
|
|
13
|
|
|
*/ |
|
14
|
|
|
class UploadFormDataFactory |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var FieldNoteService |
|
|
|
|
|
|
18
|
|
|
*/ |
|
19
|
|
|
private $fieldNoteService; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var GeoCacheLogService |
|
|
|
|
|
|
23
|
|
|
*/ |
|
24
|
|
|
private $geoCacheLogService; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* UploadFormDataFactory constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param FieldNoteService $fieldNoteService |
|
|
|
|
|
|
30
|
|
|
* @param GeoCacheLogService $geoCacheLogService |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(FieldNoteService $fieldNoteService, GeoCacheLogService $geoCacheLogService) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->fieldNoteService = $fieldNoteService; |
|
35
|
|
|
$this->geoCacheLogService = $geoCacheLogService; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Creates a UploadFormData by given user id. |
|
40
|
|
|
* |
|
41
|
|
|
* @param int $userId |
|
42
|
|
|
* |
|
43
|
|
|
* @return UploadFormData |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
public function create($userId) |
|
46
|
|
|
{ |
|
47
|
|
|
$uploadFormData = new UploadFormData(); |
|
48
|
|
|
|
|
49
|
|
|
$uploadFormData->userId = $userId; |
|
50
|
|
|
$uploadFormData->ignoreBeforeDate = $this->getLatestLogOrFieldNoteDate($userId); |
|
51
|
|
|
|
|
52
|
|
|
return $uploadFormData; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Fetches the latest log or field note date. |
|
57
|
|
|
* |
|
58
|
|
|
* @param int $userId |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
private function getLatestLogOrFieldNoteDate($userId) |
|
63
|
|
|
{ |
|
64
|
|
|
$fieldNoteDate = $this->getLatestFieldNoteDate($userId); |
|
65
|
|
|
|
|
66
|
|
|
$geoCacheLogDate = $this->getLatestLogDate($userId); |
|
67
|
|
|
|
|
68
|
|
|
return max($fieldNoteDate, $geoCacheLogDate); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
|
|
|
|
|
72
|
|
|
* Fetches the latest log date. |
|
73
|
|
|
* |
|
74
|
|
|
* @param $userId |
|
|
|
|
|
|
75
|
|
|
* |
|
76
|
|
|
* @return DateTime|null |
|
|
|
|
|
|
77
|
|
|
*/ |
|
78
|
|
|
private function getLatestLogDate($userId) |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$geoCacheLogDate = null; |
|
81
|
|
|
$geoCacheLog = $this->geoCacheLogService->getLatestUserLog($userId); |
|
82
|
|
|
|
|
83
|
|
|
if ($geoCacheLog) { |
|
84
|
|
|
$geoCacheLogDate = $geoCacheLog->date; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $geoCacheLogDate; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
|
|
|
|
|
91
|
|
|
* Fetches the latest field note date. |
|
92
|
|
|
* |
|
93
|
|
|
* @param $userId |
|
|
|
|
|
|
94
|
|
|
* |
|
95
|
|
|
* @return DateTime|null |
|
|
|
|
|
|
96
|
|
|
*/ |
|
97
|
|
|
private function getLatestFieldNoteDate($userId) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
$fieldNoteDate = null; |
|
100
|
|
|
$fieldNote = $this->fieldNoteService->getLatestUserFieldNote($userId); |
|
101
|
|
|
|
|
102
|
|
|
if ($fieldNote) { |
|
103
|
|
|
$fieldNoteDate = $fieldNote->date; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $fieldNoteDate; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|