148 lines
5.1 KiB
PHP
148 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Form;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Doctrine\ORM\Query\Expr\Join;
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
|
|
|
|
class Niveau04Type extends AbstractType
|
|
{
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder->add('submit',
|
|
SubmitType::class, [
|
|
'label' => 'Valider',
|
|
'attr' => ['class' => 'btn btn-success'],
|
|
]
|
|
);
|
|
|
|
$access = $options['access'];
|
|
$userid = $options['userid'];
|
|
$builder->add('niveau01',
|
|
EntityType::class, [
|
|
'class' => "App\Entity\Niveau01",
|
|
'label' => $options['appNiveau01label'],
|
|
'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==',
|
|
'choice_label' => 'label',
|
|
'disabled' => ('submit' != $options['mode']),
|
|
'query_builder' => function (EntityRepository $er) use ($access, $userid) {
|
|
switch ($access) {
|
|
case 'admin':
|
|
return $er->createQueryBuilder('niveau01')->orderBy('niveau01.label', 'ASC');
|
|
break;
|
|
|
|
case 'modo':
|
|
$result = $er->createQueryBuilder('table')->innerJoin('App:UserModo', 'usermodo', Join::WITH, 'table.id = usermodo.niveau01')->orderBy('table.label', 'ASC');
|
|
$result->andWhere('usermodo.user = :user');
|
|
$result->setParameter('user', $userid);
|
|
|
|
return $result;
|
|
break;
|
|
}
|
|
},
|
|
]
|
|
);
|
|
|
|
$builder->add('niveau02',
|
|
Select2EntityType::class, [
|
|
'label' => $options['appNiveau02label'],
|
|
'required' => true,
|
|
'disabled' => ('submit' != $options['mode']),
|
|
'remote_route' => 'app_niveau02_selectlist',
|
|
'class' => "App\Entity\Niveau02",
|
|
// "req_params" => ["niveau01" => "parent.children[niveau01]"],
|
|
'primary_key' => 'id',
|
|
'text_property' => 'label',
|
|
'minimum_input_length' => 0,
|
|
'page_limit' => 10,
|
|
'allow_clear' => true,
|
|
'delay' => 250,
|
|
'cache' => false,
|
|
'cache_timeout' => 60000,
|
|
'language' => 'fr',
|
|
'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==',
|
|
]
|
|
);
|
|
|
|
$builder->add('niveau03',
|
|
Select2EntityType::class, [
|
|
'label' => $options['appNiveau03label'],
|
|
'required' => true,
|
|
'disabled' => ('submit' != $options['mode']),
|
|
'remote_route' => 'app_niveau03_selectlist',
|
|
'class' => "App\Entity\Niveau03",
|
|
// "req_params" => ["niveau01" => "parent.children[niveau01]"],
|
|
'primary_key' => 'id',
|
|
'text_property' => 'label',
|
|
'minimum_input_length' => 0,
|
|
'page_limit' => 10,
|
|
'allow_clear' => true,
|
|
'delay' => 250,
|
|
'cache' => false,
|
|
'cache_timeout' => 60000,
|
|
'language' => 'fr',
|
|
'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==',
|
|
]
|
|
);
|
|
|
|
$builder->add('label',
|
|
TextType::class, [
|
|
'label' => 'Label',
|
|
]
|
|
);
|
|
|
|
$builder->add('code',
|
|
TextType::class, [
|
|
'label' => 'Code',
|
|
'required' => false,
|
|
]
|
|
);
|
|
|
|
$builder->add('email',
|
|
EmailType::class, [
|
|
'label' => 'Mail',
|
|
'required' => false,
|
|
]
|
|
);
|
|
|
|
$builder->add('postaladress',
|
|
TextareaType::class, [
|
|
'label' => 'Adresse',
|
|
'required' => false,
|
|
'attr' => ['style' => 'height:90px'],
|
|
]
|
|
);
|
|
|
|
$builder->add('telephonenumber',
|
|
TextType::class, [
|
|
'label' => 'Téléphone',
|
|
'required' => false,
|
|
]
|
|
);
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => 'App\Entity\Niveau04',
|
|
'mode' => 'string',
|
|
'access' => 'string',
|
|
'userid' => 'string',
|
|
'appMasteridentity' => 'string',
|
|
'appNiveau01label' => 'string',
|
|
'appNiveau02label' => 'string',
|
|
'appNiveau03label' => 'string',
|
|
'appNiveau04label' => 'string',
|
|
]);
|
|
}
|
|
}
|