Compare commits

..

No commits in common. 'feedback' and 'master' have entirely different histories.

@ -49,6 +49,7 @@ 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);
@ -76,8 +77,7 @@ class IndexController extends AbstractController
return $this->render('index/results.html.twig',[ return $this->render('index/results.html.twig',[
'test' => $test, 'test' => $test,
'correctAnswers' => array_filter($existingAnswers, fn(UserAnswer $a) => $a->isCorrect()), 'existingAnswers' => $existingAnswers,
'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(bool $forceNew = false) private function getUuid($forceNew = false)
{ {
$session = $this->requestStack->getCurrentRequest()->getSession(); $session = $this->requestStack->getCurrentRequest()->getSession();
if (!$session->has('uuid') || $forceNew) { if (!$session->has('uuid') || $forceNew) {

@ -72,6 +72,9 @@ class UserAnswer
return $this; return $this;
} }
/**
* @return array<AnswerModel>
*/
public function getAnswer(): array public function getAnswer(): array
{ {
return $this->answer; return $this->answer;

@ -22,9 +22,10 @@ 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): void public function buildForm(FormBuilderInterface $builder, array $options)
{ {
/** @var QuestionModel $questionModel */ /** @var QuestionModel $questionModel */
$questionModel = $options['questionModel']; $questionModel = $options['questionModel'];

@ -2,11 +2,12 @@
namespace App\Model; namespace App\Model;
final readonly class AnswerModel final class AnswerModel
{ {
public function __construct( public function __construct(
private string $name, private readonly string $name,
private array $config private readonly string $value,
private readonly array $config
) )
{ {
@ -17,6 +18,11 @@ final readonly 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 readonly class QuestionModel final class QuestionModel
{ {
public function __construct( public function __construct(
private string $prompt, private readonly string $prompt,
private array $answers private readonly array $answers
) )
{ {
@ -18,7 +18,7 @@ final readonly class QuestionModel
} }
/** /**
* @return array<AnswerModel> * @return
*/ */
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), $answer), fn($answer, $i) => new AnswerModel($this->assembleString($answer), $i, $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((float) $nextEntry['value'] === 0.0) { if((double) $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, bool $isPrompt = false): string public function assembleString(array $entries, $isPrompt = false): string
{ {
$ret = []; $ret = [];
foreach($entries as $entry) { foreach($entries as $entry) {

@ -7,26 +7,16 @@
<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 col"> <ul class="list-group">
{% for correctAnswer in correctAnswers %} {% for existingAnswer in existingAnswers %}
<li class="list-group-item {% if not correctAnswer.isCorrect() %}list-group-item-danger{% else %}list-group-item-success{% endif %}"> <li class="list-group-item {% if not existingAnswer.isCorrect() %}list-group-item-danger{% else %}list-group-item-success{% endif %}">
{{ service.getQuestionModel(correctAnswer.question).getPrompt() }} {{ service.getQuestionModel(existingAnswer.question).getPrompt() }}
{% for answer in correctAnswer.getAnswer() %} {% for answer in existingAnswer.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>

Loading…
Cancel
Save