diff --git a/src/Entity/Question.php b/src/Entity/Question.php index d5c1041..ec251df 100644 --- a/src/Entity/Question.php +++ b/src/Entity/Question.php @@ -43,7 +43,7 @@ class Question /** * @var Collection */ - #[ORM\OneToMany(targetEntity: Modality::class, mappedBy: 'question')] + #[ORM\OneToMany(targetEntity: Modality::class, mappedBy: 'question', cascade: ['persist', 'remove'])] private Collection $modalitys; /** diff --git a/src/Form/ModalityType.php b/src/Form/ModalityType.php new file mode 100644 index 0000000..d43d021 --- /dev/null +++ b/src/Form/ModalityType.php @@ -0,0 +1,29 @@ +add('name_en') + ->add('name_fr') + ->add('name_ar') + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Modality::class, + ]); + } +} diff --git a/src/Form/QuestionType.php b/src/Form/QuestionType.php index f0b27d3..34d8872 100644 --- a/src/Form/QuestionType.php +++ b/src/Form/QuestionType.php @@ -2,15 +2,16 @@ namespace App\Form; -use App\Entity\Investigation; use App\Entity\Question; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; + use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; + class QuestionType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void @@ -40,17 +41,24 @@ class QuestionType extends AbstractType ->add('type_modality', ChoiceType::class, [ 'label' => 'Type', 'choices' => [ - 'text' => '0', - 'image' => '1', - 'video' => '2', - 'son' => '3', - 'input text' => '4', + 'Text' => '1', + 'Image' => '3', + 'Video' => '4', + 'Son' => '5', + 'Form Text' => '2', ], 'placeholder' => 'Choose a type modality', // Optional placeholder 'required' => true, ]) ->add('amount') ->add('max_participant') + ->add('modalitys', CollectionType::class, array( + 'entry_type' => ModalityType::class, + 'allow_add' => true, + 'allow_delete' => true, + 'prototype' => true, + 'by_reference' => false + )) ; } diff --git a/templates/investigation/add-index.html.twig b/templates/investigation/add-index.html.twig index dd41485..68b6d17 100644 --- a/templates/investigation/add-index.html.twig +++ b/templates/investigation/add-index.html.twig @@ -165,6 +165,102 @@ + + {% set prototype %} +
+ + {# EN #} +
+ EN + {{ form_widget(formQuestion.modalitys.vars.prototype.name_en, { + attr: { + class: 'form-control', + placeholder: 'Nom (EN)' + } + }) }} +
+ {{ form_errors(formQuestion.modalitys.vars.prototype.name_en) }} + + {# FR #} +
+ FR + {{ form_widget(formQuestion.modalitys.vars.prototype.name_fr, { + attr: { + class: 'form-control', + placeholder: 'Nom (FR)' + } + }) }} +
+ {{ form_errors(formQuestion.modalitys.vars.prototype.name_fr) }} + + {# AR #} +
+ AR + {{ form_widget(formQuestion.modalitys.vars.prototype.name_ar, { + attr: { + class: 'form-control', + placeholder: 'الاسم (AR)', + dir: 'rtl' + } + }) }} +
+ {{ form_errors(formQuestion.modalitys.vars.prototype.name_ar) }} + + +
+ {% endset %} + + {# modalities #} +
+
+
+ + {% for modality in formQuestion.modalitys %} +
+ +
+ EN + {{ form_widget(modality.name_en, { + attr: { class: 'form-control', placeholder: 'Nom (EN)' } + }) }} +
+ {{ form_errors(modality.name_en) }} + +
+ FR + {{ form_widget(modality.name_fr, { + attr: { class: 'form-control', placeholder: 'Nom (FR)' } + }) }} +
+ {{ form_errors(modality.name_fr) }} + +
+ AR + {{ form_widget(modality.name_ar, { + attr: { + class: 'form-control', + placeholder: 'الاسم (AR)', + dir: 'rtl' + } + }) }} +
+ {{ form_errors(modality.name_ar) }} + + +
+ {% endfor %} +
+ +
+ +
+ +
+ +
+ + + @@ -198,7 +294,6 @@ {% endblock %} diff --git a/templates/investigation/form-question.html.twig b/templates/investigation/form-question.html.twig index e0a0b0a..412c67d 100644 --- a/templates/investigation/form-question.html.twig +++ b/templates/investigation/form-question.html.twig @@ -74,6 +74,104 @@ + + + {% set prototype %} +
+ + {# EN #} +
+ EN + {{ form_widget(formQtn.modalitys.vars.prototype.name_en, { + attr: { + class: 'form-control', + placeholder: 'Nom (EN)' + } + }) }} +
+ {{ form_errors(formQtn.modalitys.vars.prototype.name_en) }} + + {# FR #} +
+ FR + {{ form_widget(formQtn.modalitys.vars.prototype.name_fr, { + attr: { + class: 'form-control', + placeholder: 'Nom (FR)' + } + }) }} +
+ {{ form_errors(formQtn.modalitys.vars.prototype.name_fr) }} + + {# AR #} +
+ AR + {{ form_widget(formQtn.modalitys.vars.prototype.name_ar, { + attr: { + class: 'form-control', + placeholder: 'الاسم (AR)', + dir: 'rtl' + } + }) }} +
+ {{ form_errors(formQtn.modalitys.vars.prototype.name_ar) }} + + +
+ {% endset %} + + {# modalities #} +
+
+
+ + {% for modality in formQtn.modalitys %} +
+ +
+ EN + {{ form_widget(modality.name_en, { + attr: { class: 'form-control', placeholder: 'Nom (EN)' } + }) }} +
+ {{ form_errors(modality.name_en) }} + +
+ FR + {{ form_widget(modality.name_fr, { + attr: { class: 'form-control', placeholder: 'Nom (FR)' } + }) }} +
+ {{ form_errors(modality.name_fr) }} + +
+ AR + {{ form_widget(modality.name_ar, { + attr: { + class: 'form-control', + placeholder: 'الاسم (AR)', + dir: 'rtl' + } + }) }} +
+ {{ form_errors(modality.name_ar) }} + + +
+ {% endfor %} +
+ +
+ +
+ +
+ +
+ + + +