59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\ShitUser;
|
|
use App\Models\User;
|
|
use Auth;
|
|
use Carbon\Carbon;
|
|
use DB;
|
|
|
|
class ShitController extends Controller
|
|
{
|
|
|
|
public function increment(Request $request) {
|
|
$shituser = new ShitUser();
|
|
|
|
$shituser->user_id = Auth::user()->id;
|
|
$shituser->description = $request->description;
|
|
$shituser->goldenshit = $request->goldenshit == "on";
|
|
|
|
// Get the latest shit event and check if it is over a time threshold
|
|
$lastshit = ShitUser::where('user_id', $shituser->user_id)->orderByDesc('created_at')->first();
|
|
|
|
$timethreshold = Carbon::now()->subMinutes(10);
|
|
if (is_null($lastshit) || $lastshit->created_at->lessThan($timethreshold)) {
|
|
$shituser->save();
|
|
return redirect('/ownstats');
|
|
} else {
|
|
return redirect('/dashboard');
|
|
}
|
|
|
|
}
|
|
|
|
public function ownStats() {
|
|
|
|
$shits = ShitUser::where('user_id', Auth::user()->id)->get();
|
|
$amountshits = $shits->count();
|
|
$goldenshits = $shits->where('goldenshit', true)->count();
|
|
|
|
return view('ownstats')->with([
|
|
'amountshits' => $amountshits,
|
|
'goldenshits' => $goldenshits,
|
|
]);
|
|
}
|
|
|
|
public function highscores() {
|
|
|
|
$allshits = ShitUser::groupBy('user_id')->select('user_id', DB::raw('count (*) as total'))->get();
|
|
$users = User::all()->sortBy('name');
|
|
|
|
return view('highscores')->with([
|
|
'allshits' => $allshits,
|
|
'users' => $users,
|
|
]);
|
|
}
|
|
|
|
}
|