MeetingsController::show()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace plunner\Http\Controllers\Employees\Meetings;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\Response;
7
use plunner\Http\Controllers\Controller;
8
use plunner\Http\Requests;
9
use plunner\Meeting;
10
11
class MeetingsController extends Controller
12
{
13 15
    public function __construct()
14
    {
15 15
        config(['auth.model' => \plunner\Employee::class]);
16 15
        config(['jwt.user' => \plunner\Employee::class]);
17 15
        $this->middleware('jwt.authandrefresh:mode-en');
18 15
    }
19
20
    /**
21
     * Display a listing of the resource.
22
     *
23
     * @param Request $request needed for get query to get only current planed meetings
24
     * @return \Illuminate\Http\Response
25
     */
26 6
    public function index(Request $request)
27
    {
28 6
        $employee = \Auth::user();
29 6
        $meetings = $employee->meetings();
30 6
        if ($request->query('current'))
31 3
            $meetings->where(function ($query) { //parenthesis for conditions ...(C1 OR C2)...
32 3
                $query->where('start_time', '=', NULL);//to be planned
33
                //datetime to consider timezone, don't use mysql NOW()
34 3
                $query->orWhere('start_time', '>=', new \DateTime());//planned
35 3
            });
36 6
        return $meetings->get();
37
    }
38
39
    /**
40
     * Display the specified resource.
41
     *
42
     * @param  int $id
43
     * @return \Illuminate\Http\Response
44
     */
45 6
    public function show($id)
46
    {
47 6
        $meeting = Meeting::findOrFail($id);
48 6
        $this->authorize($meeting);
49 3
        return $meeting;
50
    }
51
52
    /**
53
     * Store a newly created resource in storage.
54
     *
55
     * @param int $meetingId
56
     * @return static
57
     */
58
    public function showImage($meetingId)
59
    {
60
        $meeting = Meeting::findOrFail($meetingId);
61
        $this->authorize($meeting);
62
        $ret = self::getImg($meeting);
63
        $blank = storage_path('img/meetings.jpg');
64
        if ($ret === false)
65
            return (new Response(file_get_contents($blank), 200))
66
                ->header('Content-Type', 'image/jpeg');
67
        return (new Response($ret, 200))
68
            ->header('Content-Type', 'image/jpeg');
69
    }
70
71
    private static function getImg(Meeting $meeting)
72
    {
73
        $name = 'meetings/' . $meeting->id;
74
        if (!\Storage::exists($name))
0 ignored issues
show
Bug introduced by
The method exists() does not seem to exist on object<Illuminate\Contracts\Filesystem\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
            return false;
76
        return \Storage::get($name);
77
    }
78
}
79