src/Controller/Api/AfectadoEvaluacionController.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Afectado;
  4. use App\Entity\Evaluacion;
  5. use App\Entity\EvaluacionEvacuacion;
  6. use App\Entity\EvaluacionInicial;
  7. use App\Entity\EvaluacionMeta;
  8. use App\Entity\EvaluacionStart;
  9. use App\Entity\Herida;
  10. use App\Entity\Incidente;
  11. use App\Entity\Pregunta;
  12. use App\Entity\Respuesta;
  13. use App\Form\AfectadoApiCreateType;
  14. use App\Form\AfectadoEvaluacionCreateType;
  15. use App\Form\HeridaApiCreateType;
  16. use App\Repository\AfectadoRepository;
  17. use App\Repository\EvaluacionRepository;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Exception;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Nelmio\ApiDocBundle\Annotation\Model;
  22. use Nelmio\ApiDocBundle\Annotation\Security;
  23. use OpenApi\Annotations as OA;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use Psr\Log\LoggerInterface;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Symfony\Component\HttpFoundation\JsonResponse;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\Serializer\SerializerInterface;
  30. /**
  31.  * @Route("afectados/", name="api_afectados_")
  32.  */
  33. class AfectadoEvaluacionController extends AbstractController
  34. {
  35.     public function __construct(LoggerInterface $loggerEntityManagerInterface $emAfectadoRepository $erSerializerInterface $serializer)
  36.     {
  37.         $this->logger $logger;
  38.         $this->serializer $serializer;
  39.         $this->em $em;
  40.         $this->er $er;
  41.     }
  42.     /**
  43.      * @Route("{afectadoId}/evaluacion/{evaluacionId}/tipo/{tipo}", name="delete_evaluacion", methods={"DELETE"})
  44.      */
  45.     public function deleteEvaluacion(Request $request$afectadoId$evaluacionId$tipo)
  46.     {
  47.         $this->logger->info('Testing api delete-evaluacion afectado evaluacion');
  48.         $afectado $this->er->find($afectadoId);
  49.         switch ($tipo) {
  50.             case 'inicial':
  51.                 $evaluacion $this->em->getRepository(EvaluacionInicial::class)->findBy(['afectado' => $afectadoId'evaluacion' => $evaluacionId]);
  52.                 $afectado->setInical(null);
  53.                 break;
  54.             case 'start':
  55.                 $evaluacion $this->em->getRepository(EvaluacionStart::class)->findBy(['afectado' => $afectadoId'evaluacion' => $evaluacionId]);
  56.                 $afectado->setStart(null);
  57.                 break;
  58.             case 'meta':
  59.                 $evaluacion $this->em->getRepository(EvaluacionMeta::class)->findBy(['afectado' => $afectadoId'evaluacion' => $evaluacionId]);
  60.                 $afectado->setMeta(null);
  61.                 break;
  62.             case 'evacuacion':
  63.                 $evaluacion $this->em->getRepository(EvaluacionEvacuacion::class)->findBy(['afectado' => $afectadoId'evaluacion' => $evaluacionId]);
  64.                 $afectado->serEvacuacion(null);
  65.                 break;
  66.             default:
  67.                 return new Response($this->serializer->serialize(
  68.                     ['status' => 'HTTP_BAD_REQUEST''code' => Response::HTTP_BAD_REQUEST'error' => 'Parametros incorrectos'],
  69.                     "json",
  70.                 ), Response::HTTP_BAD_REQUEST);
  71.                 break;
  72.         }
  73.         if ($evaluacion[0]) {
  74.             $this->em->remove($evaluacion[0]);
  75.             $this->em->flush();
  76.         }
  77.         
  78.         return new Response($this->serializer->serialize(
  79.             $afectado,
  80.             "json",
  81.             ['groups' => ['afectado''afectado_heridas''afectado_evaluacion']]
  82.         ), Response::HTTP_OK);
  83.     }
  84. }