mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
Optimize filter of skin library
This commit is contained in:
parent
874f4bd681
commit
5c7b8bf6b2
@ -32,41 +32,41 @@ class SkinlibController extends Controller
|
||||
{
|
||||
$filter = $request->input('filter', 'skin');
|
||||
$sort = $request->input('sort', 'time');
|
||||
$uid = $request->input('uid', session('uid'));
|
||||
$page = $request->input('page', 1);
|
||||
$page = $page <= 0 ? 1 : $page;
|
||||
$uid = intval($request->input('uid', 0));
|
||||
$page = $request->input('page', 1) <= 0 ? 1 : $request->input('page', 1);
|
||||
|
||||
$sort_by = ($sort == "time") ? "upload_at" : $sort;
|
||||
|
||||
if ($filter == "skin") {
|
||||
$textures = Texture::where(function($query) {
|
||||
$query->where('type', '=', 'steve')
|
||||
->orWhere('type', '=', 'alex');
|
||||
})->orderBy($sort_by, 'desc');
|
||||
|
||||
} elseif ($filter == "user") {
|
||||
$textures = Texture::where('uploader', $uid)->orderBy($sort_by, 'desc');
|
||||
|
||||
$textures = Texture::where('type', 'steve')->orWhere('type', 'alex');
|
||||
} else {
|
||||
$textures = Texture::where('type', $filter)->orderBy($sort_by, 'desc');
|
||||
$textures = Texture::where('type', $filter);
|
||||
}
|
||||
|
||||
$textures = $textures->orderBy($sort_by, 'desc')->get();
|
||||
|
||||
if ($uid != 0) {
|
||||
$textures = $textures->where('uploader', $uid);
|
||||
}
|
||||
|
||||
if (!is_null($this->user)) {
|
||||
// show private textures when show uploaded textures of current user
|
||||
if (!$this->user->isAdmin())
|
||||
$textures = $textures->where('public', '1')
|
||||
->orWhere('uploader', $this->user->uid);
|
||||
if ($uid != $this->user->uid && !$this->user->isAdmin()) {
|
||||
$textures = $textures->where('public', 1)
|
||||
->merge($textures->where('uploader', $this->user->uid));
|
||||
}
|
||||
} else {
|
||||
$textures = $textures->where('public', '1');
|
||||
}
|
||||
|
||||
$total_pages = ceil($textures->count() / 20);
|
||||
|
||||
$textures = $textures->skip(($page - 1) * 20)->take(20)->get();
|
||||
$textures = $textures->slice(($page - 1) * 20);
|
||||
|
||||
return view('skinlib.index')->with('user', $this->user)
|
||||
->with('sort', $sort)
|
||||
->with('filter', $filter)
|
||||
->with('uploader', $uid)
|
||||
->with('textures', $textures)
|
||||
->with('page', $page)
|
||||
->with('total_pages', $total_pages);
|
||||
@ -96,6 +96,7 @@ class SkinlibController extends Controller
|
||||
return view('skinlib.search')->with('user', $this->user)
|
||||
->with('sort', $sort)
|
||||
->with('filter', $filter)
|
||||
->with('uploader', 0)
|
||||
->with('q', $q)
|
||||
->with('textures', $textures);
|
||||
}
|
||||
|
@ -39,14 +39,14 @@
|
||||
<i class="fa fa-filter" aria-hidden="true"></i> {{ trans('skinlib.general.filter') }} <span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=skin&sort={{ $sort }}'>{{ trans('general.skin') }} <small>{{ trans('skinlib.filter.any-model') }}</small></a></li>
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=steve&sort={{ $sort }}'>{{ trans('general.skin') }} <small>{{ trans('skinlib.filter.steve-model') }}</small></a></li>
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=alex&sort={{ $sort }}'>{{ trans('general.skin') }} <small>{{ trans('skinlib.filter.alex-model') }}</small></a></li>
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=skin&{{ isset($_GET["uid"]) ? "uid=$uploader&" : "" }}sort={{ $sort }}'>{{ trans('general.skin') }} <small>{{ trans('skinlib.filter.any-model') }}</small></a></li>
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=steve&{{ isset($_GET["uid"]) ? "uid=$uploader&" : "" }}sort={{ $sort }}'>{{ trans('general.skin') }} <small>{{ trans('skinlib.filter.steve-model') }}</small></a></li>
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=alex&{{ isset($_GET["uid"]) ? "uid=$uploader&" : "" }}sort={{ $sort }}'>{{ trans('general.skin') }} <small>{{ trans('skinlib.filter.alex-model') }}</small></a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=cape&sort={{ $sort }}'>{{ trans('general.cape') }}</a></li>
|
||||
<li><a href='?{{ isset($_GET["q"]) ? "q=$q&" : "" }}filter=cape&{{ isset($_GET["uid"]) ? "uid=$uploader&" : "" }}sort={{ $sort }}'>{{ trans('general.cape') }}</a></li>
|
||||
@if (!is_null($user))
|
||||
<li class="divider"></li>
|
||||
<li><a href="?filter=user&uid={{ $user->uid }}&sort={{ $sort }}">{{ trans('skinlib.general.my-upload') }}</a></li>
|
||||
<li><a href="?{{ isset($_GET["filter"]) ? "filter=$filter&" : "" }}uid={{ $user->uid }}&sort={{ $sort }}">{{ trans('skinlib.general.my-upload') }}</a></li>
|
||||
@endif
|
||||
<li class="divider"></li>
|
||||
<li><a href="{{ url('skinlib') }}">{{ trans('skinlib.filter.clean-filter') }}</a></li>
|
||||
|
@ -75,7 +75,7 @@
|
||||
<tr>
|
||||
<td>{{ trans('skinlib.show.uploader') }}</td>
|
||||
@if ($uploader = app('users')->get($texture->uploader))
|
||||
<td><a href="{{ url('skinlib?filter=user&uid='.$uploader->uid) }}&sort=time">{{ $uploader->getNickName() }}</a></td>
|
||||
<td><a href="{{ url('skinlib?filter='.($texture->type == 'cape' ? 'cape' : 'skin').'&uid='.$uploader->uid) }}&sort=time">{{ $uploader->getNickName() }}</a></td>
|
||||
@else
|
||||
<td><a href="#">{{ trans('general.unexistent-user') }}</a></td>
|
||||
@endif
|
||||
|
9
resources/views/vendor/breadcrumb.tpl
vendored
9
resources/views/vendor/breadcrumb.tpl
vendored
@ -5,17 +5,18 @@
|
||||
{{ trans('skinlib.filter.skin') }}
|
||||
<small>{{ trans('skinlib.filter.any-model') }}</small>
|
||||
@elseif ($filter == "steve")
|
||||
{{ trans('skinlib.filter.any-model') }}
|
||||
<small>({{ trans('skinlib.filter.steve-model') }})</small>
|
||||
{{ trans('skinlib.filter.skin') }}
|
||||
<small>{{ trans('skinlib.filter.steve-model') }}</small>
|
||||
@elseif ($filter == "alex")
|
||||
{{ trans('skinlib.filter.skin') }}
|
||||
<small>{{ trans('skinlib.filter.alex-model') }}</small>
|
||||
@elseif ($filter == "cape")
|
||||
{{ trans('skinlib.filter.cape') }}
|
||||
@elseif ($filter == "user")
|
||||
{{ trans('skinlib.filter.uploader', ['name' => App::make('users')->get($_GET['uid'])->getNickName()]) }}
|
||||
@endif
|
||||
</li>
|
||||
@unless ($uploader == 0)
|
||||
<li>{{ trans('skinlib.filter.uploader', ['name' => App::make('users')->get($_GET['uid'])->getNickName()]) }}</li>
|
||||
@endunless
|
||||
<li class="active">
|
||||
@if ($sort == "time")
|
||||
{{ trans('skinlib.sort.newest-uploaded') }}
|
||||
|
Loading…
Reference in New Issue
Block a user