Completed
Push — dev5 ( 16c2ad...90e844 )
by Ron
08:07
created

AdminController::showLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\User;
6
use Illuminate\Http\Request;
7
use App\Http\Controllers\Controller;
8
9
class AdminController extends Controller
10
{
11
    public function __construct()
12
    {
13
        $this->middleware('auth');
14
    }
15
    
16
    //  Admin landing page
17
    public function index()
18
    {
19
        return view('admin.index');
20
    }
21
    
22
    //  Display all file links
23
    public function userLinks()
24
    {
25
        return view('admin.userLinks');
26
    }
27
    
28
    //  Get the number of links for each user
29
    public function countLinks()
30
    {
31
        $userLinks = User::with('FileLinks')->get();
32
        $linkCount = [];
33
        
34
        foreach($userLinks as $user)
35
        {
36
            $expired = $user->FileLinks->filter(function($lnk)
0 ignored issues
show
Bug introduced by
The property FileLinks does not exist on App\User. Did you mean fileLinks?
Loading history...
37
                       {
38
                           if($lnk->expire < date('Y-m-d'))
39
                           {
40
                               return $lnk;
41
                           }
42
                       })->count();
43
44
            $linkCount[] = [
45
                'user_id' => $user->user_id,
46
                'name'    => $user->first_name.' '.$user->last_name,
47
                'total'   => $user->FileLinks->count(),
48
                'expired' => $expired
49
            ];
50
        }
51
        
52
        return response()->json($linkCount);
53
    }
54
    
55
    //  Show the links for the selected user
56
    public function showLinks($id)
57
    {
58
        $user     = User::find($id);
59
        $userName = $user->first_name.' '.$user->last_name;
60
        
61
        return view('admin.linkDetails', [
62
            'userID' => $id,
63
            'name'   => $userName
64
        ]);
65
    }
66
}
67