74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\Downloads;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class DownloadsPatreon extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public $fileSearch;
|
|
|
|
public $order = 'created_at_desc';
|
|
|
|
protected $queryString = [
|
|
'fileSearch' => ['except' => '', 'as' => 'fS'],
|
|
'order' => ['except' => '', 'as' => 'order'],
|
|
];
|
|
|
|
public function updatingFileSearch()
|
|
{
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$orderby = 'created_at';
|
|
$orderdirection = 'desc';
|
|
|
|
switch ($this->order) {
|
|
case 'az':
|
|
$orderby = 'url';
|
|
$orderdirection = 'asc';
|
|
break;
|
|
case 'za':
|
|
$orderby = 'url';
|
|
$orderdirection = 'desc';
|
|
break;
|
|
case 'created_at_desc':
|
|
$orderby = 'created_at';
|
|
$orderdirection = 'desc';
|
|
break;
|
|
case 'created_at_asc':
|
|
$orderby = 'created_at';
|
|
$orderdirection = 'asc';
|
|
break;
|
|
case 'size_asc':
|
|
$orderby = 'size';
|
|
$orderdirection = 'asc';
|
|
break;
|
|
case 'size_desc':
|
|
$orderby = 'size';
|
|
$orderdirection = 'desc';
|
|
break;
|
|
default:
|
|
$orderby = 'created_at';
|
|
$orderdirection = 'desc';
|
|
}
|
|
|
|
$downloads = Downloads::when($this->fileSearch != '', fn ($query) => $query->where('url', 'like', '%'.$this->fileSearch.'%'))
|
|
->where('size', '>', 0)
|
|
->where(fn ($q) => $q->where('type', '=', 'UHD')->orWhere('type', '=', 'UHDi'))
|
|
->orderBy($orderby, $orderdirection)
|
|
->paginate(20);
|
|
|
|
return view('livewire.downloads-patreon', [
|
|
'downloads' => $downloads,
|
|
'query' => $this->fileSearch,
|
|
]);
|
|
}
|
|
}
|