diff --git a/Changelog b/Changelog index 2a97ee374..64bdf8fc1 100755 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2018-04-04 DariusIII + * Chg: Add CartController 2018-04-03 DariusIII * Chg: Update BrowseController * Fix: Fix return value of Category model getCategorySearch function diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php new file mode 100644 index 000000000..c66b122db --- /dev/null +++ b/app/Http/Controllers/CartController.php @@ -0,0 +1,81 @@ +setPrefs(); + $meta_title = 'My Download Basket'; + $meta_keywords = 'search,add,to,cart,download,basket,nzb,description,details'; + $meta_description = 'Manage Your Download Basket'; + + $results = UsersRelease::getCart(Auth::id()); + $this->smarty->assign('results', $results); + + $content = $this->smarty->fetch('cart.tpl'); + $this->smarty->assign( + [ + 'content' => $content, + 'meta_title' => $meta_title, + 'meta_keywords' => $meta_keywords, + 'meta_description' => $meta_description, + ] + ); + $this->pagerender(); + } + + + /** + * @param \Illuminate\Http\Request $request + * @throws \Exception + */ + public function store(Request $request) + { + $this->setPrefs(); + $guids = explode(',', $request->input('id')); + $data = Release::getByGuid($guids); + + if (! $data) { + $this->show404(); + } + + foreach ($data as $d) { + UsersRelease::addCart(Auth::id(), $d['id']); + } + + redirect('/cart/index'); + } + + /** + * @param $id + * @throws \Exception + */ + public function destroy($id) + { + $this->setPrefs(); + $ids = null; + if (!empty($id)) { + $ids = (array) $id; + } elseif (\is_array($id)) { + $ids = $id; + } + + if ($ids !== null && UsersRelease::delCartByGuid($ids, Auth::id())) { + redirect('/cart/index'); + } + + if (! $id) { + redirect('/cart/index'); + } + } +} diff --git a/routes/web.php b/routes/web.php index 1ba6bf810..74276ef34 100644 --- a/routes/web.php +++ b/routes/web.php @@ -50,6 +50,14 @@ Route::get('anime/{id?}', 'AnimeController@index'); Route::get('books/{id?}', 'BooksController@index'); +Route::prefix('cart')->group(function () { + Route::get('index', 'CartController@index'); + Route::get('add/{id}', 'CartController@store'); + Route::post('add/{id}', 'CartController@store'); + Route::get('delete/{id}', 'CartController@destroy'); + Route::post('delete/{id}', 'CartController@destroy'); +}); + Route::get('/console', function () { redirect('/console'); })->middleware('auth');