modalitys
This commit is contained in:
@@ -43,7 +43,7 @@ class Question
|
|||||||
/**
|
/**
|
||||||
* @var Collection<int, Modality>
|
* @var Collection<int, Modality>
|
||||||
*/
|
*/
|
||||||
#[ORM\OneToMany(targetEntity: Modality::class, mappedBy: 'question')]
|
#[ORM\OneToMany(targetEntity: Modality::class, mappedBy: 'question', cascade: ['persist', 'remove'])]
|
||||||
private Collection $modalitys;
|
private Collection $modalitys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
29
src/Form/ModalityType.php
Normal file
29
src/Form/ModalityType.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Entity\Modality;
|
||||||
|
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;
|
||||||
|
|
||||||
|
class ModalityType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('name_en')
|
||||||
|
->add('name_fr')
|
||||||
|
->add('name_ar')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => Modality::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,15 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Form;
|
namespace App\Form;
|
||||||
|
|
||||||
use App\Entity\Investigation;
|
|
||||||
use App\Entity\Question;
|
use App\Entity\Question;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||||
|
|
||||||
class QuestionType extends AbstractType
|
class QuestionType extends AbstractType
|
||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
@@ -40,17 +41,24 @@ class QuestionType extends AbstractType
|
|||||||
->add('type_modality', ChoiceType::class, [
|
->add('type_modality', ChoiceType::class, [
|
||||||
'label' => 'Type',
|
'label' => 'Type',
|
||||||
'choices' => [
|
'choices' => [
|
||||||
'text' => '0',
|
'Text' => '1',
|
||||||
'image' => '1',
|
'Image' => '3',
|
||||||
'video' => '2',
|
'Video' => '4',
|
||||||
'son' => '3',
|
'Son' => '5',
|
||||||
'input text' => '4',
|
'Form Text' => '2',
|
||||||
],
|
],
|
||||||
'placeholder' => 'Choose a type modality', // Optional placeholder
|
'placeholder' => 'Choose a type modality', // Optional placeholder
|
||||||
'required' => true,
|
'required' => true,
|
||||||
])
|
])
|
||||||
->add('amount')
|
->add('amount')
|
||||||
->add('max_participant')
|
->add('max_participant')
|
||||||
|
->add('modalitys', CollectionType::class, array(
|
||||||
|
'entry_type' => ModalityType::class,
|
||||||
|
'allow_add' => true,
|
||||||
|
'allow_delete' => true,
|
||||||
|
'prototype' => true,
|
||||||
|
'by_reference' => false
|
||||||
|
))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,6 +165,102 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% set prototype %}
|
||||||
|
<div class="modality-item border rounded p-3 mt-3 mb-3">
|
||||||
|
|
||||||
|
{# EN #}
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">EN</span>
|
||||||
|
{{ form_widget(formQuestion.modalitys.vars.prototype.name_en, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'Nom (EN)'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(formQuestion.modalitys.vars.prototype.name_en) }}
|
||||||
|
|
||||||
|
{# FR #}
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">FR</span>
|
||||||
|
{{ form_widget(formQuestion.modalitys.vars.prototype.name_fr, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'Nom (FR)'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(formQuestion.modalitys.vars.prototype.name_fr) }}
|
||||||
|
|
||||||
|
{# AR #}
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">AR</span>
|
||||||
|
{{ form_widget(formQuestion.modalitys.vars.prototype.name_ar, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'الاسم (AR)',
|
||||||
|
dir: 'rtl'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(formQuestion.modalitys.vars.prototype.name_ar) }}
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endset %}
|
||||||
|
|
||||||
|
{# modalities #}
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div id="modalities" data-prototype="{{ prototype|e('html_attr') }}">
|
||||||
|
|
||||||
|
{% for modality in formQuestion.modalitys %}
|
||||||
|
<div class="modality-item border rounded p-3 mb-3">
|
||||||
|
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">EN</span>
|
||||||
|
{{ form_widget(modality.name_en, {
|
||||||
|
attr: { class: 'form-control', placeholder: 'Nom (EN)' }
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(modality.name_en) }}
|
||||||
|
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">FR</span>
|
||||||
|
{{ form_widget(modality.name_fr, {
|
||||||
|
attr: { class: 'form-control', placeholder: 'Nom (FR)' }
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(modality.name_fr) }}
|
||||||
|
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">AR</span>
|
||||||
|
{{ form_widget(modality.name_ar, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'الاسم (AR)',
|
||||||
|
dir: 'rtl'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(modality.name_ar) }}
|
||||||
|
|
||||||
|
<button type="button" class="remove-modality btn btn-danger btn-sm"> Supprimer </button>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4">
|
||||||
|
<button type="button" id="add-modality" class="btn btn-primary">Ajouter une modalité</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -198,7 +294,6 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
console.log("ddddd");
|
|
||||||
var $collection = $('#questions-collection');
|
var $collection = $('#questions-collection');
|
||||||
var $addButton = $('.add-question');
|
var $addButton = $('.add-question');
|
||||||
|
|
||||||
@@ -252,6 +347,36 @@
|
|||||||
$(this).find('h5').text('Question N: ' + (index + 1));
|
$(this).find('h5').text('Question N: ' + (index + 1));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//modalities add-modality
|
||||||
|
const container = document.getElementById('modalities');
|
||||||
|
const addButton = document.getElementById('add-modality');
|
||||||
|
let index = container.children.length;
|
||||||
|
|
||||||
|
addButton.addEventListener('click', () => {
|
||||||
|
const prototype = container.dataset.prototype;
|
||||||
|
const html = prototype.replace(/__name__/g, index);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.classList.add('modality-item');
|
||||||
|
div.innerHTML = html +
|
||||||
|
'<button type="button" class="remove-modality btn btn-danger">Supprimer</button>';
|
||||||
|
|
||||||
|
container.appendChild(div);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
container.addEventListener('click', (e) => {
|
||||||
|
if (e.target.classList.contains('remove-modality')) {
|
||||||
|
e.target.closest('.modality-item').remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -74,6 +74,104 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% set prototype %}
|
||||||
|
<div class="modality-item border rounded p-3 mt-3 mb-3">
|
||||||
|
|
||||||
|
{# EN #}
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">EN</span>
|
||||||
|
{{ form_widget(formQtn.modalitys.vars.prototype.name_en, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'Nom (EN)'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(formQtn.modalitys.vars.prototype.name_en) }}
|
||||||
|
|
||||||
|
{# FR #}
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">FR</span>
|
||||||
|
{{ form_widget(formQtn.modalitys.vars.prototype.name_fr, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'Nom (FR)'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(formQtn.modalitys.vars.prototype.name_fr) }}
|
||||||
|
|
||||||
|
{# AR #}
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">AR</span>
|
||||||
|
{{ form_widget(formQtn.modalitys.vars.prototype.name_ar, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'الاسم (AR)',
|
||||||
|
dir: 'rtl'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(formQtn.modalitys.vars.prototype.name_ar) }}
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endset %}
|
||||||
|
|
||||||
|
{# modalities #}
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div id="modalities" data-prototype="{{ prototype|e('html_attr') }}">
|
||||||
|
|
||||||
|
{% for modality in formQtn.modalitys %}
|
||||||
|
<div class="modality-item border rounded p-3 mb-3">
|
||||||
|
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">EN</span>
|
||||||
|
{{ form_widget(modality.name_en, {
|
||||||
|
attr: { class: 'form-control', placeholder: 'Nom (EN)' }
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(modality.name_en) }}
|
||||||
|
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">FR</span>
|
||||||
|
{{ form_widget(modality.name_fr, {
|
||||||
|
attr: { class: 'form-control', placeholder: 'Nom (FR)' }
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(modality.name_fr) }}
|
||||||
|
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">AR</span>
|
||||||
|
{{ form_widget(modality.name_ar, {
|
||||||
|
attr: {
|
||||||
|
class: 'form-control',
|
||||||
|
placeholder: 'الاسم (AR)',
|
||||||
|
dir: 'rtl'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(modality.name_ar) }}
|
||||||
|
|
||||||
|
<button type="button" class="remove-modality btn btn-danger btn-sm"> Supprimer </button>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4">
|
||||||
|
<button type="button" id="add-modality" class="btn btn-primary">Ajouter une modalité</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user