Esempio n. 1
0
 public function userPost_callback()
 {
     if (isset(\Auth::user()->id)) {
         //All the vars
         $user_id = \Auth::user()->id;
         $beer_id = Input::get('beer_id');
         $fb_place_id = Input::get('fb_place_id');
         $image_unique_id = 0;
         if (Input::file('image')) {
             BeerImg::uploadBeerImg_callback(Input::get(), Input::file('image'));
         }
         if (!empty($ratingComment)) {
             //Preparing data to be added
             $beer_meta = \App\BeerRating::Add(Input::get());
             $overall = \App\BeerRating::overallCalc(Input::get());
             //Calculate overall scores
             $beer_meta->overall = round($overall, 1);
             $beer_meta->save();
             //Increment votes tally
             DB::table('beers')->where('id', Input::get('beer_id'))->increment('votes');
             DB::table('beers')->where('id', Input::get('beer_id'))->update(array('scores' => $overall));
         }
         if (!empty($fb_place_id)) {
             $checkin = new Checkin();
             $checkin->user_id = $user_id;
             $checkin->place_id = $fb_place_id;
             $checkin->beer_id = $beer_id;
             $checkin->source = 1;
             //we are using facebook, 1 for now
             $checkin->save();
             $place = ['place_id' => Input::get('fb_place_id'), 'name' => Input::get('location'), 'category' => Input::get('fb_category'), 'street' => Input::get('fb_address'), 'city' => Input::get('fb_city'), 'state' => Input::get('fb_state'), 'zip' => Input::get('fb_zip'), 'latitude' => Input::get('fb_lat'), 'longitude' => Input::get('fb_lng')];
             $place_meta = Places::updateOrCreate(['place_id' => Input::get('fb_place_id')])->update($place);
             //Log information
             \UserBeerHelper::userLog($user_id, $beer_id, 300, $fb_place_id, $image_unique_id);
         }
         return redirect("profile/" . \Auth::user()->username);
     } else {
         return "err - user not login";
     }
 }