Skip to content

Commit

Permalink
Added Leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
zalsader committed Sep 17, 2015
1 parent e7b4672 commit 1f22407
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
7 changes: 7 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;

class HomeController extends Controller
{
Expand All @@ -17,4 +18,10 @@ class HomeController extends Controller
public function home() {
return \Redirect::to('login');
}

public function leaderboard() {
$this->authorize('grade', null);
$users = User::orderBy('total_score', 'desc')->get();
return view('leaderboard')->with(compact(['users']));
}
}
1 change: 1 addition & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

Route::get('/','HomeController@home');
Route::get('/leaderboard','HomeController@leaderboard');
Route::get('login','Auth\AuthController@getLogin');
Route::post('login','Auth\AuthController@postLogin');
Route::get('signup','Auth\AuthController@getRegister');
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
37 changes: 37 additions & 0 deletions resources/views/leaderboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@extends('app')

@section('content')
<div class="container">

<div class="row">
<div class="col-md-10" >
<div class="">
<h1>All Users</h1>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th width="5%">Rank</th>
<th width="30%">Name</th>
<th width="35%">Email</th>
<th width="30%">Total Score</th>
</tr>
</thead>
<tbody>
@foreach($users as $i => $user)
<tr>
<td>{{$i+1}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{round($user->total_score,5)}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<hr>
</div>
</div>
</div>
</div>
@stop
13 changes: 8 additions & 5 deletions resources/views/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
@endforelse
</div>
</div>
@if(false)
@can('grade', null)
<div class=" col-md-2 well">
<div class="row">
<center><label style="font-size:21px; color:#19a2e4;">Leaderboard</label></center>
Expand All @@ -63,27 +63,30 @@
{{$i+1}}.<span>{{$leader->name}}</span>
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="50" aria-valuemin="10" aria-valuemax="100" style="width:{{$leader->total_score *100 / $maxScore}}%">
<span id="topscore{{$leader->id}}">{{$leader->total_score}}</span>
<span id="topscore{{$leader->id}}">{{round($leader->total_score, 5)}}</span>
</div>
</div>
</div>
<br>
@endforeach

<div class=""><hr></div>
<div class="row">
<center><label style="font-size:17px; color:#19a2e4;">You are #<span>{{$myRank}}</span></label></center>
</div>
<div class="" style="height:25px;">
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:{{$myTotalScore *100 / $maxScore}}%">
<span data-width="{{$myTotalScore}}">{{$myTotalScore}}</span>
<span data-width="{{$myTotalScore}}">{{round($myTotalScore,5)}}</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1"><a class="btn btn-success" href="{{url('leaderboard')}}" width="100%">Full Leaderboard</a></div>
</div>
</div>
</div>
@endif
@endcan
</div>
</div>
@stop

0 comments on commit 1f22407

Please sign in to comment.