diff --git a/Blacklight/AniDB.php b/Blacklight/AniDB.php index b40ec8836..ab79ab486 100755 --- a/Blacklight/AniDB.php +++ b/Blacklight/AniDB.php @@ -2,6 +2,7 @@ namespace Blacklight; +use App\Models\AnidbTitle; use Blacklight\db\DB; use App\Models\Category; @@ -142,67 +143,27 @@ class AniDB /** * Retrieves a range of Anime titles for site display. * - * @param int $start - * @param int $num - * @param string $animetitle - * @return array|bool - */ - public function getAnimeRange($start, $num, $animetitle = '') - { - if ($start === false) { - $limit = ''; - } else { - $limit = ' LIMIT '.$num.' OFFSET '.$start; - } - - $rsql = ''; - if ($animetitle !== '') { - $rsql = sprintf('AND at.title %s', $this->pdo->likeString($animetitle, true, true)); - } - - return $this->pdo->query( - sprintf( - " - SELECT at.anidbid, GROUP_CONCAT(at.title SEPARATOR ', ') AS title, - ai.description - FROM anidb_titles AS at - LEFT JOIN anidb_info AS ai USING (anidbid) - WHERE 1=1 %s - AND at.lang = 'en' - GROUP BY at.anidbid - ORDER BY at.anidbid ASC %s", - $rsql, - $limit - ) - ); - } - - /** - * Retrives the count of Anime titles for pager functions optionally filtered by title. * + * @param $page * @param string $animetitle - * @return int + * + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ - public function getAnimeCount($animetitle = ''): int + public function getAnimeRange($page, $animetitle = '') { - $rsql = ''; + $query = AnidbTitle::query() + ->select(['at.anidbid', DB::raw("GROUP_CONCAT(at.title SEPARATOR ', ') AS title"), 'ai.description']) + ->from('anidb_titles as at') + ->leftJoin('anidb_info as ai', 'ai.anidbid', '=', 'at.anidbid') + ->where('at.lang', '=', 'en'); if ($animetitle !== '') { - $rsql .= sprintf('AND at.title %s', $this->pdo->likeString($animetitle, true, true)); + $query->where('at.title', 'LIKE', '%'.$animetitle.'%'); } - $res = $this->pdo->queryOneRow( - sprintf( - ' - SELECT COUNT(DISTINCT at.anidbid) AS num - FROM anidb_titles AS at - LEFT JOIN anidb_info AS ai USING (anidbid) - WHERE 1=1 - %s', - $rsql - ) - ); + $query->groupBy('at.anidbid') + ->orderByDesc('at.anidbid'); - return $res['num']; + return $query->paginate(config('nntmux.items_per_page')); } /** diff --git a/Changelog b/Changelog index ec1f28f2c..51f556a41 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-04-17 DariusIII + * Chg: Add BookController and edit Blacklist/Anidb class * Chg: Add admin CategoryController * Chg: Add admin anidb and blacklist controllers 2018-04-16 DariusIII diff --git a/app/Http/Controllers/Admin/BookController.php b/app/Http/Controllers/Admin/BookController.php new file mode 100644 index 000000000..892d717c0 --- /dev/null +++ b/app/Http/Controllers/Admin/BookController.php @@ -0,0 +1,97 @@ +setAdminPrefs(); + + $title = 'Book List'; + + $bookList = BookInfo::query()->orderByDesc('created_at')->paginate(config('nntmux.items_per_page')); + + $this->smarty->assign('booklist', $bookList); + + $content = $this->smarty->fetch('book-list.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Exception + */ + public function edit(Request $request) + { + $this->setAdminPrefs(); + $book = new Books(); + + // set the current action + $action = $request->input('action') ?? 'view'; + + if ($request->has('id')) { + $id = $request->input('id'); + $b = $book->getBookInfo($id); + + if (! $b) { + $this->show404(); + } + + switch ($action) { + case 'submit': + $coverLoc = resource_path().'/covers/book/'.$id.'.jpg'; + + if ($_FILES['cover']['size'] > 0) { + $tmpName = $_FILES['cover']['tmp_name']; + $file_info = getimagesize($tmpName); + if (! empty($file_info)) { + move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc); + } + } + + $request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]); + $request->merge(['publishdate' => (empty($request->input('publishdate')) || ! strtotime($request->input('publishdate'))) ? $con['publishdate'] : Carbon::parse($request->input('publishdate'))->timestamp]); + $book->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('author'), $request->input('publisher'), $request->input('publishdate'), $request->input('cover')); + + return redirect('book-list'); + break; + case 'view': + default: + $title = 'Book Edit'; + $this->smarty->assign('book', $b); + break; + } + } + + $content = $this->smarty->fetch('book-edit.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } +} diff --git a/public/admin/book-list.php b/public/admin/book-list.php deleted file mode 100644 index 67c1315b9..000000000 --- a/public/admin/book-list.php +++ /dev/null @@ -1,35 +0,0 @@ -setAdminPrefs(); -$book = new Books(); - -$page->title = 'Book List'; - -$bookCount = Utility::getCount('bookinfo'); - -$offset = request()->input('offset') ?? 0; - -$page->smarty->assign([ - 'pagertotalitems' => $bookCount, - 'pagerquerysuffix' => '#results', - 'pageroffset' => $offset, - 'pageritemsperpage' => config('nntmux.items_per_page'), - 'pagerquerybase' => WWW_TOP.'/book-list.php?offset=', -]); - -$pager = $page->smarty->fetch('pager.tpl'); -$page->smarty->assign('pager', $pager); - -$bookList = Utility::getRange('bookinfo', $offset, config('nntmux.items_per_page')); - -$page->smarty->assign('booklist', $bookList); - -$page->content = $page->smarty->fetch('book-list.tpl'); -$page->adminrender(); diff --git a/routes/web.php b/routes/web.php index 6b2831d0f..249125b32 100644 --- a/routes/web.php +++ b/routes/web.php @@ -207,6 +207,10 @@ Route::prefix('admin')->group(function () { Route::post('binaryblacklist-list', 'Admin\BlacklistController@index'); Route::get('binaryblacklist-edit', 'Admin\BlacklistController@edit'); Route::post('binaryblacklist-edit', 'Admin\BlacklistController@edit'); + Route::get('book-list', 'Admin\BookController@index'); + Route::post('book-list', 'Admin\BookController@index'); + Route::get('book-edit', 'Admin\BookController@edit'); + Route::post('book-edit', 'Admin\BookController@edit'); Route::get('category-list', 'Admin\CategoryController@index'); Route::post('category-list', 'Admin\CategoryController@index'); Route::get('category-edit', 'Admin\CategoryController@edit');