POsteTYpe :
Code : Tout sélectionner
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('poste', EntityType::class, [
'class' => Poste::class,
'choice_label' => 'chef_equipe',
'query_builder' => function(EntityRepository $entityRepository ){
return $entityRepository->createQueryBuilder('p')->orderBy('p.nom_prenom', 'ASC');
}
])
->add('nom_prenom')
->add('lundi')
->add('mardi')
->add('mercredi')
->add('jeudi')
->add('vendredi')
->add('samedi')
->add('dimanche')
->add('chef_equipe')
->add('equipe');
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Poste::class,
'mapped' => false,
]);
}
Code : Tout sélectionner
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('poste', Entity::class, [
'class' => Poste::class,
'choice_label' => 'chefEquipe',
'placeHolder'=>"selectionner votre chef d'/ equipe ",
'mapped'=> false,
'query_builder' => function(EntityRepository $entityRepository ){
return $entityRepository->createQueryBuilder('poste')->orderBy('p.nom_prenom', 'ASC');
}
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Poste::class,
'mapped' => false,
]);
}
}
Code : Tout sélectionner
MainController :
/**
* @Route("/", name="main")
*/
public function index()
{
return $this->render('main/index.html.twig');
}
/**
* @Route("/searchChefF", name="searchChef")
*/
public function searchChef(Request $request,SearchChefFormType $searchChefFormType)
{
$searchChefForm = $this->createForm(SearchChefFormType::class);
$searchChefForm->handleRequest($request);
$chef = $searchChefForm->get('chef_equipe')->getData();
if ($searchChefForm->isSubmitted() && $searchChefForm->isValid()) {
$listeParChef = $this->getDoctrine()->getRepository(Poste::class)->findByChef($chef);
return $this->render('Poste/Find.html.twig', [
'listeParChef' => $listeParChef,
'nbPage' => 0,
]);
}
return $this->render('main/SearchChef.html.twig', [
'findByChef' => $searchChefFormType->createView(),
'nbPage' => 0,
]);
}
}
Code : Tout sélectionner
class PosteController extends Controller
{
/**
* @Route("/", name="poste_index", methods={"GET","POST"})
*/
public function index(PosteRepository $posteRepository): Response
{
return $this->render('poste/index.html.twig', [
'postes' => $posteRepository->findAll(),
]);
}
/**
* @Route("/", name="_form", methods={"GET","POST"})
*/
public function _form(PosteRepository $posteRepository): Response
{
return $this->render('poste/_form.html.twig', [
'postes' => $posteRepository->FindByChef(),
]);
}
/**
* @Route("/findByChef/{chef_equipe}", name="findByChef")
* @ $chefEquipe
* @return Response
*/
public function findByChef($chefEquipe) :Response
{
$allByChef = $this->getDoctrine()->getRepository(Poste::class)->findByChef($chefEquipe);
return $this->render('poste/findByChef.html.twig', ['listeParChef' => $allByChef]);
}
Code : Tout sélectionner
/**
* @method Poste|null find($id, $lockMode = null, $lockVersion = null)
* @method Poste|null findOneBy(array $criteria, array $orderBy = null)
* @method Poste[] findAll()
* @method Poste[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PosteRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Poste::class);
}
/* public function listChef($chef_equipe): Collection
{
$dql = ' SELECT p.chef_equipe FROM App\Entity\Poste p ';
return $this->getEntityManager()
->createQuery($dql)
->setParameter('chef_equipe', $chef_equipe)
->getResult();
}*/
public function FindByChefEquipe($chef_equipe)
{
// Requete avec jointure pour récupérer les employé par chef d'equipe
$dql = 'SELECT p FROM App\Entity\Poste p
INNER JOIN App\Entity\Horaire AS h WITH p.nom_prenom = h.nom_prenom
where p.chef_equipe= :value
order by p.nom_prenom ';
return $this->getEntityManager()
->createQuery($dql)
->setParameter('value', $chef_equipe)
->getResult();
}
/**
* @param $value
* @return Poste[] Returns an array of Ad objects
*/
public function findByChef($chefEquipe): array
{
return $this->createQueryBuilder('p')
->innerJoin('p.nom_prenom','h.nom_prenom')
->andWhere('p.chef_equipe = :val')
->setParameter('val', $chefEquipe)
->orderBy('p.chef_equipe', 'ASC')
->getQuery()
->getResult();
}
Code : Tout sélectionner
1
2
3
4
5
6
7
8
9
10
11
12
{% extends 'base.html.twig' %}
{% block body %}
{{ form_start(findByChef) }}
{{ form_widget(findByChef) }}
<button class="btn">{{ button_label|default('rechercher') }}</button>
{{ form_end(findByChef) }}
{% endblock %}
{% block title %}
{% endblock %}
S'il vous plait aider moi !