Skip to content

Instantly share code, notes, and snippets.

@Alan01252
Created August 22, 2012 14:55
Show Gist options
  • Save Alan01252/3426407 to your computer and use it in GitHub Desktop.
Save Alan01252/3426407 to your computer and use it in GitHub Desktop.
Before tidying!!!!!
/**
* This is an example of the structure returned from this function.
*
* $serviceData = [
* ['Points','Account 1','Account 2','Account 3'],
* [100,1000,null,null],
* [50,null,2000,null],
* [75,null,null,3000],
* ];
*
* $serviceData[0] is an array of arrays.
*
* $serviceData[0][0] is hardcoded to points
* $serviceData[0][1..n] are the names of the accounts
*
* $serviceData[1..n][0] are the points and the x axis on the graph
* $serviceData[1..n][1..n] is the revenue value for each account and the y axis on the hraph
*
* @return array An array in the format google chart requires to produce a scatter chart
*/
public function getServiceVsRevenueData() {
$apiUrl = symbleapi::getApiURL();
$stats = json_decode(file_get_contents($apiUrl.'/account/servicevsrevenuestats/'));
$serviceData[0][0] = 'Points';
foreach($stats as $stat) {
$serviceData[][0] = $stat->_id;
$keys = array_keys($serviceData);
$currentRow = end($keys);
$end = 0;
if(isset($stat->value->accounts)) {
foreach($stat->value->accounts as $account) {
$keys = array_keys($serviceData[0]);
$end = end($keys);
$serviceData[0][] = $account->name;
$serviceData[$currentRow][$end+1] = 12312312323;
}
}
else {
$keys = array_keys($serviceData[0]);
$end = end($keys);
$serviceData[0][] = $stat->value->name;
$serviceData[$currentRow][$end+1] = 12312312323;
$column = $end+1;
while($column > 1) {
$column--;
$serviceData[$currentRow][$column] = null;
}
}
while($currentRow > 1){
$currentRow--;
$serviceData[$currentRow][$end+1] = null;
}
}
$this->deep_ksort($serviceData);
echo "<pre>";
print_r($serviceData);
echo "</pre>";
return $serviceData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment