Good morning everyone, I am very new to this so please be patient
I have a class that has a link in the class that follows as this.
Now if i take the link and add a username like this
it loads all the stats about the username, I have a profile page that i would love to pull some of those values
now on i have the username available so that it will get the proper user my issue is how do i go about incorporating
it in to my profile page how do i display the values.
i have the class here
<?php
class sProfile {
public $profileData = array();
public $soldierName;
public $jsonError;
public $cache = false;
public $CacheDir = "cache/";
public $hasError = false;
private $apiLinks = array();
private $apiPath = "http://www.website.com/api/v1/users/";
public function __construct($soldierName) {
$this->soldierName = urlencode(trim($soldierName));
if(empty($this->soldierName)) {
$this->hasError = true; //oops, the set name was blank
$this->jsonError = "A blank Soldier Name was entered.";
return false;
}
$this->apiLink = $this->apiPath.$this->soldierName;
return true;
}
public function BuildProfile () {
$dataStream = @file_get_contents($this->apiLink);
if(!$dataStream) {
$this->hasError = true; //HTTP Not available? Unlikey
$this->jsonError = "Unable to reach the stats API. Try again later.";
}
$dataArray = json_decode($dataStream, true);
if(is_array($dataArray)) {
if(trim($dataArray['errors']) != '') {
$this->jsonError = $dataArray['errors']; //API returned a predefined error
$this->hasError = true;
}
$this->profileData = $dataArray['soldier'];
} else {
$this->hasError = true; //Was not a JSON response (Player not found)
$this->jsonError = "Player not found.";
}
if($this->hasError) {
return false;
}
$this->FlattenprofileData();
$this->FlattenProfile();
$this->CaculateStats();
return true;
}
public function CaculateStats () {
$this->CaculateHeadShots();
extract($this->FlatProfile);
$this->LevelXPNeeded = $this->FlatProfile['LvlXPEnd'] - $this->FlatProfile['LvlXPStart'];
$this->LevelXPCurrent = $this->FlatProfile['LvlXP'] - $this->FlatProfile['LvlXPStart'];
$tnl = number_format($this->LevelXPNeeded - $this->LevelXPCurrent);
$nextRank = $NextRankInGameDisplay;
$kdr = @round($EnemyNeutralized / $TimesNeutralized,2);
$accuracy = @round(($TotalHits / $TotalShots) * 100, 2);
$kills = number_format($EnemyNeutralized);
$khr = @round(($this->FlatProfile['HeadShots'] / $EnemyNeutralized) * 100, 2);
$this->FlatProfile['HeadShotPercentage'] = $khr;
$this->FlatProfile['Accuracy'] = $accuracy;
$this->FlatProfile['Kills'] = $kills;
$this->FlatProfile['NextRankEXP'] = $tnl;
$this->FlatProfile['KDR'] = $kdr;
$this->FlatProfile['PlayTime'] = @round((($this->FlatProfile['TimePlaying'] / 60) / 60),2)."Hrs";
}
public function FlattenprofileData () {
foreach($this->profileData as $k1 => $v1) {
$this->profileData[$k1] = $this->FlattenArray($v1);
}
}
public function WriteCache () {
return file_put_contents($this->CacheDir . md5(strtoupper($this->soldierName)), json_encode($this->profileData));
}
public function ReadCache () {
if(file_exists($this->CacheDir . md5(strtoupper($this->soldierName)))) {
$lastSaved = filemtime($this->CacheDir . md5(strtoupper($this->soldierName)));
if(time() - 300 < $lastSaved) {
$this->profileData = json_decode(file_get_contents($this->CacheDir . md5(strtoupper($this->soldierName))),true);
return true;
}
}
return false;
}
public function CaculateHeadShots () {
$this->FlatProfile['HeadShots'] = 0;
foreach($this->profileData['weapons'] as $weapon => $data) {
$this->FlatProfile['HeadShots'] += $data['HitChart']['Head'];
}
}
public function FlattenProfile () {
$this->FlatProfile = array();
$this->FlatProfile = array_merge($this->profileData['profile'], $this->profileData['career'], $this->profileData['objectives']);
}
public function FlattenArray ($array) {
foreach($array as $k => $v) {
if(is_array($v)) {
if(array_key_exists('Value', $v)) {
$array[$k] = $v['Value'];
} else {
foreach($v as $kk => $vv) {
if(is_array($vv)) {
$array[$k] = $this->FlattenArray($array[$k]);
}
}
}
}
}
return $array;
}
}
?>