public function postReading() { //Get the title from the url $title = urldecode(Request::segment(2)); //Get variables $comic = Comicbooks::series($title)->select('comicdb_books.id')->first(); $userExist = Userinfo::userbook(Auth::id(), $comic->id)->first(); //If the comic exists if (!is_null($comic->id)) { //If the user doesn't exist in the userinfo table (meaning they haven't marked anything as read/to read yet) if (is_null($userExist)) { //Add a new row of data for the user Userinfo::insert(array('book_id_FK' => $comic->id, 'user_id_FK' => Auth::id(), 'reading_status' => Input::get('reading_status'))); return Redirect::back(); } else { //Update the row of data for the user Userinfo::where('user_id_FK', '=', Auth::id())->where('book_id_FK', '=', $comic->id)->update(array('reading_status' => Input::get('reading_status'))); return Redirect::back(); } } else { return Redirect::back()->with('postMsg', 'An error occurred. Please try again.'); } }
/** * Remove a comicbook series from the database * DELETE /content/{title} * * @param string $title * @return Response */ public function destroy($title) { //Instance of Comicbooks model $comic = new Comicbooks(); $book_id = $comic->series($title)->select('comicdb_books.id')->distinct()->get(); $delete_comic = $comic->findOrFail($book_id[0]->id); //If the comicbook series exists if ($delete_comic) { //Delete any instance of it in the Userinfo table (tracks unread/to read list) Userinfo::where('book_id_FK', '=', $book_id[0]->id)->delete(); //Delete any instance of it in the comicbook issues table Comicissues::where('book_id', '=', $book_id[0]->id)->delete(); //Delete the comicbook series in the comicbook books table $delete_comic->delete($book_id[0]->id); return Redirect::to('browse')->with('postMsg', 'The book has been deleted.'); } else { return Redirect::to(URL::previous())->with('postMsg', 'Whoops! Looks like you got some errors.'); } }
public function getSeries($book) { //Page Title $data['book_title'] = $book; //Get the first result of book series query $data['book'] = Comicbooks::series($book)->select('comicdb_books.id')->distinct()->first(); //If it's not null... if ($data['book']) { //Get book information $data['book_info'] = Comicbooks::series($book)->select('publisher_name', 'book_description')->distinct()->get(); $data['book_genre'] = Comicbooks::series($book)->select('genre_name')->distinct()->get(); $data['book_issues'] = Comicbooks::series($book)->select('issue_id', 'cover_image', 'book_id')->distinct()->get(); $data['book_characters'] = Comicbooks::bookcharacters($book)->select('character_name')->distinct()->get(); $comic = Comicbooks::series($book)->select('comicdb_books.id')->first(); $read = Userinfo::where('book_id_FK', $comic->id)->where('user_id_FK', Auth::id())->select('read_status', 'reading_status')->first(); //If read variable isn't empty if ($read != '') { switch ($read->read_status) { case 0: $data['read_msg'] = 'MARK AS READ'; $data['read_status'] = 1; break; case 1: $data['read_msg'] = 'MARK AS UNREAD'; $data['read_status'] = 0; break; } switch ($read->reading_status) { case 0: $data['reading_msg'] = 'ADD TO READLIST'; $data['reading_status'] = 1; break; case 1: $data['reading_msg'] = 'REMOVE FROM READLIST'; $data['reading_status'] = 0; break; } } else { $data['read_msg'] = 'MARK AS READ'; $data['read_status'] = 1; $data['reading_msg'] = 'ADD TO READLIST'; $data['reading_status'] = 1; } $this->layout->content = View::make('series', $data); } else { //Redirect to the error page if the book series it doesn't exist return Redirect::to('error'); } }