aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/app
diff options
context:
space:
mode:
Diffstat (limited to 'services/app')
-rw-r--r--services/app/assets/loading.js8
-rw-r--r--services/app/src/App.php28
-rw-r--r--services/app/templates/answer_view.html.twig5
3 files changed, 40 insertions, 1 deletions
diff --git a/services/app/assets/loading.js b/services/app/assets/loading.js
index 4699303..986fa43 100644
--- a/services/app/assets/loading.js
+++ b/services/app/assets/loading.js
@@ -1,4 +1,6 @@
document.addEventListener('DOMContentLoaded', () => {
+ const phperTokenElem = document.getElementsByClassName('js-phper-token')[0];
+
const aggregatedStatusElem = document.getElementsByClassName('js-aggregated-execution-status')[0];
const aggregatedStatusLoadingIndicatorElem = document.getElementsByClassName('js-aggregated-execution-status-loading-indicator')[0];
const answerId = aggregatedStatusElem.dataset.answerId;
@@ -20,7 +22,11 @@ document.addEventListener('DOMContentLoaded', () => {
timerId = setInterval(() => {
fetch(apiUrl)
.then(response => response.json())
- .then(({ aggregated_status, testcase_executions }) => {
+ .then(({ aggregated_status, testcase_executions, phper_token }) => {
+ if (phper_token) {
+ phperTokenElem.textContent = `バーディー! ${phper_token}`;
+ }
+
for (const ex of testcase_executions) {
const statusElem = statusElemsMap.get(ex.id);
const loadingIndicatorElem = statusLoadingIndicatorElemsMap.get(ex.id);
diff --git a/services/app/src/App.php b/services/app/src/App.php
index 9d6cc70..9502976 100644
--- a/services/app/src/App.php
+++ b/services/app/src/App.php
@@ -26,6 +26,9 @@ use Nsfisis\Albatross\Middlewares\CacheControlPrivateMiddleware;
use Nsfisis\Albatross\Middlewares\CurrentUserMiddleware;
use Nsfisis\Albatross\Middlewares\TrailingSlash;
use Nsfisis\Albatross\Middlewares\TwigMiddleware;
+use Nsfisis\Albatross\Models\AggregatedExecutionStatus;
+use Nsfisis\Albatross\Models\Answer;
+use Nsfisis\Albatross\Models\Quiz;
use Nsfisis\Albatross\Models\User;
use Nsfisis\Albatross\Repositories\AnswerRepository;
use Nsfisis\Albatross\Repositories\QuizRepository;
@@ -385,11 +388,16 @@ final class App
throw new HttpForbiddenException($request);
}
+ if ($currentUser !== null) {
+ $phper_token = $this->obtainPhperToken($quiz, $answer, $currentUser);
+ }
+
return $this->render($request, $response, 'answer_view.html.twig', [
'page_title' => "問題 #{$quiz->quiz_id} - 回答 #{$answer->answer_number}",
'quiz' => $quiz,
'answer' => $answer,
'testcase_executions' => $testcaseExecutionRepo->listByAnswerId($answer->answer_id),
+ 'phper_token' => $phper_token ?? null,
]);
}
@@ -881,6 +889,8 @@ final class App
$testcaseExecutions = $testcaseExecutionRepo->listByAnswerId($answer->answer_id);
+ $phper_token = $this->obtainPhperToken($quiz, $answer, $currentUser);
+
return $this->makeJsonResponse($response, [
'aggregated_status' => [
'label' => $answer->execution_status->label(),
@@ -893,6 +903,7 @@ final class App
'show_loading_indicator' => $ex->status->showLoadingIndicator(),
],
], $testcaseExecutions),
+ 'phper_token' => $phper_token,
])->withStatus(200);
}
@@ -944,6 +955,23 @@ final class App
->withStatus(200);
}
+ private function obtainPhperToken(Quiz $quiz, Answer $answer, User $currentUser): ?string
+ {
+ if ($answer->author_id !== $currentUser->user_id) {
+ return null;
+ }
+ if ($answer->execution_status !== AggregatedExecutionStatus::OK) {
+ return null;
+ }
+ if ($quiz->birdie_code_size === null) {
+ return null;
+ }
+ if ($answer->code_size > $quiz->birdie_code_size) {
+ return null;
+ }
+ return '#albatros-' . md5('KORE-HA-TEKITO-NA-SORUTO-DESU' . $quiz->slug);
+ }
+
private function makeJsonResponse(ResponseInterface $response, mixed $data): ResponseInterface
{
$payload = json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
diff --git a/services/app/templates/answer_view.html.twig b/services/app/templates/answer_view.html.twig
index af46b9d..300f2f5 100644
--- a/services/app/templates/answer_view.html.twig
+++ b/services/app/templates/answer_view.html.twig
@@ -15,6 +15,11 @@
</p>
<pre><code class="hljs language-php">{{ answer.code }}</code></pre>
<h2>実行結果</h2>
+ <div class="js-phper-token">
+ {% if phper_token %}
+ バーディー! {{ phper_token }}
+ {% endif %}
+ </div>
<div>
ステータス: <span class="js-aggregated-execution-status" data-answer-id="{{ answer.answer_id }}">{{ answer.execution_status.label() }}</span>
{% if answer.execution_status.showLoadingIndicator() %}