Initial survey bundle import

This commit is contained in:
Jürgen Mummert
2026-05-17 17:31:28 +02:00
commit b8475e3a57
84 changed files with 7157 additions and 0 deletions
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Mummert\SurveyBundle\QuestionType;
use Mummert\SurveyBundle\Model\SurveyContentModel;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\NotBlank;
final class YesNoMaybeQuestionType implements QuestionTypeInterface
{
public function getName(): string
{
return 'yes_no_maybe';
}
public function getConstraints(SurveyContentModel $question): array
{
$choices = ['yes', 'no'];
if ('1' === (string) $question->allowMaybe) {
$choices[] = 'maybe';
}
$constraints = [new Choice(['choices' => $choices])];
if ('1' === (string) $question->mandatory) {
$constraints[] = new NotBlank();
}
return $constraints;
}
public function buildField(FormBuilderInterface $builder, SurveyContentModel $question, string $fieldName = 'answer'): void
{
$choices = [
'Ja' => 'yes',
'Nein' => 'no',
];
if ('1' === (string) $question->allowMaybe) {
$choices['Vielleicht'] = 'maybe';
}
$builder->add($fieldName, ChoiceType::class, [
'label' => false,
'expanded' => true,
'multiple' => false,
'choices' => $choices,
'constraints' => $this->getConstraints($question),
]);
}
public function normalizeAnswer(mixed $value, SurveyContentModel $question): string
{
return mb_strtolower(trim((string) $value));
}
}