Browse Source

Add user ban listing

staging
Christopher Ross Hind 3 years ago
parent
commit
ddc964a1cc
8 changed files with 137 additions and 7 deletions
  1. +11
    -3
      app/Http/Controllers/UserController.php
  2. +53
    -0
      app/Knockout/Ban.php
  3. +1
    -1
      app/Knockout/Post.php
  4. +1
    -1
      app/Knockout/Thread.php
  5. +35
    -0
      app/Knockout/UserBan.php
  6. +34
    -0
      resources/views/page/user-bans.blade.php
  7. +1
    -1
      resources/views/page/user.blade.php
  8. +1
    -1
      routes/web.php

+ 11
- 3
app/Http/Controllers/UserController.php View File

@@ -2,11 +2,11 @@

namespace App\Http\Controllers;

use App\Knockout\Post;
use Illuminate\Http\Request;
use App\Knockout\User;
use App\Knockout\UserPost;
use App\Knockout\UserThread;
use App\Knockout\UserBan;

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()
]);
}

}

+ 53
- 0
app/Knockout/Ban.php View File

@@ -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;
}

}

+ 1
- 1
app/Knockout/Post.php View File

@@ -26,7 +26,7 @@ class Post {
$s->content = $post->content;

// grab user if available
if (isset($post->user)) {
if (isset($post->user) && isset($post->user->id)) {
$s->user = User::unwrap($post->user);
}



+ 1
- 1
app/Knockout/Thread.php View File

@@ -124,7 +124,7 @@ class Thread {
}

// grab last post if available
if (isset($thread->lastPost)) {
if (isset($thread->lastPost) && isset($thread->lastPost->id)) {
$s->lastPost = Post::unwrap($thread->lastPost);
}



+ 35
- 0
app/Knockout/UserBan.php View File

@@ -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);
});
}

}

+ 34
- 0
resources/views/page/user-bans.blade.php View File

@@ -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

+ 1
- 1
resources/views/page/user.blade.php View File

@@ -11,7 +11,7 @@
@endsection

@section('content')
@include('partial/user');
@include('partial/user')
<div class="row spacer"></div>
<div class="row">
<p>Will add bios later, probably</p>


+ 1
- 1
routes/web.php View File

@@ -73,7 +73,7 @@ $router->get('/user/{user}/threads[/{page}]', [
'uses' => 'UserController@threads'
]);

$router->get('/user/{user}/bans[/{page}]', [
$router->get('/user/{user}/bans', [
'as' => 'user.bans',
'uses' => 'UserController@bans'
]);


Loading…
Cancel
Save