snipe-it/app/Http/Controllers/DashboardController.php

52 lines
1.7 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
2016-03-25 01:18:05 -07:00
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Artisan;
2016-03-25 01:18:05 -07:00
2016-04-07 13:21:09 -07:00
/**
* This controller handles all actions related to the Admin Dashboard
* for the Snipe-IT Asset Management application.
*
* @author A. Gianotto <snipe@snipe.net>
* @version v1.0
2016-04-07 13:21:09 -07:00
*/
2016-03-25 01:18:05 -07:00
class DashboardController extends Controller
{
/**
* Check authorization and display admin dashboard, otherwise display
* the user's checked-out assets.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0]
* @return View
*/
public function index()
2016-03-25 01:18:05 -07:00
{
// Show the page
if (Auth::user()->hasAccess('admin')) {
$asset_stats = null;
2016-03-25 01:18:05 -07:00
2017-05-31 02:02:55 -07:00
$counts['asset'] = \App\Models\Asset::count();
$counts['accessory'] = \App\Models\Accessory::count();
$counts['license'] = \App\Models\License::assetcount();
$counts['consumable'] = \App\Models\Consumable::count();
$counts['component'] = \App\Models\Component::count();
$counts['user'] = \App\Models\Company::scopeCompanyables(Auth::user())->count();
$counts['grand_total'] = $counts['asset'] + $counts['accessory'] + $counts['license'] + $counts['consumable'];
2016-03-25 01:18:05 -07:00
if ((! file_exists(storage_path().'/oauth-private.key')) || (! file_exists(storage_path().'/oauth-public.key'))) {
Artisan::call('migrate', ['--force' => true]);
2017-10-11 12:42:31 -07:00
\Artisan::call('passport:install');
2016-03-25 01:18:05 -07:00
}
return view('dashboard')->with('asset_stats', $asset_stats)->with('counts', $counts);
2016-03-25 01:18:05 -07:00
} else {
// Redirect to the profile page
return redirect()->intended('account/view-assets');
2016-03-25 01:18:05 -07:00
}
}
}