Пример #1
0
 /**
  * Fetchs the players battlelog profile
  * @return mixed
  */
 public function fetchProfile()
 {
     // Generate URI for request
     $uri = sprintf($this->uris['generic']['profile'], $this->game, $this->player->SoldierName);
     // Send request
     $this->profile = $this->sendRequest($uri);
     // If the persona object is empty throw a BattlelogException
     if (empty($this->profile['context']['profilePersonas'])) {
         throw new BattlelogException(404, sprintf('No player by the name "%s" exists on battlelog.', $this->player->SoldierName));
     }
     // Set the gravtar of the player
     $this->personaGravatar = $this->profile['context']['profileCommon']['user']['gravatarMd5'];
     // Assign array of personas
     $personas = $this->profile['context']['profilePersonas'];
     // Loop over the personas and find a persona for the PC version only
     foreach ($personas as $persona) {
         // PC Namespace
         if ($persona['namespace'] == 'cem_ea_id') {
             $this->personaID = $persona['personaId'];
             $this->personaUserID = $persona['userId'];
             break;
         }
     }
     // If we don't have an existing stored persona we need to create one
     if (!$this->player->hasPersona()) {
         // Clear old cache for player
         Cache::forget(sprintf('api.player.%u', $this->player->PlayerID));
         Cache::forget(sprintf('player.%u', $this->player->PlayerID));
         // Assign a relationship for them and save to the database
         $this->player->battlelog()->save(new \BFACP\AdKats\Battlelog(['gravatar' => $this->personaGravatar, 'persona_banned' => false, 'persona_id' => $this->personaID, 'user_id' => $this->personaUserID]));
         // Reload the relationship
         $this->player->load('battlelog');
     }
     return $this;
 }
Пример #2
0
 /**
  * Creates or Updates the player reputation then reloads it
  * @return mixed
  */
 public function createOrUpdate()
 {
     $this->source()->target()->special()->calculate();
     if ($this->player->hasReputation()) {
         $reputation = $this->player->reputation;
         // Only update the reputation if the total reputation is different
         if ($reputation->total_rep != $this->totalReputation) {
             $reputation->source_rep = $this->sourceReputation;
             $reputation->target_rep = $this->targetReputation;
             $reputation->total_rep = $this->totalReputation;
             $reputation->total_rep_co = $this->finalReputation;
             $reputation->save();
             // Reload the relationship
             $this->player->load('reputation');
         }
     } else {
         $this->player->reputation()->save(new \BFACP\Battlefield\Reputation(['game_id' => $this->player->GameID, 'source_rep' => $this->sourceReputation, 'target_rep' => $this->targetReputation, 'total_rep' => $this->totalReputation, 'total_rep_co' => $this->finalReputation]));
         // Reload the relationship
         $this->player->load('reputation');
     }
     return $this;
 }