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
+56
View File
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace Mummert\SurveyBundle\QuestionType;
use Mummert\SurveyBundle\Model\SurveyContentModel;
use Symfony\Component\Form\Extension\Core\Type\RangeType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Range;
final class RangeQuestionType implements QuestionTypeInterface
{
public function getName(): string
{
return 'range';
}
public function getConstraints(SurveyContentModel $question): array
{
$constraints = [
new Range([
'min' => (int) $question->rangeMin,
'max' => (int) $question->rangeMax,
]),
];
if ('1' === (string) $question->mandatory) {
$constraints[] = new NotBlank();
}
return $constraints;
}
public function buildField(FormBuilderInterface $builder, SurveyContentModel $question, string $fieldName = 'answer'): void
{
$builder->add($fieldName, RangeType::class, [
'label' => false,
'constraints' => $this->getConstraints($question),
'attr' => [
'min' => (int) $question->rangeMin,
'max' => (int) $question->rangeMax,
'step' => max(1, (int) $question->rangeStep),
'class' => 'range range-primary w-full',
'data-controller' => 'range-preview',
'data-action' => 'input->range-preview#update',
],
]);
}
public function normalizeAnswer(mixed $value, SurveyContentModel $question): string
{
return (string) (int) $value;
}
}