Completed
Push — master ( 0f7f58...ca9e28 )
by Arthur
09:32
created

ActivityController::realtime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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