Skip to content

Commit

Permalink
Added a get total map usage function that just returns the total numb…
Browse files Browse the repository at this point in the history
…er of games played on a given map
  • Loading branch information
ameerkat committed Dec 2, 2010
1 parent c525203 commit 2fe5f15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions example.php
Expand Up @@ -26,6 +26,8 @@
print_r($request->get_map_data(17525));
echo "\n===\nGet Latest Map Usage Stats: \n===\n";
print_r($request->get_latest_map_usage());
echo "\n===\nGet Total Map Usage Stats: \n===\n";
print_r($request->get_total_map_usage());
//echo "\n\n===\nSorted Map Data: \n===\n";
//print_r($request->get_sorted_map_data(17525));

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -23,8 +23,8 @@ record, defaulting to the 1v1 record of the last requested character
$request->get_bracket_data();

## TODO
* Add documentation for the new merged functions
* Add support for batch requests
* Add demo of new functions
* Add other helper functions for processing returned data
* Add documentation somewhere for the returned object structure
* Add sorted map statistics methods
29 changes: 28 additions & 1 deletion sc2ranks.php
Expand Up @@ -212,7 +212,7 @@ public function get_map_data($map_id){
* Returns the latest map usage statistics
* @param object $response_object optional response object, defaults
to the last valid response
* @return $object the deserialized team ranking object
* @return object the deserialized team ranking object
*/
public function get_latest_map_usage($response_object = null){
if($response_object == null){
Expand All @@ -237,6 +237,33 @@ public function get_latest_map_usage($response_object = null){
return array("date" => $latest_date, "value" => $latest_date_value);
}

/**
* Returns the total map usage statistics
* @param object $response_object optional response object, defaults to
* the last response, if the response isn't a map request then
* the function returns null, so you'll need to pass the proper
* response object for the map request you made.
* @return integer the total number of games played on this map
*/
public function get_total_map_usage($response_object = null){
if($response_object == null){
if($this->last_response != null && isset($this->last_response->teams)){
// We shouldn't have team for map data so this is wrong
return null;
}
else {
$response_object = $this->last_response;
}
}
if (isset($response_object->teams))
return null;
$total = 0;
foreach ($response_object as $value){
$total += $value;
}
return $total;
}

/**
* Returns the deserialized character data object from the info
* provided to the function.
Expand Down

0 comments on commit 2fe5f15

Please sign in to comment.