コード例 #1
0
ファイル: SearchController.php プロジェクト: sudroid/comicake
 public function index()
 {
     //Set keyword to proper format using Str::lower - it's the same as strtolower
     $keyword = Str::lower(Input::get('keyword'));
     //Use Query builder to look for the keyword in various category
     $data['comics'] = Comicbooks::where('book_name', 'LIKE', '%' . $keyword . '%')->select('book_name')->distinct()->get();
     $data['characters'] = Characters::where('character_name', 'LIKE', '%' . $keyword . '%')->select('character_name')->distinct()->get();
     $data['authors'] = Authors::where('author_name', 'LIKE', '%' . $keyword . '%')->select('author_name')->distinct()->get();
     $data['artists'] = Artists::where('artist_name', 'LIKE', '%' . $keyword . '%')->select('artist_name')->distinct()->get();
     $data['publishers'] = Publishers::where('publisher_name', 'LIKE', '%' . $keyword . '%')->select('publisher_name')->distinct()->get();
     $this->layout->content = View::make('search', $data);
 }
コード例 #2
0
 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.');
     }
 }
コード例 #3
0
 /**
  * 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.');
     }
 }
コード例 #4
0
ファイル: UsersController.php プロジェクト: sudroid/comicake
 public function getAdmin()
 {
     //Get info
     $data['users'] = User::paginate(5);
     $data['recent_books'] = Comicbooks::select('book_name', 'updated_at')->orderBy('updated_at', 'desc')->paginate(3);
     $data['user_count'] = User::where('id', '>', 0)->count();
     $data['publisher_count'] = Publishers::where('id', '>', 0)->count();
     $data['books_count'] = Comicbooks::where('id', '>', 0)->count();
     $data['issue_count'] = Comicissues::where('issue_id', '>', 0)->where('book_id', '>', 0)->count();
     $data['artist_count'] = Artists::count();
     $data['author_count'] = Authors::count();
     $data['books_created'] = Comicbooks::select(DB::raw('count(*) as count'), 'created_at')->groupby(DB::raw('date_format(created_at, "%b %Y")'))->orderby('created_at', 'asc')->get();
     $data['issues_created'] = Comicissues::select(DB::raw('count(*) as count'), 'created_at')->groupby(DB::raw('date_format(created_at, "%b %Y")'))->orderby('created_at', 'asc')->get();
     //Check if there are any comicbook series
     if (count($data['books_created']) > 0) {
         //Get the count of books per the month/year then return the json encoded string
         foreach ($data['books_created'] as $created) {
             $created_books[] = $created->count;
             $created_books_date[] = date_format($created->created_at, "M Y");
         }
         $data['created_books'] = json_encode($created_books);
     }
     //Check if there are any comicbook issue
     if (count($data['issues_created']) > 0) {
         //Get the count of issues per the month/year then return the json encoded string
         foreach ($data['issues_created'] as $created) {
             $created_issues[] = $created->count;
             $created_issues_date[] = date_format($created->created_at, "M Y");
         }
         $data['created_issues'] = json_encode($created_issues);
     }
     //Merge dates from comicbook series and issues created then return the json encoded string
     $data['created_dates'] = json_encode(array_unique(array_merge($created_issues_date, $created_books_date)));
     $this->layout->content = View::make('admin.index', $data);
 }
コード例 #5
0
ファイル: IssueController.php プロジェクト: sudroid/comicake
 /**
  * Update an issue in the database
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     //Trim inputs
     Input::merge(array_map('trim', Input::all()));
     //Set rules
     $rules = array('author_name' => 'required|min:5', 'artist_name' => 'required|min:5', 'published_date' => 'required|date_format:yy-m-d', 'issue_summary' => 'max:2000');
     //Create session
     $this->createSession();
     //Set validator
     $validator = Validator::make(Input::all(), $rules);
     //Set variables
     $data['issue_id'] = $id;
     $comic_title = Comicbooks::find(Input::get('id'));
     $comic_issues = Comicissues::issues($comic_title->book_name, $id)->select('book_id', 'issue_id')->first();
     //If comicbook issue exists
     if (!is_null($comic_issues)) {
         //Validation check
         if ($validator->passes()) {
             //Instance of Comicissue model
             $comic_issues = new Comicissues();
             //Set variables
             $author = Str::lower(Input::get('author_name'));
             $artist = Str::lower(Input::get('artist_name'));
             $authorExists = Authors::where('author_name', $author)->select('id')->first();
             $artistExists = Artists::where('artist_name', $artist)->select('id')->first();
             //Check if author already exist in the database
             if (isset($authorExists)) {
                 //if they do get the id
                 $author_id = $authorExists->id;
             } else {
                 //else create it in the Authors table using the instance of author model
                 $author_id = Authors::insertGetId(array('author_name' => $author));
             }
             //Check if artist already exist in the database
             if (isset($artistExists)) {
                 //if they do get the id
                 $artist_id = $artistExists->id;
             } else {
                 //else create it in the Artists table using the instance of artist model
                 $artist_id = Artists::insertGetId(array('artist_name' => $artist));
             }
             //Set an array of update variables
             $update_array = array('author_id_FK' => $author_id, 'artist_id_FK' => $artist_id, 'summary' => Input::get('issue_summary'), 'published_date' => Input::get('published_date'), 'updated_at' => date('Y-m-d H:i:s', time()));
             //Add cover image to local file and set location string into database
             if (Input::hasFile('cover_image')) {
                 $fileName = $comic_title->book_name . $id . '_Cov_' . Str::random(10) . '.' . Input::file('cover_image')->getClientOriginalExtension();
                 $cover_image = Input::file('cover_image')->move('public/img/comic_covers/', $fileName);
                 $update_array['cover_image'] = 'img/comic_covers/' . $fileName;
             }
             //Add issue information to comicdb_books
             Comicissues::where('book_id', Input::get('id'))->where('issue_id', $id)->update($update_array);
             //Destroy session data
             $this->destorySession();
             return Redirect::to('browse/series/' . $comic_title->book_name)->with('postMsg', 'Thanks for submiting!');
         } else {
             return Redirect::to(URL::previous())->with('postMsg', 'Whoops! Looks like you got some errors.')->withErrors($validator)->withInput();
         }
     }
     $this->destorySession();
     return Redirect::to(URL::previous())->with('postMsg', 'Looks like that issue already exists!');
 }
コード例 #6
0
ファイル: BrowseController.php プロジェクト: sudroid/comicake
 public function getYears($year)
 {
     $data['year_name'] = $year;
     //Get comics published in a specific year
     $data['year_cover'] = Comicbooks::years($year)->select('cover_image')->orderBy('published_date', 'asc')->distinct()->get();
     $data['year_works'] = Comicbooks::years($year)->select('book_name')->orderBy('published_date', 'asc')->distinct()->get();
     $data['has_year'] = count($data['year_works']) ? true : false;
     //If there are no series published in the year (because of URL tempering), return with error message
     if (!$data['has_year']) {
         return Redirect::to('browse/year')->with('postMsg', $this->msg);
     }
     $this->layout->content = View::make('year', $data);
 }