diff --git a/Changelog b/Changelog index b0bf70dd1..5cf52a195 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-04-19 DariusIII + * Chg: Add PredbController * Chg: Add NzbController * Chg: Add MusicController * Chg: Add MovieController diff --git a/app/Http/Controllers/Admin/PredbController.php b/app/Http/Controllers/Admin/PredbController.php new file mode 100644 index 000000000..c2f67c308 --- /dev/null +++ b/app/Http/Controllers/Admin/PredbController.php @@ -0,0 +1,50 @@ +setAdminPrefs(); + + if ($request->has('presearch')) { + $lastSearch = $request->input('presearch'); + $parr = Predb::getAll($request->input('presearch')); + } else { + $lastSearch = ''; + $parr = Predb::getAll(); + } + + $this->smarty->assign('lastSearch', $lastSearch); + + $this->smarty->assign('results', $parr); + + $title = 'Browse PreDb'; + $meta_title = 'View PreDb info'; + $meta_keywords = 'view,predb,info,description,details'; + $meta_description = 'View PreDb info'; + + $content = $this->smarty->fetch('predb.tpl'); + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + 'meta_title' => $meta_title, + 'meta_keywords' => $meta_keywords, + 'meta_description' => $meta_description, + ] + ); + + $this->adminrender(); + } +} diff --git a/app/Models/Predb.php b/app/Models/Predb.php index 12c04602b..9e91de491 100644 --- a/app/Models/Predb.php +++ b/app/Models/Predb.php @@ -146,42 +146,18 @@ class Predb extends Model * Get all PRE's in the DB. * * - * @param $offset - * @param $offset2 * @param string|array $search * @return array */ - public static function getAll($offset, $offset2, $search = ''): array + public static function getAll($search = ''): array { if ($search !== '') { $search = explode(' ', trim($search)); } $expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_medium')); - if ($search === '') { - $check = Cache::get('predbcount'); - if ($check !== null) { - $count = $check; - } else { - $count = self::count(); - Cache::put('predbcount', $count, $expiresAt); - } - } else { - $sql = self::query()->where(function ($query) use ($search) { - for ($i = 0, $iMax = \count($search); $i < $iMax; $i++) { - $query->where('title', 'like', '%'.$search[$i].'%'); - } - }); - $check = Cache::get(md5(implode(',', $search))); - if ($check !== null) { - $count = $check; - } else { - $count = $sql->count('id'); - Cache::put(md5(implode(',', $search)), $count, $expiresAt); - } - } - $sql = self::query()->leftJoin('releases', 'predb.id', '=', 'releases.predb_id')->orderBy('predb.predate', 'desc')->limit($offset2)->offset($offset); + $sql = self::query()->leftJoin('releases', 'releases.predb_id', '=', 'predb.id')->orderByDesc('predb.predate'); if ($search !== '') { $sql->where(function ($query) use ($search) { for ($i = 0, $iMax = \count($search); $i < $iMax; $i++) { @@ -190,15 +166,15 @@ class Predb extends Model }); } $search = $search !== '' ? implode(',', $search) : ''; - $check = Cache::get(md5($offset.$offset2.$search)); + $check = Cache::get(md5($search)); if ($check !== null) { $parr = $check; } else { - $parr = $sql->get(); - Cache::put(md5($offset.$offset2.$search), $parr, $expiresAt); + $parr = $sql->paginate(config('nntmux.items_per_page')); + Cache::put(md5($search), $parr, $expiresAt); } - return ['arr' => $parr, 'count' => $count ?? 0]; + return $parr; } /** diff --git a/routes/web.php b/routes/web.php index 8e9569d40..c89be436a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -315,5 +315,7 @@ Route::middleware('admin')->prefix('admin')->group(function () { Route::post('nzb-import', 'NzbController@import'); Route::get('nzb-export', 'NzbController@export'); Route::post('nzb-export', 'NzbController@export'); + Route::get('predb', 'PredbController@index'); + Route::post('predb', 'PredbController@index'); }); });