Esempio n. 1
0
 public function getWishListAdd($id = null)
 {
     if (isset($id)) {
         \Project4\Comic::addComicToUserWishList($id);
         // return to the search view
         // TODO try to pass the search results back in to give the illusion that the page didn't change?
         \Session::flash('message', 'Comic successfully added to your wish list.');
     } else {
         \Session::flash('message', 'Cannot add comic with null ID.');
     }
     return redirect('/search');
 }
Esempio n. 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $comic = \Project4\Comic::firstOrCreate(['comic_id' => 41530]);
     $comic->title = 'Ant-Man: So (Trade Paperback)';
     $comic->thumbnail_url = 'http://i.annihil.us/u/prod/marvel/i/mg/c/30/4fe8cb51f32e0.jpg';
     $comic->marvel_url = 'http://marvel.com/comics/collection/41530/ant-man_so_trade_paperback?utm_campaign=apiRef&utm_source=3955c81150716cd1f39158b80925e978';
     $comic->description = "It's the origin of the original Avenger, Ant-Man! Hank Pym has been known by a variety of names - including Ant-Man, Giant-Man, Goliath and Yellowjacket - he's been an innovative scientist, a famed super hero, an abusive spouse and more. What demons drive a man like Hank Pym? And how did he begin his heroic career?";
     $comic->on_sale_date = date('Y-m-d', strtotime('2020-12-31T00:00:00-0500'));
     $comic->isbn = '978-0-7851-6390-9';
     $comic->save();
     $comic = \Project4\Comic::firstOrCreate(['comic_id' => 58530]);
     $comic->title = 'Miracleman by Gaiman & Buckingham: The Silver Age (2016) #2';
     $comic->thumbnail_url = 'http://i.annihil.us/u/prod/marvel/i/mg/6/a0/56e6d107692cc.jpg';
     $comic->marvel_url = 'http://marvel.com/comics/issue/58530/miracleman_by_gaiman_buckingham_the_silver_age_2016_2?utm_campaign=apiRef&utm_source=3955c81150716cd1f39158b80925e978';
     $comic->description = "Miracleman has his old friend back, but Young Miracleman has never felt more alone. Where can a hero from a simpler time call home in this brave new world? The tensions building underneath Miracleman and Young Miracleman’s relationship explode in “When Titans Clash!” Remastered with stunning new artwork by Mark Buckingham! Including material originally presented in MIRACLEMAN (1985) #24, plus bonus content.";
     $comic->on_sale_date = date('Y-m-d', strtotime('2016-09-28T00:00:00-0400'));
     $comic->isbn = '';
     $comic->save();
     $comic = \Project4\Comic::firstOrCreate(['comic_id' => 56205]);
     $comic->title = 'The Unbeatable Squirrel Girl (2015) #10';
     $comic->thumbnail_url = 'http://i.annihil.us/u/prod/marvel/i/mg/9/20/5717e054ade2c.jpg';
     $comic->marvel_url = 'http://marvel.com/comics/issue/56205/the_unbeatable_squirrel_girl_2015_10?utm_campaign=apiRef&utm_source=3955c81150716cd1f39158b80925e978';
     $comic->description = "Mole Man has fallen in love with Squirrel Girl, and he’s holding the world hostage until she goes on a date with him! MOLE MEN, am I right?? Watch as Squirrel Girl gains the help of an unlikely ally! Thrill as two people kiss! BUT WHICH TWO?? You’ll have to buy the issue to find out, so all I’ll say right now is this: IN THIS ISSUE THERE IS A NON-ZERO CHANCE FOR EVERY MARVEL SHIP TO BECOME CANON!! “Ship” is short for “relationship,” in case you thought I was talking about, like, Galactus’ “Star Sphere” or Mr. Fantastic’s “Fantasticship” or whatever. Anyway, enjoy!!";
     $comic->on_sale_date = date('Y-m-d', strtotime('2016-07-27T00:00:00-0400'));
     $comic->isbn = '';
     $comic->save();
     $request = new \Illuminate\Http\Request();
     $offset = 0;
     $request->replace(array('limit' => 100, 'offset' => $offset));
     $helper = new \Project4\Libraries\MarvelAPIHelper();
     $apiresult = $helper->getComicsFromAPI($request);
     $total = $apiresult['total'];
     $comics = $apiresult['results'];
     foreach ($comics as $comic) {
         $newcomic = \Project4\Comic::firstOrCreate(['comic_id' => $comic['id']]);
         $newcomic->title = $comic['title'];
         $newcomic->thumbnail_url = $comic['thumbnail']['path'] . '.' . $comic['thumbnail']['extension'];
         foreach ($comic['urls'] as $url) {
             if ($url['type'] == 'detail') {
                 $newcomic->marvel_url = $url['url'];
             }
         }
         $newcomic->description = $comic['description'];
         foreach ($comic['dates'] as $date) {
             if ($date['type'] = 'onsaleDate') {
                 $newcomic->on_sale_date = date('Y-m-d', strtotime($date['date']));
             }
         }
         $newcomic->isbn = $comic['isbn'];
         $newcomic->save();
     }
 }
Esempio n. 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     # First, create an array of all the users we want to associate comics with
     # The *key* will be the user name, and the *value* will be an array of comic_ids.
     $users = ['Admin' => [41530, 58530, 56205], 'Jill' => [41530, 58530, 56205], 'Jamal' => [41530, 58530, 56205]];
     # Now loop through the above array, creating a new pivot for each user to comic
     foreach ($users as $name => $comic_ids) {
         # First get the user
         $user = \Project4\User::where('name', 'like', $name)->first();
         # Now loop through each comic for this user, adding the pivot
         foreach ($comic_ids as $comic_id) {
             $comic = \Project4\Comic::where('comic_id', 'LIKE', $comic_id)->first();
             # Connect this comic to this user
             # (create a many to many entry)
             $user->comics()->save($comic, array('collection_count' => 1, 'wishlist_count' => 1));
         }
     }
 }
Esempio n. 4
0
 public static function addComicToUserWishList($id)
 {
     // find current user
     $user = \Project4\User::where('id', '=', \Auth::id())->first();
     // first, see if there is already an entry in the ComicUser table for this combination
     $comics = $user->comics;
     $exists = false;
     foreach ($user->comics as $comic) {
         if ($comic->id == $id) {
             $exists = true;
         }
     }
     // IF there is, set the collection value to 1
     if ($exists) {
         $user->comics()->updateExistingPivot($id, ['wishlist_count' => 1]);
     } else {
         $comic = \Project4\Comic::where('id', 'LIKE', $id)->first();
         # Connect this comic to this user
         # (create a many to many entry)
         $user->comics()->save($comic, array('collection_count' => 0, 'wishlist_count' => 1));
     }
 }
Esempio n. 5
0
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
         $offset = 0;
         $now = \Carbon\Carbon::now();
         $request = new Illuminate\Http\Request();
         $request->replace(array('limit' => 100, 'offset' => $offset));
         do {
             $helper = new \Project4\Libraries\MarvelAPIHelper();
             $apiresult = $helper->getComicsFromAPI($request);
             $total = $apiresult['total'];
             $comics = $apiresult['results'];
             foreach ($comics as $comic) {
                 $dbcomic = \Project4\Comic::firstOrCreate(['comic_id' => $comic['id']]);
                 // only update if the comic has been updated in the API in the last 24 hours
                 if ($dbcomic->updated_at->lt($now)) {
                     $dbcomic->title = $comic['title'];
                     $dbcomic->thumbnail_url = $comic['thumbnail']['path'] . '.' . $comic['thumbnail']['extension'];
                     foreach ($comic['urls'] as $url) {
                         if ($url['type'] == 'detail') {
                             $dbcomic->marvel_url = $url['url'];
                         }
                     }
                     $dbcomic->description = $comic['description'];
                     foreach ($comic['dates'] as $date) {
                         if ($date['type'] = 'onsaleDate') {
                             $dbcomic->on_sale_date = date('Y-m-d', strtotime($date['date']));
                         }
                     }
                     $dbcomic->isbn = $comic['isbn'];
                     $dbcomic->save();
                 }
             }
         } while ($offset <= $total + 100);
     })->daily();
 }
Esempio n. 6
0
|
*/
Route::get('/', function () {
    return view('index');
});
Route::get('/collection', function () {
    $comics = null;
    if (Auth::check()) {
        $comics = \Project4\Comic::getComicsForCurrentUser();
    }
    return view('collection', ['comics' => $comics]);
});
Route::get('/wish-list', function () {
    $comics = null;
    if (Auth::check()) {
        $comics = \Project4\Comic::getComicsForCurrentUser();
    }
    return view('wishlist', ['comics' => $comics]);
});
Route::get('/search', function () {
    return view('search');
});
# Show login form
Route::get('/login', 'Auth\\AuthController@getLogin');
# Process login form
Route::post('/login', 'Auth\\AuthController@postLogin');
# Process logout
Route::get('/logout', 'Auth\\AuthController@logout');
# Show registration form
Route::get('/register', 'Auth\\AuthController@getRegister');
# Process registration form