Standings

dni_license = ‘f4ca77fee2-e97c2fafbf-f27daa910e-22a215c909’;
$this->api_key = ‘814535c2-0785-4084-adf8-13f32bbd6e1a’;
$this->team_id = ‘468531’; //466743 is Carrot River Outback Thunder
$this->feed_url = ‘http://datafeed.esportsdesk.com/datafeed/datafeed.cfc’;

}
/**
*
* Get the next game
*
* @param int $i Used to determine what game to show. Default is 0 showing next home game.
* If the game has started (live scoring) pass ‘1’ to it to show next home game instead of current game playing.
* The system doesn’t update the next home game until the game is done and gamesheet verified, so this bypasses.
* @return array
*/

function getNextGame($i=0) {
$season = $this->getSeasonId(true);
$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘method’ => urlencode(“getSchedule”),
‘seasonID’ => urlencode($season),
‘showGameType’ => urlencode(‘ALL’),
‘futurePastTodayAll’ => urlencode(‘FUTURE’)
);

/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);

$count = count($data[“DATA”]);

$return[“Game”][“Date”] = $data[“DATA”][$i][4];
$return[“Game”][“Time”] = $data[“DATA”][$i][23];
$return[“Game”][“Location”] = $data[“DATA”][$i][13];
$return[“Game”][“Home”] = $data[“DATA”][$i][6];
$return[“Game”][“Visitor”] = $data[“DATA”][$i][9];
$return[“Game”][“City”] = $data[“DATA”][$i][17];
$return[“Game”][“Province”] = $data[“DATA”][$i][18];
$date = $return[“Game”][“Date”].’ ‘.str_replace(‘:00:000’,”,$return[“Game”][“Time”]);
$return[“Game”][“Timestamp”]= strtotime($date);
$return[“DATA”] = $data[“DATA”];

$return[“Game”][“ID”] = $data[“DATA”][$i][0];
// If the Home ID matches our ID, make the next opponent the Visiting Team.
// If the Visiting ID matches our ID, then make the next opponent the home team.
if($data[“DATA”][$i][5] == $this->team_id) {
$return[“Game”][“Vs”] = $return[“Game”][“Visitor”];
}
else {
$return[“Game”][“Vs”] = $return[“Game”][“Home”];
}
return $return;
}
/**
*
* Get the last score.
*
* @return array
*/

function getLastScore() {
$season = $this->getSeasonId(true);

$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘method’ => urlencode(“getSchedule”),
‘seasonID’ => urlencode($season),
‘showGameType’ => urlencode(‘ALL’),
‘futurePastTodayAll’ => urlencode(‘PAST’)
);

/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);

$count = count($data[“DATA”]);
if(@$data[“DATA”][($count-1)][54] > 0) {
$return[“Period”] = ‘ Overtime ‘;
}
elseif(@$data[“DATA”][($count-1)][43] > 0) {
$return[“Period”] = ‘ Overtime ‘;
}
elseif(@$data[“DATA”][($count-1)][44] > 0) {
$return[“Period”] = ‘ Shoot Out ‘;
}
elseif(@$data[“DATA”][($count-1)][55] > 0) {
$return[“Period”] = ‘ Shoot Out ‘;
}
else { $return[“Period”] = ‘Final’; }
$return[“GameID”] = $data[“DATA”][($count-1)][0];
$return[“Home”][“Team”] = $data[“DATA”][($count-1)][6];
$return[“Home”][“Score”] = $data[“DATA”][($count-1)][39];
$return[“Visitor”][“Team”] = $data[“DATA”][($count-1)][9];
$return[“Visitor”][“Score”] = $data[“DATA”][($count-1)][50];
return $return;
}

/**
*
* Returns the current season
*
* @return int – Returns the season ID for teh current season.
*/
function getSeasonId($cur=”) {
if(empty($_GET[“season”]) || !empty($cur)) {
$season = $this->getThisSeason();
$season = $season[“id”];
}
else {
$season = $_GET[“season”];
}
return $season;
}

/**
*
* Get this season.
*
* @return array – Returns the season Title and ID of the current season.
*/
function getThisSeason() {
/*?method=getSchedule*/
$url = ‘http://datafeed.esportsdesk.com/datafeed/datafeed.cfc?method=getSeasons’;

$fields = array(
‘codekey’ => urlencode($this->api_key),
‘method’ => urlencode(“getSeasons”)
);

/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);

$season[“id”] = $data[“DATA”][0][0];
$season[“title”] = $data[“DATA”][0][1];
return $season;
}

/**
*
* Contacts the .
*
* @param array $fields – List of fields to send to the feed url.
* @param string $dev – When true, it uses the development url instead of the feed url.
* Not available in production enviroment.
*
* feed_url – The URL to the API feed.
* @param string $directory description
* @return boolean
*/

function curl($fields,$dev=’false’) {
/* Do a check to make curl is alive somewhere. */
if (!function_exists(‘curl_init’) && @$_SERVER[‘HTTP_HOST’]!=’localhost’ ){

die(‘Sorry cURL is not installed!’);
}
//$this->show($fields);
$fields_string = ”;
foreach($fields as $key=>$value) { $fields_string .= $key.’=’.$value.’&’; }
rtrim($fields_string, ‘&’);

if(@$_SERVER[‘HTTP_HOST’]!=’localhost’) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_URL, $this->feed_url); // get the url contents
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Accept: application/json’));
$data = trim(curl_exec($ch)); // execute curl request
curl_close($ch);
}
else {
$data = array();
}
return $data;
}

/**
*
* Print an array to screen to help determine the values needed.
*
* @param array $array – This will print out the array in a readable format.
* @return boolean
*/
function show($array) {
echo ‘

';
			print_r($array);
			echo '

‘;
}

/**
*
* Get player statistics.
*
* @returns array – Returns array of player and their statistics.
*/
function getPlayerStats() {
$season = $this->getSeasonId();
$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘teamID’ => urlencode($this->team_id),
‘method’ => urlencode(“getPlayerStats”),
‘seasonID’ => urlencode($season),
);
/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);
return $data;
}
function getGoalieStats($type=’RS’) {
$season = $this->getSeasonId();
$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘teamID’ => urlencode($this->team_id),
‘method’ => urlencode(“getGoalieStats”),
‘showGameType’ => urlencode($type),
‘seasonID’ => urlencode($season)
);
/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);
return $data;
}

/**
*
* Get Player Profile Information
*
* @param int $playerid – The player id to get the data for.
* @param string $type – Choose what to get, player “stats” or player “profile”
* @param string $type_season – Get Regular season stats or PO stats.
* @echos Table rows (no table headers) showing penalties. TIME | TEAM | OFFENDER AND INFRACTION
*/
function getPlayerProfile($playerid,$type=’profile’,$type_season=’RS’) {
$season = $this->getSeasonId(true);
$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘playerID’ => urlencode($playerid),
‘method’ => urlencode(“getPlayerProfile”),
‘showGameType’ => urlencode($type_season),
‘profileOrStats’ => urlencode($type),
‘seasonID’ => urlencode($season)
);
/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);
return $data;
}

/**
*
* Show the league standings.
*
* @return array – Returns the array of league standings for the REGULAR SEASON ONLY.
*/
function getStandings() {
$season = $this->getSeasonId();
$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘teamID’ => urlencode($this->team_id),
‘method’ => urlencode(“getStandings”),
‘seasonID’ => urlencode($season),
‘showGameType’ => urlencode(‘RS’),
‘version’ => urlencode(3)
);
/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);

return $data;
}
/**
*
* Return the schedule information
*
* @param string $type – Pass what schedule you want to get. Exhinition, Playoff, ALL, Regular Season, etc…
* @return array – Returns the array of schedule information to be parsed and displayed on in page.
*/
function getSchedule($type=’RS’) {
$season = $this->getSeasonId();
$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘teamID’ => urlencode($this->team_id),
‘method’ => urlencode(“getSchedule”),
‘seasonID’ => urlencode($season),
‘showGameType’ => urlencode($type)
);
/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields),true);

return $data;
}
/**
*
* Show the box score penatlies statistics.
*
* @param int $gameID – Pass the game id of the game you wish to show the boxscore for or get it via (url.php?game=_______) where _____ = game id.
* @returns array – Returns an array of box score information. Pass this to goalsRow and penaltiesRow to create the tables for goal scorers and penalties in box scores page.
*/
function getBoxScore($gameID=”) {
if(empty($gameID)) {
$gameID = $_GET[“game”];
}
$season = $this->getSeasonId();
$fields_string = ”;
/*?method=getSchedule*/
$fields = array(
‘codekey’ => urlencode($this->api_key),
‘method’ => urlencode(“getBoxScores”),
‘gameID’ => urlencode($gameID),
‘version’ => urlencode(8),
‘outputStyle’ => urlencode(1)
);
/*Initiate Curl – move to new function later */
$data = json_decode($this->curl($fields,’true’),true);

return $data;
}
/**
*
* Show the box score goals statistics.
*
* @param array $score – Pass the returned data from the API to here in order to output the tables.
* @param int $period – What period, 1 2, 3 or 4.
* @echos Table rows (no table headers) showing penalties. TIME | TEAM | TYPE OF GOAL (PP, SH, EN) – GOAL SCORER AND ASSISTS
*/
function goalsRow($score,$period=’1′) {
$score[“scoringPeriod”.$period] = @array_reverse($score[“scoringPeriod”.$period]);
//sort($score[“scoringPeriod”.$period]);
//$this->show($score[“scoringPeriod”.$period]);
if(count(@$score[“scoringPeriod”.$period]) > 0) {
for($i=0;$iteam_id) {
$scored .= ‘‘.$score[“scoringPeriod”.$period][$i][“GOALSCORERNAME”].’‘;
if(!empty($score[“scoringPeriod”.$period][$i][“ASSIST1_NAME”])) {
$scored .= ‘ from ‘.$score[“scoringPeriod”.$period][$i][“ASSIST1_NAME”].’‘;
}
else { $scored .= ”; }
if(!empty($score[“scoringPeriod”.$period][$i][“ASSIST2_NAME”])) {
$scored .= ‘ and ‘.$score[“scoringPeriod”.$period][$i][“ASSIST2_NAME”].’‘;
}
}
else {
$scored = $score[“scoringPeriod”.$period][$i][“GOALSCORERNAME”];
if(!empty($score[“scoringPeriod”.$period][$i][“ASSIST1_NAME”])) {
$scored .= ‘ from ‘.$score[“scoringPeriod”.$period][$i][“ASSIST1_NAME”];
}
else { $scored .= ”;
}
if(!empty($score[“scoringPeriod”.$period][$i][“ASSIST2_NAME”])) {
$scored .= ‘ and ‘.$score[“scoringPeriod”.$period][$i][“ASSIST2_NAME”];
}
}

?>


No Scoring

0) {
for($i=0;$iteam_id) {
$scored .= ‘‘.$player.’‘;
$scored .= ‘, ‘.$score[“penaltyPeriod”.$period][$i][‘MP’].’ minutes for ‘.$score[“penaltyPeriod”.$period][$i][‘INFRACTION’].’.’;

}
else {
$scored = $player;
$scored .= ‘, ‘.$score[“penaltyPeriod”.$period][$i][‘MP’].’ minutes for ‘.$score[“penaltyPeriod”.$period][$i][‘INFRACTION’].’.’;

}

?>


No Penalties

# Name G A PTS

‘;
$count = count($score[$ah.”PLAYERSTATS”][“DATA”]);
for($i=0;$i<$count;$i++) { ?>

‘;

}
elseif($type==”GOALIE”) {
//HOMETEAMID
echo ‘

‘;
$count = count($score[$ah.”GOALIESTATS”][“DATA”]);
for($i=0;$i<$count;$i++) { arsort($score[$ah."GOALIESTATS"]["DATA"]); if($score[$ah."GOALIESTATS"]["DATA"][$i][8]=='ST') { $starter = ''; } else { $starter = '(Backup)'; } ?>


# Name MP SHOTS SAVES SAVE %


North Statistics

getStandings();
//$esports->show($standings); ?>

‘;
}
}
?>

Team GP W L T OTL PTS Last 10
‘.$standings[“DATA”][$i][53].’ ‘.number_format($standings[“DATA”][$i][25],0).’ ‘.(number_format($standings[“DATA”][$i][9]) + number_format($standings[“DATA”][$i][18],0)).’ ‘.number_format($standings[“DATA”][$i][10],0).’ ‘.number_format($standings[“DATA”][$i][11],0).’ ‘.(number_format($standings[“DATA”][$i][16],0) + number_format($standings[“DATA”][$i][17],0)).’ ‘.number_format($standings[“DATA”][$i][66],0).’ ‘.number_format($standings[“DATA”][$i][42],0).’-‘.number_format($standings[“DATA”][$i][43],0).’-‘.number_format($standings[“DATA”][$i][44],0).’-‘.number_format($standings[“DATA”][$i][47],0).’-‘.number_format($standings[“DATA”][$i][48],0).’