%PDF- %PDF-
Direktori : /www/old2/_music/diplomka/diplomka/src/API/app/presenters/ |
Current File : /www/old2/_music/diplomka/diplomka/src/API/app/presenters/StatsPresenter.php |
<?php use Nette\Diagnostics\Debugger; use Nette\Application\Responses; /** * Stats presenter. */ class StatsPresenter extends BasePresenter { private $model; private $response; /** Injects Stats model into presenter * @param Stats $model Model to be injected */ public function injectModels(Stats $model) { $this->model = $model; } /** * Sets necessary things after response startup */ public function startup() { parent::startup(); $this->response = $this->getService('httpResponse'); } public function renderDefault() { } public function renderPlayerMaxLevel() { $data = $this->model->getPlayersMaxLevel(); $this->sendJSONData($data); } public function renderPlayerAp($name, $range, $city = 'Brno') { $data = $this->model->getPlayerAp($name, $range, $city); $this->sendJSONData($data); } public function renderPlayerApOverall($range, $city = 'Brno') { $data = $this->model->getPlayerApOverall($range, $city); usort($data, 'cmp_by_ap'); $this->sendJSONData($data); } public function renderPlayerResonatorDeploy($name, $range, $city = 'Brno') { $data = $this->model->getPlayerResonatorAction($name, 'resonator_create', $range, $city); $this->sendJSONData($data); } public function renderPlayerResonatorDestroy($name, $range, $city = 'Brno') { $data = $this->model->getPlayerResonatorAction($name, 'resonator_destroy', $range, $city); $this->sendJSONData($data); } public function renderPlayerLastActions($name, $range, $city = 'Brno') { $data = $this->model->getPlayerLastActions($name, $range, $city); $this->sendJSONData($data); } /** Sends an JSON response to client containing given data object or array * @param $data Data object or array to be serialized to JSON and sent out */ protected function sendJSONData($data) { $txt = json_encode($data, JSON_PRETTY_PRINT); $resp = new Responses\TextResponse($txt); $this->sendResponse($resp); } } // Helper static fucntions // TODO: do this more inteligently :D /** Compares two playerApInfo entities by total AP * @param $a First entity * @param $b Second entity * @return int Comparing int */ function cmp_by_ap($a, $b) { if ($a->total == $b->total) { return 0; } return ($a->total > $b->total) ? -1 : 1; }