<?php
namespace App\Form;
//FOS\CKEditorBundle\Form\Type\CKEditorType
//composer require friendsofsymfony/ckeditor-bundle
use App\Entity\CertificationType;
use App\Entity\DeviceAndTraining;
use App\Entity\Domain;
use App\Entity\EducationLevel;
use App\Entity\Keywords;
use App\Entity\SubDomain;
use App\Entity\TrainingPlace;
use App\Entity\Trainings;
use App\Entity\Type;
use App\Entity\User;
use App\Repository\CertificationTypeRepository;
use App\Repository\DeviceAndTrainingRepository;
use App\Repository\DomainRepository;
use App\Repository\EducationLevelRepository;
use App\Repository\KeywordsRepository;
use App\Repository\SubDomainRepository;
use App\Repository\TrainingPlaceRepository;
use App\Repository\TrainingsRepository;
use App\Repository\TypeRepository;
use App\Repository\UserRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
class FicheType extends AbstractType
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('ficheTitle', TextType::class, [
'label' => 'Titre de la proposition*',
'required' => true,
])
->add('title', TextType::class, [
'label' => 'Titre de la fiche*',
'required' => true,
])
->add('subTitle', TextType::class, [
'label' => 'Sous-titre',
'required' => false,
])
->add('rncpOrRs', TextType::class, [
'label' => 'Enregistré RNCP ou RS',
'required' => false
])
->add('traineeOrEnterprise', TextType::class, [
'label' => 'Stagiaire et/ou Entreprise',
'required' => false,
])
->add('code', TextType::class, [
'label' => 'Code',
'required' => false,
])
->add('cutInBlocks', CheckboxType::class, [
'label' => 'Découpé en blocs',
'required' => false,
])
->add('domain', EntityType::class, [
'label' => 'Domaines',
'class' => Domain::class,
'choice_label' => 'name',
'query_builder' => function (DomainRepository $er) {
return $er->createQueryBuilder('d')
->orderBy('d.name', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'multiple' => true,
'required' => false,
])
->add('subDomain', EntityType::class, [
'label' => 'Sous-domaines',
'class' => SubDomain::class,
'choice_label' => 'name',
'query_builder' => function (SubDomainRepository $er) {
return $er->createQueryBuilder('s')
->orderBy('s.name', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'mapped' => true,
'multiple' => true,
'required' => false,
])
->add('new', CheckboxType::class, [
'label' => 'Nouveau',
'required' => false,
])
->add('objectives', CKEditorType::class, [
'label' => 'Objectifs',
'required' => false,
])
->add('complementaryObjectives', CKEditorType::class, [
'label' => 'Objectifs complémentaires',
'required' => false,
])
->add('pedagogicContent', CKEditorType::class, [
'label' => 'Contenu pédagogique',
'required' => false,
])
->add('pluses', CKEditorType::class, [
'label' => 'Les plus de la formation',
'required' => false,
])
->add('concernedPersons', CKEditorType::class, [
'label' => 'Personnes concernées',
'required' => false,
])
->add('prerequisites', CKEditorType::class, [
'label' => 'Prérequis',
'required' => false,
])
->add('companyMissions', CKEditorType::class, [
'label' => 'Missions en entreprise',
'required' => false,
])
->add('price', TextType::class, [
'label' => 'Prix',
'required' => false,
])
->add('time', CKEditorType::class, [
'required' => false,
'label' => 'Commentaire de durée',
])
->add('days', IntegerType::class, [
'label' => 'Nombre de jours',
'required' => false,
])
->add('hours', IntegerType::class, [
'label' => "Nombre d'heures",
'required' => false,
])
->add('date', TextType::class, [
'label' => 'Date de la formation',
'required' => false,
])
->add('trainingPlace', EntityType::class, [
'label' => 'Lieu de la formation',
'class' => TrainingPlace::class,
'choice_label' => 'name',
'query_builder' => function (TrainingPlaceRepository $trainingPlaceRepository) {
return $trainingPlaceRepository->createQueryBuilder('tp')
->orderBy('tp.name', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'required' => false,
])
->add('place', TextType::class, [
'label' => 'Lieu de la formation',
'required' => false,
])
->add('deviceAndTraining', EntityType::class, [
'label' => 'Dispositif de formation',
'class' => DeviceAndTraining::class,
'choice_label' => 'name',
'query_builder' => function (DeviceAndTrainingRepository $er) {
return $er->createQueryBuilder('d')
->orderBy('d.name', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'multiple' => true,
'required' => false,
])
->add('termsOfAccess', CKEditorType::class, [
'label' => "Modalités d'accès",
'required' => false,
])
->add('alternatingRythm', CKEditorType::class, [
'label' => "Rythme d'alternance",
'required' => false,
])
->add('teachingMethods', CKEditorType::class, [
'label' => 'Méthodes pédagogiques',
'required' => false,
])
->add('teachingMeans', CKEditorType::class, [
'label' => 'Moyens pédagogiques',
'required' => false,
])
->add('certificationType', EntityType::class, [
'label' => 'Type de certification',
'class' => CertificationType::class,
'choice_label' => 'name',
'query_builder' => function (CertificationTypeRepository $er) {
return $er->createQueryBuilder('d')
->orderBy('d.name', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'required' => false,
])
->add('educationLevel', CKEditorType::class, [
'label' => 'Commentaire niveau de formation',
'required' => false,
])
->add('educationLevelName', EntityType::class, [
'label' => 'Niveau de formation',
'class' => EducationLevel::class,
'choice_label' => 'name',
'query_builder' => function (EducationLevelRepository $educationLevelRepository) {
return $educationLevelRepository->createQueryBuilder('el')
->orderBy('el.name', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'multiple' => false,
'required' => false,
])
->add('certificationName', TextType::class, [
'label' => 'Nom de la certification',
'required' => false,
])
->add('assessmentMethods', CKEditorType::class, [
'label' => "Modalités d'évaluation",
'required' => false,
])
->add('targetFunctions', CKEditorType::class, [
'label' => 'Fonctions visées',
'required' => false,
])
->add('continuingStudies', CKEditorType::class, [
'label' => "Poursuite d'études",
'required' => false,
])
->add('disabledAccessibility', ChoiceType::class, [
'label' => 'Accessibilité',
'choices' => [
'Oui' => '0',
'Non' => '1',
'Rien' => '2',
],
'attr' => [
'class' => 'custom-control custom-radio selectgroup',
],
'multiple' => false,
'expanded' => true,
'required' => false
])
->add('pedagogicalReferent', EntityType::class, [
'label' => 'Référent pédagogique',
'class' => User::class,
'choice_label' => function($choice, $key, $value){
return $choice->getFirstName().' '.$choice->getLastName();
},
'query_builder' => function (UserRepository $er) {
return $er->createQueryBuilder('u')
->where("u.roles LIKE '%ROLE_INTERVENANT%'")
->orWhere("u.roles LIKE '%ROLE_COMMERCIAL%'")
->orWhere("u.roles LIKE '%ROLE_ADMIN%'")
->orderBy('u.firstName', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'required' => false,
'multiple' => true,
])
->add('commercials', EntityType::class, [
'label' => 'Contact Commercial',
'class' => User::class,
'choice_label' => function ($choice, $key, $value) {
return $choice->getFirstName() . ' ' . $choice->getLastName();
},
'query_builder' => function (UserRepository $er) {
return $er->createQueryBuilder('u')
->where("u.roles LIKE '%ROLE_COMMERCIAL%'")
->orWhere("u.roles LIKE '%ROLE_ADMIN%'")
->orderBy('u.firstName', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'required' => false,
'multiple' => true,
])
->add('accessibilityText', CKEditorType::class, [
'label' => "Texte d'accessiblité",
'required' => false,
])
->add('testimonials', CKEditorType::class, [
'label' => 'Témoignages',
'required' => false,
])
->add('linkedTrainings', EntityType::class, [
'class' => Trainings::class,
'choice_label' => 'title',
'query_builder' => function (TrainingsRepository $trainingsRepository) {
return $trainingsRepository->createQueryBuilder('t')
->andWhere('t.isFiche = :isFiche')
->setParameter('isFiche',0)
->orderBy('t.title', 'ASC');
},
'attr' => [
'class' => 'form-select choices select2',
],
'label' => 'Formations liées',
'required' => false,
'multiple' => true
])
->add('validityDateRncp', DateType::class, [
'label' => 'Date de validité du RNCP',
'required' => true
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Trainings::class,
]);
}
}