|
1
|
|
|
<?php namespace BB\Http\Controllers; |
|
2
|
|
|
|
|
3
|
|
|
use Auth; |
|
4
|
|
|
use BB\Entities\Settings; |
|
5
|
|
|
use BB\Events\MemberActivity; |
|
6
|
|
|
use Carbon\Carbon; |
|
7
|
|
|
|
|
8
|
|
|
class ActivityController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var \BB\Repo\ActivityRepository |
|
13
|
|
|
*/ |
|
14
|
|
|
private $activityRepository; |
|
15
|
|
|
|
|
16
|
|
|
function __construct(\BB\Repo\ActivityRepository $activityRepository) |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
$this->activityRepository = $activityRepository; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Display a listing of the resource. |
|
23
|
|
|
* |
|
24
|
|
|
* @return Response |
|
25
|
|
|
*/ |
|
26
|
|
|
public function index() |
|
27
|
|
|
{ |
|
28
|
|
|
$date = \Input::get('date', \Carbon\Carbon::now()->format('Y-m-d')); |
|
29
|
|
|
$date = \Carbon\Carbon::createFromFormat('Y-m-d', $date)->setTime(0, 0, 0); |
|
30
|
|
|
$today = \Carbon\Carbon::now()->setTime(0, 0, 0); |
|
31
|
|
|
$doorPin = \Input::get('doorPin'); |
|
32
|
|
|
|
|
33
|
|
|
$logEntries = $this->activityRepository->getForDate($date); |
|
34
|
|
|
|
|
35
|
|
|
$nextDate = null; |
|
36
|
|
|
if ($date->lt($today)) { |
|
37
|
|
|
$nextDate = $date->copy()->addDay(); |
|
38
|
|
|
} |
|
39
|
|
|
$previousDate = $date->copy()->subDay(); |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
return \View::make('activity.index') |
|
44
|
|
|
->with('logEntries', $logEntries) |
|
45
|
|
|
->with('date', $date) |
|
46
|
|
|
->with('nextDate', $nextDate) |
|
47
|
|
|
->with('previousDate', $previousDate) |
|
48
|
|
|
->with('doorPin', $doorPin); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function create() |
|
52
|
|
|
{ |
|
53
|
|
|
$keyFob = Auth::user()->keyFob(); |
|
54
|
|
|
event(new MemberActivity($keyFob, 'main-door', Carbon::now(), true)); |
|
55
|
|
|
|
|
56
|
|
|
$doorPin = Settings::get('emergency_door_key_storage_pin'); |
|
57
|
|
|
|
|
58
|
|
|
return redirect(route('activity.index', ['doorPin' => $doorPin])); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return Response |
|
64
|
|
|
*/ |
|
65
|
|
|
public function realtime() |
|
66
|
|
|
{ |
|
67
|
|
|
return \View::make('activity.realtime'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.