|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\Tracker\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\Tracker\Models\TimeTracker; |
|
6
|
|
|
use App\Containers\Tracker\Services\FindTimeTrackerService; |
|
7
|
|
|
use App\Containers\Tracker\Settings\Repositories\TimeTrackerRepository; |
|
8
|
|
|
use App\Containers\User\Services\FindUserService; |
|
9
|
|
|
use App\Port\Action\Abstracts\Action; |
|
10
|
|
|
use Carbon\Carbon; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class TrackOpenAction. |
|
14
|
|
|
* |
|
15
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class TrackOpenAction extends Action |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var \App\Containers\User\Services\FindUserService |
|
22
|
|
|
*/ |
|
23
|
|
|
private $findUserService; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \App\Containers\Tracker\Settings\Repositories\TimeTrackerRepository |
|
27
|
|
|
*/ |
|
28
|
|
|
private $timeTrackerRepository; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \App\Containers\Tracker\Services\FindTimeTrackerService |
|
32
|
|
|
*/ |
|
33
|
|
|
private $findTimeTrackerService; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* TrackOpenAction constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param \App\Containers\User\Services\FindUserService $findUserService |
|
39
|
|
|
* @param \App\Containers\Tracker\Settings\Repositories\TimeTrackerRepository $timeTrackerRepository |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
FindUserService $findUserService, |
|
43
|
|
|
TimeTrackerRepository $timeTrackerRepository, |
|
44
|
|
|
FindTimeTrackerService $findTimeTrackerService |
|
45
|
|
|
) { |
|
46
|
|
|
$this->findUserService = $findUserService; |
|
47
|
|
|
$this->timeTrackerRepository = $timeTrackerRepository; |
|
48
|
|
|
$this->findTimeTrackerService = $findTimeTrackerService; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param $email |
|
53
|
|
|
* @param $password |
|
54
|
|
|
* |
|
55
|
|
|
* @return mixed |
|
56
|
|
|
*/ |
|
57
|
|
|
public function run($visitorId) |
|
58
|
|
|
{ |
|
59
|
|
|
$user = $this->findUserService->byVisitorId($visitorId); |
|
60
|
|
|
|
|
61
|
|
|
// check if any previous session was not closed |
|
62
|
|
|
$timeTracker = $this->findTimeTrackerService->byUserIdAndStatusNull($user->id); |
|
63
|
|
|
if ($timeTracker && $timeTracker->status == TimeTracker::PENDING) { |
|
64
|
|
|
$this->timeTrackerRepository->update(['status' => TimeTracker::FAILED], $timeTracker->id); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// create the new record with pending status |
|
68
|
|
|
$timeTracker = new TimeTracker(); |
|
69
|
|
|
$timeTracker->open_at = Carbon::now(); |
|
|
|
|
|
|
70
|
|
|
$timeTracker->status = TimeTracker::PENDING; |
|
|
|
|
|
|
71
|
|
|
$timeTracker->user()->associate($user); |
|
72
|
|
|
$timeTracker = $this->timeTrackerRepository->create($timeTracker->toArray()); |
|
73
|
|
|
|
|
74
|
|
|
return $timeTracker; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write 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.