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