remodelled homecontroller a bit

This commit is contained in:
flash 2016-12-21 17:46:12 +01:00
parent ca685bd460
commit a5750187d7
5 changed files with 28 additions and 29 deletions

View file

@ -33,6 +33,7 @@ class HomeController extends Controller
->orderBy('user_id', 'desc') ->orderBy('user_id', 'desc')
->limit(1) ->limit(1)
->get(['user_id']); ->get(['user_id']);
$newestUser = User::construct($newestUserId ? $newestUserId[0]->user_id : 0); $newestUser = User::construct($newestUserId ? $newestUserId[0]->user_id : 0);
// Get all the currently online users // Get all the currently online users
@ -58,28 +59,27 @@ class HomeController extends Controller
$onlineUsers[$user->id] = $user; $onlineUsers[$user->id] = $user;
} }
//$news = new Category(config('general.news')); $news = []; //new Category(config('general.news'));
Template::vars([ $userCount = DB::table('users')
'news' => [], ->where('rank_main', '!=', config('rank.banned'))
'stats' => [ ->where('user_activated', 1)
'userCount' => DB::table('users') ->where('user_restricted', 0)
->where('rank_main', '!=', config('rank.banned')) ->count();
->where('user_activated', 1)
->where('user_restricted', 0)
->count(),
'newestUser' => $newestUser,
'lastRegDate' => date_diff(
date_create(date('Y-m-d', $newestUser->registered)),
date_create(date('Y-m-d'))
)->format('%a'),
'topicCount' => DB::table('topics')->where('forum_id', '!=', config('forum.trash'))->count(),
'postCount' => DB::table('posts')->where('forum_id', '!=', config('forum.trash'))->count(),
'onlineUsers' => $onlineUsers,
],
]);
// Return the compiled page $lastRegDate = date_diff(
return Template::render('meta/index'); date_create(date('Y-m-d', $newestUser->registered)),
date_create(date('Y-m-d'))
)->format('%a');
$trashId = config('forum.trash');
$topicCount = DB::table('topics')
->where('forum_id', '!=', $trashId)
->count();
$postCount = DB::table('posts')
->where('forum_id', '!=', $trashId)
->count();
return view('home/index', compact('news', 'userCount', 'newestUser', 'lastRegDate', 'topicCount', 'postCount', 'onlineUsers'));
} }
} }

View file

@ -21,14 +21,14 @@
</div> </div>
{% endif %} {% endif %}
<div class="content__header content__header--alt">Stats</div> <div class="content__header content__header--alt">Stats</div>
We have <b>{{ stats.userCount }} user{% if stats.userCount != 1 %}s{% endif %}</b>, We have <b>{{ userCount }} user{% if userCount != 1 %}s{% endif %}</b>,
<b><a href="{{ route('user.profile', stats.newestUser.id) }}" style="color: {{ stats.newestUser.colour }};">{{ stats.newestUser.username }}</a></b> is the newest user, <b><a href="{{ route('user.profile', newestUser.id) }}" style="color: {{ newestUser.colour }};">{{ newestUser.username }}</a></b> is the newest user,
it has been <b>{{ stats.lastRegDate }} day{{ stats.lastRegDate == 1 ? '' : 's' }}</b> since the last user registered and the forum has <b>{{ stats.topicCount }} topic{% if stats.topicCount != 1 %}s{% endif %}</b> and <b>{{ stats.postCount }} post{% if stats.postCount != 1 %}s{% endif %}</b>. it has been <b>{{ lastRegDate }} day{{ lastRegDate == 1 ? '' : 's' }}</b> since the last user registered and the forum has <b>{{ topicCount }} topic{% if topicCount != 1 %}s{% endif %}</b> and <b>{{ postCount }} post{% if postCount != 1 %}s{% endif %}</b>.
<div class="content__header content__header--alt">Online Users</div> <div class="content__header content__header--alt">Online Users</div>
{% if stats.onlineUsers %} {% if onlineUsers %}
All active users in the past 2 minutes All active users in the past 2 minutes
<table class="sidepanel-table"> <table class="sidepanel-table">
{% for amount, onlineUser in stats.onlineUsers %} {% for amount, onlineUser in onlineUsers %}
<tr> <tr>
<td class="sidepanel-table__column sidepanel-table__column--align-left"> <td class="sidepanel-table__column sidepanel-table__column--align-left">
<a href="{{ route('user.profile', onlineUser.id) }}" style="font-weight: bold; color: {{ onlineUser.colour }};"> <a href="{{ route('user.profile', onlineUser.id) }}" style="font-weight: bold; color: {{ onlineUser.colour }};">

View file

@ -126,7 +126,7 @@
Yuuno.Main.Startup(); Yuuno.Main.Startup();
{% if config('dev.show_changelog') and stats is defined %} {% if config('dev.show_changelog') and server['REQUEST_URI'] == '/' %}
Sakura.Changelog.Build(Sakura.DOM.ID('indexPanel')); Sakura.Changelog.Build(Sakura.DOM.ID('indexPanel'));
{% endif %} {% endif %}

View file

@ -1 +0,0 @@
{% extends 'master.twig' %}

View file

@ -18,7 +18,7 @@ Router::filter('maintenance', function () {
}); });
Router::group(['before' => 'maintenance'], function () { Router::group(['before' => 'maintenance'], function () {
// Meta pages // Homepage
Router::get('/', 'HomeController@index', 'main.index'); Router::get('/', 'HomeController@index', 'main.index');
// Link compatibility layer, prolly remove this in like a year // Link compatibility layer, prolly remove this in like a year