datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
datatable.directory/app/Http/Controllers/DashController.php

73 lines
2.3 KiB

<?php
namespace App\Http\Controllers;
use App\Models\Table;
use App\Models\User;
use Illuminate\Http\Request;
use MightyPork\Utils\Utils;
class DashController extends Controller
{
public function view(Request $request)
{
$dismiss = false;
if ($request->has('dismiss-greeter')) {
$dismiss = Utils::parseBool01($request->get('dismiss-greeter'));
\Cookie::queue('dismiss-greeter', $dismiss, 24*60*365*10);
return back();
}
$data['tableSort'] = $sort = \Input::get('tableSort', 'last-updated');
$data['sortOptions'] = [
'most-visited' => 'Most Visited',
'last-updated' => 'Last Updated',
'most-updated' => 'Most Changed',
// 'most-discussed' => 'Most Discussed',
// 'most-liked' => 'Most Liked',
'newest' => 'Newest',
'oldest' => 'Oldest',
];
$data['users'] = User::orderBy('updated_at', 'desc')
->withCount(['tables'])
->paginate(10, ['id', 'title', 'name', 'tables_count'], 'userPage')
->appends(\Input::except('userPage'));
$tableQuery = Table::forList();
switch ($sort) {
case 'most-visited':
$tableQuery = $tableQuery->orderBy('visits', 'desc');
break;
case 'last-updated':
$tableQuery = $tableQuery->orderBy('updated_at', 'desc');
break;
case 'most-updated':
$tableQuery = $tableQuery->orderBy('revisions_count', 'desc');
break;
case 'most-discussed':
$tableQuery = $tableQuery->orderBy('comments_count', 'desc');
break;
case 'most-liked':
$tableQuery = $tableQuery->orderBy('favourites_count', 'desc');
break;
case 'newest':
$tableQuery = $tableQuery->orderBy('created_at', 'desc');
break;
case 'oldest':
$tableQuery = $tableQuery->orderBy('created_at', 'asc');
break;
}
$data['tables'] = $tableQuery->paginate(10, ['*'], 'tablePage')
->appends(\Input::except('tablePage'));
$data['showGreeter'] = !$dismiss && !$request->cookie('dismiss-greeter', false);
return view('welcome', $data);
}
}