src/FormSubscriber/RFPaqueteSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. // src/Form/EventListener/AddNameFieldSubscriber.php
  3. namespace App\FormSubscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Form\Extension\Core\Type\TextType;
  6. use Symfony\Component\Form\FormEvent;
  7. use Symfony\Component\Form\FormEvents;
  8. use Symfony\Component\Form\Form;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. class RFPaqueteSubscriber implements EventSubscriberInterface {
  11.     private $entityManager;
  12.     public function __construct(
  13.             EntityManagerInterface $entityManager
  14.     ) {
  15.         $this->entityManager $entityManager;
  16.     }
  17.     public static function getSubscribedEvents(): array {
  18.         // Tells the dispatcher that you want to listen on the form.pre_set_data
  19.         // event and that the preSetData method should be called.
  20.         return [FormEvents::PRE_SUBMIT => 'preSubmit'];
  21.     }
  22.     public function preSubmit(FormEvent $event): void {
  23.         $data $event->getData();
  24.         //data es un arreglo con los valores establecidos por el usuario en el form.
  25.         //como $data contiene el pais seleccionado por el usuario al enviar el formulario,
  26.         // usamos el valor de la posicion $data['country'] para filtrar el sql de los estados
  27.         if (isset($data['personaRecibe']) || isset($data['personaDestinatario'])) {
  28.             //  echo $data['personaRecibe'];exit;
  29.             if (isset($data['personaRecibe'])) {
  30.                 $idColaborador $data['personaRecibe'];
  31.             } else if (isset($data['personaDestinatario'])) {
  32.                 $idColaborador $data['personaDestinatario'];
  33.             }
  34.             $colaborador $this->entityManager->getRepository(\App\Entity\TerPersona::class)->find($idColaborador);
  35.             //   $salario = 0;
  36. //            $cargo = "N/A";
  37.             $proceso "N/A";
  38. //            $jefeProceso = "";
  39.             if ($colaborador->getPerfilCargo()) {
  40.                 $cargo $colaborador->getPerfilCargo()->getCargo()->getNombre();
  41.                 $proceso $colaborador->getPerfilCargo()->getParProceso()->getNombre();
  42.                 foreach ($colaborador->getPerfilCargo()->getPersona() as $persona) {
  43.                     if ($persona->getEstado()->getId() == 1) {
  44.                         foreach ($persona->getNivelCargo() as $nc) {
  45.                             if ($nc->getId() == || $nc->getId() == || $nc->getId() == 3) {
  46.                                 $jefeProceso $persona->getNombres();
  47.                             }
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.             //$data['cargoTmp'] = $cargo;
  53.             $data['procesoTmp'] = $proceso;
  54.             $event->getForm()
  55.                     //->add('cargoTmp', null, ['attr' => ['class' => 'form-control'], 'data' => $cargo, 'disabled' => true, 'label' => 'Cargo Actual', 'mapped' => false])
  56.                     ->add('procesoTmp'null, ['attr' => ['class' => 'form-control'], 'data' => $proceso'disabled' => true'label' => 'Proceso''mapped' => false])
  57.                     ->add('firma'null, ['attr' => ['class' => 'firma']]);
  58.                     //->add('jefeProcesoTmp', null, ['attr' => ['class' => 'form-control'], 'data' => $jefeProceso, 'disabled' => true, 'label' => 'Jefe Inmediato', 'mapped' => false]);
  59.         } else {
  60.             $event->getForm()
  61.                     //->add('cargoTmp', null, ['disabled' => true, 'label' => 'Cargo Actual', 'mapped' => false])
  62.                     ->add('procesoTmp'null, ['disabled' => true'label' => 'Proceso Actual''mapped' => false])
  63.                     ->add('firma'null, ['attr' => ['class' => 'firma']]);
  64.         }
  65.     }
  66. }