<?php
// src/Form/EventListener/AddNameFieldSubscriber.php
namespace App\FormSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Form;
use Doctrine\ORM\EntityManagerInterface;
class GHEntrenamientoProcesoSubscriber implements EventSubscriberInterface {
private $entityManager;
public function __construct(
EntityManagerInterface $entityManager
) {
$this->entityManager = $entityManager;
}
public static function getSubscribedEvents(): array {
// Tells the dispatcher that you want to listen on the form.pre_set_data
// event and that the preSetData method should be called.
return [FormEvents::PRE_SUBMIT => 'preSubmit'];
}
public function preSubmit(FormEvent $event): void {
$data = $event->getData();
//data es un arreglo con los valores establecidos por el usuario en el form.
//como $data contiene el pais seleccionado por el usuario al enviar el formulario,
// usamos el valor de la posicion $data['country'] para filtrar el sql de los estados
if (isset($data['proceso'])) {
$idBusqueda = $data['proceso'];
$proceso = $this->entityManager->getRepository(\App\Entity\ParProceso::class)->find($idBusqueda);
$desInduccion = "";
$event->getForm()
->add('responsable', \Symfony\Bridge\Doctrine\Form\Type\EntityType::class, ['class' => \App\Entity\TerPersona::class, 'query_builder' => function (\Doctrine\ORM\EntityRepository $er) use ($idBusqueda) {
return $er->createQueryBuilder('p')
->leftJoin('p.perfilCargo', 'pc')
->leftJoin('pc.ParProceso', 'pro')
->leftJoin('p.estado', 'e')
->where('pro.id = :idProceso')
->andWhere('e.id = 1')
->setParameter('idProceso', $idBusqueda)
->orderBy('p.nombres', 'ASC');
}, 'label' => 'Responsable',
'attr' => ['class' => 'form-control'], 'placeholder' => 'Seleccione una Opción.'])
;
foreach ($proceso->getMatrizEntrenamientoProceso() as $reg) {
$desInduccion = $reg->getDescripcion();
}
$data['descripcionEntrenamiento'] = $desInduccion;
$event->setData($data);
}
}
}