quiz->quiz_id} - 提出"; } public function redirectUrl(): string { $answer = $this->answer; assert(isset($answer)); return $this->routeParser->urlFor( 'answer_view', ['qslug' => $this->quiz->slug, 'anum' => "$answer->answer_number"], ); } protected function submitLabel(): string { return '投稿'; } /** * @return list */ protected function items(): array { return [ new FormItem( name: 'code', type: 'textarea', label: 'コード', isRequired: true, extra: 'rows=3 cols=80', ), ]; } /** * @return array{quiz: Quiz, is_closed: bool} */ public function getRenderContext(): array { return [ 'quiz' => $this->quiz, 'is_closed' => $this->quiz->isClosedToAnswer(), ]; } public function submit(): void { if ($this->quiz->isClosedToAnswer()) { $this->state->setErrors(['general' => 'この問題の回答は締め切られました']); throw new FormSubmissionFailureException(); } $code = $this->state->get('code') ?? ''; try { $answer_id = $this->conn->transaction(function () use ($code) { $answer_id = $this->answerRepo->create( $this->quiz->quiz_id, $this->currentUser->user_id, $code, ); $this->testcaseExecutionRepo->enqueueForSingleAnswer( $answer_id, $this->quiz->quiz_id, ); return $answer_id; }); } catch (EntityValidationException $e) { $this->state->setErrors($e->toFormErrors()); throw new FormSubmissionFailureException(previous: $e); } $answer = $this->answerRepo->findById($answer_id); assert(isset($answer)); $this->answer = $answer; } }