mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
Add Video Listing with Pagination
This commit is contained in:
@@ -8,8 +8,17 @@ use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class VideosController extends Controller
|
||||
{
|
||||
|
||||
public function index() {
|
||||
$videos = Video::orderByRaw('udf_NaturalSortFormat(alias, 10, ".")')->paginate(50);
|
||||
|
||||
return view('videos', [
|
||||
'videos' => $videos
|
||||
]);
|
||||
}
|
||||
|
||||
// Source: https://stackoverflow.com/q/36778167
|
||||
public function do($alias) {
|
||||
public function show($alias) {
|
||||
set_time_limit(0);
|
||||
|
||||
$video = Video::where('alias', $alias)->firstOrFail();
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateNaturalSort extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::unprepared("DROP FUNCTION IF EXISTS `udf_FirstNumberPos`;
|
||||
CREATE FUNCTION `udf_FirstNumberPos` (`instring` varchar(4000))
|
||||
RETURNS int
|
||||
LANGUAGE SQL
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
SQL SECURITY INVOKER
|
||||
BEGIN
|
||||
DECLARE position int;
|
||||
DECLARE tmp_position int;
|
||||
SET position = 5000;
|
||||
SET tmp_position = LOCATE('0', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('1', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('2', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('3', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('4', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('5', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('6', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('7', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('8', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
SET tmp_position = LOCATE('9', instring); IF (tmp_position > 0 AND tmp_position < position) THEN SET position = tmp_position; END IF;
|
||||
|
||||
IF (position = 5000) THEN RETURN 0; END IF;
|
||||
RETURN position;
|
||||
END");
|
||||
|
||||
DB::unprepared("DROP FUNCTION IF EXISTS `udf_NaturalSortFormat`;
|
||||
CREATE FUNCTION `udf_NaturalSortFormat` (`instring` varchar(4000), `numberLength` int, `sameOrderChars` char(50))
|
||||
RETURNS varchar(4000)
|
||||
LANGUAGE SQL
|
||||
DETERMINISTIC
|
||||
NO SQL
|
||||
SQL SECURITY INVOKER
|
||||
BEGIN
|
||||
DECLARE sortString varchar(4000);
|
||||
DECLARE numStartIndex int;
|
||||
DECLARE numEndIndex int;
|
||||
DECLARE padLength int;
|
||||
DECLARE totalPadLength int;
|
||||
DECLARE i int;
|
||||
DECLARE sameOrderCharsLen int;
|
||||
|
||||
SET totalPadLength = 0;
|
||||
SET instring = TRIM(instring);
|
||||
SET sortString = instring;
|
||||
SET numStartIndex = udf_FirstNumberPos(instring);
|
||||
SET numEndIndex = 0;
|
||||
SET i = 1;
|
||||
SET sameOrderCharsLen = CHAR_LENGTH(sameOrderChars);
|
||||
|
||||
WHILE (i <= sameOrderCharsLen) DO
|
||||
SET sortString = REPLACE(sortString, SUBSTRING(sameOrderChars, i, 1), ' ');
|
||||
SET i = i + 1;
|
||||
END WHILE;
|
||||
|
||||
WHILE (numStartIndex <> 0) DO
|
||||
SET numStartIndex = numStartIndex + numEndIndex;
|
||||
SET numEndIndex = numStartIndex;
|
||||
|
||||
WHILE (udf_FirstNumberPos(SUBSTRING(instring, numEndIndex, 1)) = 1) DO
|
||||
SET numEndIndex = numEndIndex + 1;
|
||||
END WHILE;
|
||||
|
||||
SET numEndIndex = numEndIndex - 1;
|
||||
|
||||
SET padLength = numberLength - (numEndIndex + 1 - numStartIndex);
|
||||
|
||||
IF padLength < 0 THEN
|
||||
SET padLength = 0;
|
||||
END IF;
|
||||
|
||||
SET sortString = INSERT(sortString, numStartIndex + totalPadLength, 0, REPEAT('0', padLength));
|
||||
|
||||
SET totalPadLength = totalPadLength + padLength;
|
||||
SET numStartIndex = udf_FirstNumberPos(RIGHT(instring, CHAR_LENGTH(instring) - numEndIndex));
|
||||
END WHILE;
|
||||
|
||||
RETURN sortString;
|
||||
END");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::unprepared("DROP FUNCTION IF EXISTS `udf_FirstNumberPos`");
|
||||
DB::unprepared("DROP FUNCTION IF EXISTS `udf_NaturalSortFormat`");
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,6 @@
|
||||
<li><a href="https://www.reddit.com/r/AnimeThemes/">Reddit</a></li>
|
||||
<li><a href="https://twitter.com/parameterized">Twitter</a></li>
|
||||
<li><a href="https://github.com/paranarimasu/AnimeThemes">Github</a></li>
|
||||
<li><a href="{{ route('video.index') }}">Browse</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
@@ -0,0 +1,19 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="jumbotron">
|
||||
<h1>AnimeThemes</h1>
|
||||
<p class="lead">A simple and consistent repository of anime opening and ending themes</p>
|
||||
</div>
|
||||
@include('layouts.announcements')
|
||||
@include('layouts.webm')
|
||||
@include('layouts.nav')
|
||||
|
||||
<br>
|
||||
|
||||
@foreach ($videos as $video)
|
||||
<p><a href="{{ route('video.show', ['alias' => $video->alias]) }}">{{ $video->alias }}</a></p>
|
||||
@endforeach
|
||||
|
||||
<nav>{{ $videos->links() }}</nav>
|
||||
@endsection
|
||||
+3
-1
@@ -12,4 +12,6 @@
|
||||
*/
|
||||
|
||||
Route::get('/', 'WelcomeController@do')->name('welcome');
|
||||
Route::get('/video/{alias}', 'VideosController@do');
|
||||
Route::resource('video', 'VideosController', ['only' => [
|
||||
'index', 'show'
|
||||
]]);
|
||||
Reference in New Issue
Block a user