|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\Tracker\Tasks; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\Tracker\Data\Repositories\TimeTrackerRepository; |
|
6
|
|
|
use App\Containers\Tracker\Models\TimeTracker; |
|
7
|
|
|
use App\Containers\User\Tasks\FindUserByVisitorIdTask; |
|
8
|
|
|
use App\Port\Action\Abstracts\Action; |
|
9
|
|
|
use Carbon\Carbon; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class UpdateTimeTrackerToCloseTask. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class UpdateTimeTrackerToCloseTask extends Action |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \App\Containers\User\Tasks\FindUserByVisitorIdTask |
|
21
|
|
|
*/ |
|
22
|
|
|
private $findUserByVisitorIdTask; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \App\Containers\Tracker\Data\Repositories\TimeTrackerRepository |
|
26
|
|
|
*/ |
|
27
|
|
|
private $timeTrackerRepository; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \App\Containers\Tracker\Tasks\FindTimeTrackerTask |
|
31
|
|
|
*/ |
|
32
|
|
|
private $findTimeTrackerTask; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* TrackOpenAction constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param \App\Containers\User\Tasks\FindUserByVisitorIdTask $findUserByVisitorIdTask |
|
38
|
|
|
* @param \App\Containers\Tracker\Data\Repositories\TimeTrackerRepository $timeTrackerRepository |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct( |
|
41
|
|
|
FindUserByVisitorIdTask $findUserByVisitorIdTask, |
|
42
|
|
|
TimeTrackerRepository $timeTrackerRepository, |
|
43
|
|
|
FindTimeTrackerTask $findTimeTrackerTask |
|
44
|
|
|
) { |
|
45
|
|
|
$this->findUserByVisitorIdTask = $findUserByVisitorIdTask; |
|
46
|
|
|
$this->timeTrackerRepository = $timeTrackerRepository; |
|
47
|
|
|
$this->findTimeTrackerTask = $findTimeTrackerTask; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param \App\Containers\Tracker\Models\TimeTracker $timeTracker |
|
52
|
|
|
* |
|
53
|
|
|
* @return \App\Containers\Tracker\Models\TimeTracker|mixed |
|
54
|
|
|
*/ |
|
55
|
|
|
public function run(TimeTracker $timeTracker) |
|
56
|
|
|
{ |
|
57
|
|
|
if ($timeTracker && $timeTracker->status == TimeTracker::PENDING) { |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$now = Carbon::now(); |
|
60
|
|
|
|
|
61
|
|
|
// get the time between now and when it was opened |
|
62
|
|
|
$durationsSeconds = $now->diffInSeconds($timeTracker->open_at); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$data = [ |
|
65
|
|
|
'status' => TimeTracker::SUCCEEDED, |
|
66
|
|
|
'close_at' => $now, |
|
67
|
|
|
'duration' => $durationsSeconds, |
|
68
|
|
|
]; |
|
69
|
|
|
$this->timeTrackerRepository->update($data, $timeTracker->id); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.