@@ -2,11 +2,11 @@ | |||||
namespace App\Http\Controllers; | namespace App\Http\Controllers; | ||||
use App\Knockout\Post; | |||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use App\Knockout\User; | use App\Knockout\User; | ||||
use App\Knockout\UserPost; | use App\Knockout\UserPost; | ||||
use App\Knockout\UserThread; | use App\Knockout\UserThread; | ||||
use App\Knockout\UserBan; | |||||
class UserController extends Controller { | class UserController extends Controller { | ||||
@@ -71,9 +71,17 @@ class UserController extends Controller { | |||||
]); | ]); | ||||
} | } | ||||
public function bans() | |||||
public function bans(Request $request) | |||||
{ | { | ||||
return 'not implemented'; | |||||
$userId = $request->route('user', null); | |||||
$user = User::one($userId); | |||||
$bans = UserBan::all($userId); | |||||
return view('page/user-bans', [ | |||||
'user' => $user->getRecord(), | |||||
'bans' => $bans->getRecords() | |||||
]); | |||||
} | } | ||||
} | } |
@@ -0,0 +1,53 @@ | |||||
<?php | |||||
namespace App\Knockout; | |||||
use Carbon\Carbon; | |||||
class Ban { | |||||
// meta | |||||
public $id; | |||||
public $createdAt; | |||||
public $endsAt; | |||||
public $reason; | |||||
// related | |||||
public Post $post; | |||||
public Thread $thread; | |||||
public User $creator; | |||||
public User $user; | |||||
public static function unwrap($ban) | |||||
{ | |||||
$s = new self(); | |||||
$s->id = $ban->id; | |||||
$s->createdAt = Carbon::parse($ban->createdAt)->format('d/m/Y H:i'); | |||||
$s->endsAt = Carbon::parse($ban->expiresAt)->format('d/m/Y H:i'); | |||||
$s->reason = $ban->banReason; | |||||
// grab user if available | |||||
if (isset($ban->user)) { | |||||
$s->user = User::unwrap($ban->user); | |||||
} | |||||
// grab creator if available | |||||
if (isset($ban->bannedBy)) { | |||||
$s->creator = User::unwrap($ban->bannedBy); | |||||
} | |||||
// grab thread if available | |||||
if (isset($ban->thread)) { | |||||
$s->thread = Thread::unwrap($ban->thread); | |||||
} | |||||
// grab post if available | |||||
if (isset($ban->post)) { | |||||
$s->post = Post::unwrap($ban->post); | |||||
} | |||||
return $s; | |||||
} | |||||
} |
@@ -26,7 +26,7 @@ class Post { | |||||
$s->content = $post->content; | $s->content = $post->content; | ||||
// grab user if available | // grab user if available | ||||
if (isset($post->user)) { | |||||
if (isset($post->user) && isset($post->user->id)) { | |||||
$s->user = User::unwrap($post->user); | $s->user = User::unwrap($post->user); | ||||
} | } | ||||
@@ -124,7 +124,7 @@ class Thread { | |||||
} | } | ||||
// grab last post if available | // grab last post if available | ||||
if (isset($thread->lastPost)) { | |||||
if (isset($thread->lastPost) && isset($thread->lastPost->id)) { | |||||
$s->lastPost = Post::unwrap($thread->lastPost); | $s->lastPost = Post::unwrap($thread->lastPost); | ||||
} | } | ||||
@@ -0,0 +1,35 @@ | |||||
<?php | |||||
namespace App\Knockout; | |||||
use Illuminate\Support\Facades\Cache; | |||||
class UserBan { | |||||
private static function requestAll(int $userId): Dataset | |||||
{ | |||||
$data = (new AbstractData)->httpGet(sprintf('/user/%u/bans', $userId)); | |||||
$json = json_decode($data); | |||||
$records = array_map(function($user) { | |||||
return Ban::unwrap($user); | |||||
}, $json); | |||||
return (new Dataset($records)); | |||||
} | |||||
public static function updateAll(int $userId): Dataset | |||||
{ | |||||
$key = sprintf('user-bans-%u', $userId); | |||||
$data = self::requestAll($userId); | |||||
Cache::put($key, $data, 300); | |||||
return $data; | |||||
} | |||||
public static function all(int $userId): Dataset | |||||
{ | |||||
$key = sprintf('user-bans-%u', $userId); | |||||
return Cache::get($key, function() use($userId) { | |||||
return self::updateAll($userId); | |||||
}); | |||||
} | |||||
} |
@@ -0,0 +1,34 @@ | |||||
@extends('default') | |||||
@section('title', $user->username . ' Bans') | |||||
@section('breadcrumb') | |||||
<a href="{{ route('index') }}">Home</a> | |||||
<a>></a> | |||||
<a href="{{ route('users') }}">Users</a> | |||||
<a>></a> | |||||
<a href="{{ route('user', ['user' => $user->id]) }}">{{ $user->username }}</a> | |||||
<a>></a> | |||||
<a href="{{ route('user.bans', ['user' => $user->id]) }}">Bans</a> | |||||
@endsection | |||||
@section('content') | |||||
@foreach($bans as $ban) | |||||
<div class="row"> | |||||
<b>{{ $ban->user->username }}</b> was banned by <b>{{ $ban->creator->username }}</b> at <b>{{ $ban->createdAt }}</b> until <b>{{ $ban->endsAt }}</b> | |||||
<br/>Reason: "{{ $ban->reason }}" | |||||
</div> | |||||
<div class="row post"> | |||||
<div class="inner"> | |||||
<div class="postContent"> | |||||
{!! $ban->post->render() !!} | |||||
</div> | |||||
</div> | |||||
</div> | |||||
<div class="row spacer"></div> | |||||
@endforeach | |||||
@endsection | |||||
@section('scripts') | |||||
<link rel='stylesheet' type='text/css' href='/css/page/thread.css'/> | |||||
@endsection |
@@ -11,7 +11,7 @@ | |||||
@endsection | @endsection | ||||
@section('content') | @section('content') | ||||
@include('partial/user'); | |||||
@include('partial/user') | |||||
<div class="row spacer"></div> | <div class="row spacer"></div> | ||||
<div class="row"> | <div class="row"> | ||||
<p>Will add bios later, probably</p> | <p>Will add bios later, probably</p> | ||||
@@ -73,7 +73,7 @@ $router->get('/user/{user}/threads[/{page}]', [ | |||||
'uses' => 'UserController@threads' | 'uses' => 'UserController@threads' | ||||
]); | ]); | ||||
$router->get('/user/{user}/bans[/{page}]', [ | |||||
$router->get('/user/{user}/bans', [ | |||||
'as' => 'user.bans', | 'as' => 'user.bans', | ||||
'uses' => 'UserController@bans' | 'uses' => 'UserController@bans' | ||||
]); | ]); | ||||