0
0
mirror of https://github.com/anthonyaxenov/iptv.git synced 2024-11-22 05:24:45 +00:00

Сортировка и размер страницы через конфиг

This commit is contained in:
Anthony Axenov 2022-09-04 09:24:09 +08:00
parent b65ab2cca0
commit a868b677f0
Signed by: anthony
GPG Key ID: EA9EC32FF7CCD4EC
4 changed files with 20 additions and 6 deletions

View File

@ -5,3 +5,5 @@ TWIG_DEBUG=0
FLIGHT_CASE_SENSITIVE=0 FLIGHT_CASE_SENSITIVE=0
FLIGHT_HANDLE_ERRORS=1 FLIGHT_HANDLE_ERRORS=1
FLIGHT_LOG_ERRORS=1 FLIGHT_LOG_ERRORS=1
PAGE_SIZE=10
SORT_BY=

View File

@ -18,6 +18,15 @@ class HomeController extends Controller
$this->ini = new PlaylistProcessor(); $this->ini = new PlaylistProcessor();
} }
/**
* @return int
*/
protected function getPageSize(): int
{
$size = config('app.page_size');
return empty($size) || $size < 5 || $size > 100 ? 10 : $size;
}
/** /**
* @throws Exception * @throws Exception
*/ */
@ -28,11 +37,12 @@ class HomeController extends Controller
Flight::redirect(base_url($id)); Flight::redirect(base_url($id));
die; die;
} }
$per_page = 10; $per_page = $this->getPageSize();
$list = $this->ini->playlists $list = $this->ini->playlists->where('redirect_id', null);
->where('redirect_id', null) if (config('app.sort_by')) {
// ->sortBy('id') $list = $list->sortBy(config('app.sort_by'));
->forPage($page, $per_page); }
$list = $list->forPage($page, $per_page);
view('list', [ view('list', [
'updated_at' => $this->ini->updatedAt(), 'updated_at' => $this->ini->updatedAt(),
'count' => $this->ini->playlists->count(), 'count' => $this->ini->playlists->count(),

View File

@ -49,7 +49,7 @@ final class PlaylistProcessor
return $code < 400; return $code < 400;
} }
protected function fetch(string $id) protected function fetch(string $id): array
{ {
$curl = curl_init(); $curl = curl_init();
curl_setopt_array($curl, [ curl_setopt_array($curl, [

View File

@ -26,5 +26,7 @@ return [
// 'CP866', // 'CP866',
// 'ISO-8859-5', // 'ISO-8859-5',
], ],
'page_size' => (int)(env('PAGE_SIZE', 10)),
'sort_by' => env('SORT_BY'),
], ],
]; ];