public function index($instanceId) { $user = AuthController::auth(); $scoreRepo = new ScoreRepository(); $scores = $scoreRepo->getScoreByInstanceId($instanceId); $instanceRepo = new InstanceRepository(); $instance = $instanceRepo->get($instanceId); usort($scores, function ($a, $b) { if ($a->score == $b->score) { return 0; } return $a->score < $b->score ? 1 : -1; }); $this->view('score.php', ['user' => $user, 'scores' => $scores, 'instance' => $instance]); }
public function delete() { $request = json_decode(file_get_contents("php://input")); if (!$this->auth($request->id, $request->password)) { http_response_code(401); } else { $scoreRepo = new ScoreRepository(); $score = $scoreRepo->get($request->scoreId); $scoreRepo->delete($request->scoreId); $scores = $scoreRepo->getScoreByInstanceId($request->id); $count = count($scores); $returnData['score']['id'] = $score->id; $returnData['score']['name'] = $score->name; $returnData['score']['score'] = $score->score; $returnData['count'] = $count; header('Content-Type: application/json'); echo json_encode($returnData); } }