Example #1
0
 /**
  * @param \Onyx\Account $account
  * @param \Onyx\Halo5\Objects\Data $old
  * @param \Onyx\Halo5\Objects\Data $new
  * @return string
  */
 public static function buildH5UpdateMessage($account, $old, $new)
 {
     $old_kd = $old->kd();
     $old_kad = $old->kad();
     $old_games = $old->totalGames;
     $new_kd = $new->kd();
     $new_kad = $new->kad();
     $new_games = $new->totalGames;
     $msg = '<strong>' . $account->gamertag . '</strong> stats have been updated!<br /><br />';
     $msg .= 'KD went from ' . $old_kd . ' to ' . $new_kd . ' <br />';
     $msg .= 'KAD went from ' . $old_kad . ' to ' . $new_kad . ' <br />';
     $msg .= 'Total Games played went from ' . $old_games . ' to ' . $new_games . '<br />';
     return $msg;
 }
Example #2
0
 public static function boot()
 {
     parent::boot();
     Account::created(function ($account) {
         // destiny stuff
         $data = new Data();
         $data->account_id = $account->id;
         $data->membershipId = $account->destiny_membershipId;
         $data->save();
         // halo 5 stuff
         $h5_data = new H5Data();
         $h5_data->account_id = $account->id;
         $h5_data->save();
     });
 }
Example #3
0
 /**
  * @param $gamertag
  * @return Account|void|static
  * @throws H5PlayerNotFoundException
  * @throws Helpers\Network\ThreeFourThreeOfflineException
  */
 public function getAccountByGamertag($gamertag)
 {
     $url = sprintf(Constants::$servicerecord_arena, Text::encodeGamertagForApi($gamertag));
     $account = $this->checkCacheForGamertag($gamertag);
     if ($account instanceof Account) {
         // lets check if they have H5 data
         if (!$account->h5 instanceof Data) {
             $h5_data = new Data();
             $h5_data->account_id = $account->id;
             $h5_data->save();
         }
         return $account;
     }
     $json = $this->getJson($url);
     if (isset($json['Results'][0]['ResultCode']) && $json['Results'][0]['ResultCode'] == 0) {
         try {
             return Account::firstOrCreate(['gamertag' => $json['Results'][0]['Id']]);
         } catch (QueryException $e) {
             throw new H5PlayerNotFoundException();
         }
     } else {
         throw new H5PlayerNotFoundException();
     }
 }
Example #4
0
 public function postUpdate()
 {
     $all = $this->request->all();
     if (isset($all['google_id'])) {
         try {
             $user = User::where('google_id', $all['google_id'])->firstOrFail();
             if ($user->account_id != 0 && $user->account->h5 instanceof Data) {
                 $old_h5 = clone $user->account->h5;
                 $this->dispatch(new UpdateHalo5Account($user->account));
                 $new_h5 = Data::where('account_id', $user->account_id)->first();
                 $msg = MessageGenerator::buildH5UpdateMessage($user->account, $old_h5, $new_h5);
                 return Response::json(['error' => false, 'msg' => $msg], 200);
             } else {
                 return Response::json(['error' => false, 'msg' => 'bitch pls. You need to confirm your gamertag on PandaLove so I know who you are.'], 200);
             }
         } catch (ModelNotFoundException $e) {
             return $this->_error('User account could not be found.');
         }
     }
 }