This repository was archived by the owner on Oct 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +52
-32
lines changed
src/Twig/Components/Challenge
templates/components/Challenge Expand file tree Collapse file tree 4 files changed +52
-32
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App \Twig \Components \Challenge ;
6+
7+ use App \Entity \Question ;
8+ use App \Service \QuestionDbRunnerService ;
9+ use Symfony \UX \LiveComponent \Attribute \AsLiveComponent ;
10+ use Symfony \UX \LiveComponent \Attribute \LiveProp ;
11+ use Symfony \UX \LiveComponent \DefaultActionTrait ;
12+
13+ #[AsLiveComponent]
14+ final class ColumnsOfAnswer
15+ {
16+ use DefaultActionTrait;
17+
18+ public function __construct (
19+ private readonly QuestionDbRunnerService $ questionDbRunnerService ,
20+ ) {
21+ }
22+
23+ #[LiveProp]
24+ public Question $ question ;
25+
26+ /**
27+ * Get the columns of the answer.
28+ *
29+ * @return string[] the columns of the answer
30+ */
31+ public function getColumnsOfAnswer (): array
32+ {
33+ try {
34+ $ answer = $ this ->questionDbRunnerService ->getAnswerResult ($ this ->question );
35+ $ answerResult = $ answer ->getResult ();
36+
37+ if (0 === \count ($ answerResult )) {
38+ return [];
39+ }
40+
41+ return $ answer ->getResult ()[0 ];
42+ } catch (\Throwable $ e ) {
43+ return ["⚠️ Invalid Question: {$ e ->getMessage ()}" ];
44+ }
45+ }
46+ }
Original file line number Diff line number Diff line change 55namespace App \Twig \Components \Challenge ;
66
77use App \Entity \Question ;
8- use App \Service \QuestionDbRunnerService ;
98use Symfony \UX \TwigComponent \Attribute \AsTwigComponent ;
109
1110#[AsTwigComponent]
1211final class Description
1312{
14- public function __construct (
15- private readonly QuestionDbRunnerService $ questionDbRunnerService ,
16- ) {
17- }
18-
1913 public Question $ question ;
20-
21- /**
22- * Get the columns of the answer.
23- *
24- * @return string[] the columns of the answer
25- */
26- public function getColumnsOfAnswer (): array
27- {
28- try {
29- $ answer = $ this ->questionDbRunnerService ->getAnswerResult ($ this ->question );
30- $ answerResult = $ answer ->getResult ();
31-
32- if (0 === \count ($ answerResult )) {
33- return [];
34- }
35-
36- return $ answer ->getResult ()[0 ];
37- } catch (\Throwable $ e ) {
38- return ["⚠️ Invalid Question: {$ e ->getMessage ()}" ];
39- }
40- }
4114}
Original file line number Diff line number Diff line change 1+ <p {{ attributes }}>
2+ <strong >輸出格式:</strong >欄位順序分別為:<code >{{
3+ this .columnsOfAnswer | joinToQuoted(' 、' )
4+ }}</code >。
5+ </p >
Original file line number Diff line number Diff line change 33 {{ question .description | raw }}
44 </div >
55
6- <p >
7- <strong >輸出格式:</strong >欄位順序分別為:<code >{{
8- this .columnsOfAnswer | joinToQuoted(' 、' )
9- }}</code >。
10- </p >
6+ <twig:Challenge:ColumnsOfAnswer :question =" question" loading =" defer" />
117
128 {% if question .schema %}
139 <p ><strong >Schema ({{ question .schema .id }}): </strong >
You can’t perform that action at this time.
0 commit comments