Completed
Push — master ( 8927df...f70445 )
by Abdelrahman
02:05
created

DashboardController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 46
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B home() 0 28 1
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Http\Controllers\Backend;
17
18
19
use Carbon\Carbon;
20
use Illuminate\Support\Facades\DB;
21
use Rinvex\Fort\Http\Controllers\AuthorizedController;
22
23
class DashboardController extends AuthorizedController
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $resource = 'dashboard';
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $resourceAbilityMap = ['home'   => 'access'];
34
35
    /**
36
     * Show the dashboard home.
37
     *
38
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
39
     */
40
    public function home()
41
    {
42
        $abilityRepository = app('rinvex.fort.ability');
43
        $roleRepository    = app('rinvex.fort.role');
44
        $userRepository    = app('rinvex.fort.user');
45
46
        // Get recent registered users
47
        $limit = config('rinvex.fort.backend.items_per_dashboard');
48
        $users = $userRepository->orderBy('created_at', 'desc')->limit($limit)->findAll();
49
50
        // Get statistics
51
        $stats = [
52
            'abilities' => $abilityRepository->count(),
53
            'roles'     => $roleRepository->count(),
54
            'users'     => $userRepository->count(),
55
        ];
56
57
        // Get online users
58
        $onlineInterval = Carbon::now()->subMinutes(config('rinvex.fort.online.interval'));
59
        $persistences   = app('rinvex.fort.persistence')
60
            ->groupBy(['user_id'])
61
            ->with(['user'])
62
            ->where('attempt', '=', 0)
63
            ->where('updated_at', '>', $onlineInterval)
64
            ->findAll(['user_id', DB::raw('MAX(updated_at) as updated_at')]);
65
66
        return view('rinvex/fort::backend/dashboard.home', compact('users', 'persistences', 'stats'));
67
    }
68
}
69