Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c0fabf9433
|
@@ -49,7 +49,6 @@ class IndexController extends AbstractController
|
||||
$session->set('step', $step);
|
||||
$form = $this->getForm($test, $step);
|
||||
} else {
|
||||
$session->set('test_' . $test->getId(), true);
|
||||
$session->remove('step');
|
||||
$oldUuid = $this->getUuid();
|
||||
$this->getUuid(true);
|
||||
@@ -77,7 +76,8 @@ class IndexController extends AbstractController
|
||||
|
||||
return $this->render('index/results.html.twig',[
|
||||
'test' => $test,
|
||||
'existingAnswers' => $existingAnswers,
|
||||
'correctAnswers' => array_filter($existingAnswers, fn(UserAnswer $a) => $a->isCorrect()),
|
||||
'incorrectAnswers' => array_filter($existingAnswers, fn(UserAnswer $a) => !$a->isCorrect()),
|
||||
'service' => $this->questionService,
|
||||
'uuid' => $uuid,
|
||||
]);
|
||||
@@ -97,7 +97,7 @@ class IndexController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function getUuid($forceNew = false)
|
||||
private function getUuid(bool $forceNew = false)
|
||||
{
|
||||
$session = $this->requestStack->getCurrentRequest()->getSession();
|
||||
if (!$session->has('uuid') || $forceNew) {
|
||||
|
||||
@@ -72,9 +72,6 @@ class UserAnswer
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<AnswerModel>
|
||||
*/
|
||||
public function getAnswer(): array
|
||||
{
|
||||
return $this->answer;
|
||||
|
||||
@@ -22,10 +22,9 @@ class UserAnswerType extends AbstractType
|
||||
|
||||
public function __construct(private readonly QuestionService $questionService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
/** @var QuestionModel $questionModel */
|
||||
$questionModel = $options['questionModel'];
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
final class AnswerModel
|
||||
final readonly class AnswerModel
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $name,
|
||||
private readonly string $value,
|
||||
private readonly array $config
|
||||
private string $name,
|
||||
private array $config
|
||||
)
|
||||
{
|
||||
|
||||
@@ -18,11 +17,6 @@ final class AnswerModel
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getConfig(): array
|
||||
{
|
||||
return $this->config;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
final class QuestionModel
|
||||
final readonly class QuestionModel
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $prompt,
|
||||
private readonly array $answers
|
||||
private string $prompt,
|
||||
private array $answers
|
||||
)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ final class QuestionModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @return array<AnswerModel>
|
||||
*/
|
||||
public function getAnswers(): array
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ class QuestionService
|
||||
{
|
||||
$questionAnswers = $question->getAnswers();
|
||||
$answers = array_map(
|
||||
fn($answer, $i) => new AnswerModel($this->assembleString($answer), $i, $answer),
|
||||
fn($answer, $i) => new AnswerModel($this->assembleString($answer), $answer),
|
||||
$questionAnswers,
|
||||
array_keys($questionAnswers)
|
||||
);
|
||||
@@ -92,7 +92,7 @@ class QuestionService
|
||||
$result *= (float) $nextEntry['value'];
|
||||
break;
|
||||
case OperatorsEnum::DIV:
|
||||
if((double) $nextEntry['value'] === 0.0) {
|
||||
if((float) $nextEntry['value'] === 0.0) {
|
||||
throw new \RuntimeException('Division by 0');
|
||||
}
|
||||
$result /= (float) $nextEntry['value'];
|
||||
@@ -108,7 +108,7 @@ class QuestionService
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function assembleString(array $entries, $isPrompt = false): string
|
||||
public function assembleString(array $entries, bool $isPrompt = false): string
|
||||
{
|
||||
$ret = [];
|
||||
foreach($entries as $entry) {
|
||||
|
||||
@@ -7,16 +7,26 @@
|
||||
<h4>You finished trial: <strong>{{ test.getName() }}</strong></h4>
|
||||
<h5>Your results <a href="{{ url('test_results', {'test_id': test.getId(), 'uuid': uuid}) }}">link</a></h5>
|
||||
<div class="row">
|
||||
<ul class="list-group">
|
||||
{% for existingAnswer in existingAnswers %}
|
||||
<li class="list-group-item {% if not existingAnswer.isCorrect() %}list-group-item-danger{% else %}list-group-item-success{% endif %}">
|
||||
{{ service.getQuestionModel(existingAnswer.question).getPrompt() }}
|
||||
{% for answer in existingAnswer.getAnswer() %}
|
||||
<ul class="list-group col">
|
||||
{% for correctAnswer in correctAnswers %}
|
||||
<li class="list-group-item {% if not correctAnswer.isCorrect() %}list-group-item-danger{% else %}list-group-item-success{% endif %}">
|
||||
{{ service.getQuestionModel(correctAnswer.question).getPrompt() }}
|
||||
{% for answer in correctAnswer.getAnswer() %}
|
||||
{{ service.assembleString(answer) }}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<ul class="list-group col">
|
||||
{% for incorrectAnswer in incorrectAnswers %}
|
||||
<li class="list-group-item {% if not incorrectAnswer.isCorrect() %}list-group-item-danger{% else %}list-group-item-success{% endif %}">
|
||||
{{ service.getQuestionModel(incorrectAnswer.question).getPrompt() }}
|
||||
{% for answer in incorrectAnswer.getAnswer() %}
|
||||
{{ service.assembleString(answer) }}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user