Completed
Push — master ( 37cc1c...37cc1c )
by
unknown
12:03
created

QuizController::showIndexWelcome()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Models\Quiz;
7
use App\Models\User;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Illuminate\Support\Facades\DB;
10
use Illuminate\Support\Facades\Auth;
11
12
class QuizController extends Controller
13
{
14
    public function showIndexWelcome()
15
    {
16
        return view('index.welcome');
17
    }
18
19
    public function showHostDashboard()
20
    {
21
        // Move to trait/facade/logic class @TODO
22
        $quizCount = DB::table('user_quizzes')->where('user_id', Auth::user()->id)->count();
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
23
        return view('quiz_host.dashboard.index')->with('quizCount', $quizCount);
24
    }
25
26
    public function showHostManageQuizzes()
27
    {
28
        $quizzes = Quiz::leftJoin('user_quizzes', 'user_quizzes.quiz_id', 'quizzes.id')
29
                        ->join('users', 'user_quizzes.user_id', '=', 'users.id')
30
                        ->where('users.id', Auth::user()->id)
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
31
                        ->get();
32
33
        return view('quiz_host.dashboard.manage-quizzes')->with('quizzes', $quizzes);
34
    }
35
36
    public function create()
37
    {
38
        return view('quiz_host.dashboard.quiz.create');
39
    }
40
41
    public function store()
42
    {
43
        $quiz = new Quiz;
0 ignored issues
show
Unused Code introduced by
The assignment to $quiz is dead and can be removed.
Loading history...
44
    }
45
46
    public function showQuestion()
47
    {
48
        return view('quiz_user.question');
49
    }
50
51
    public function showPin()
52
    {
53
        return view('quiz_user.pin');
54
    }
55
56
    public function showSplash()
57
    {
58
        return view('quiz_user.splash');
59
    }
60
61
    public function enterQuizPin(Request $request)
62
    {
63
        // @TODO - PIN max length needs to be dynamic with trait
64
        // will sort out soon - Matt.
65
        $validatedData = $request->validate([
0 ignored issues
show
Unused Code introduced by
The assignment to $validatedData is dead and can be removed.
Loading history...
66
            'pin'      => 'required|string'
67
        ]);
68
69
        try {
70
            $quiz = Quiz::where('quiz_pin', $request->get('pin'))
71
                    ->where('active', '1')
72
                    ->firstOrFail();
73
        } catch (ModelNotFoundException $e) {
74
            return back()->with('pin_error', 'Either the quiz doesn\'t exist, or it hasn\'t been activated');
75
        }
76
        
77
        //Add user to the socket.io stuff!
78
        event(new \App\Events\addUser($request->get('username'))); //Adds the user to the socket stuff
79
        return redirect()->route('quiz_user.showSplash')->with('quizData', $quiz);
80
    }
81
}
82