src/Controller/administrador/planTrabajoController.php line 141

Open in your IDE?
  1. <?php
  2. namespace App\Controller\administrador;
  3. use App\Entity\estudiante\planTrabajoEntity;
  4. use Symfony\Component\HttpFoundation\Cookie;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\Validator\Validator\ValidatorInterface;
  12. use App\Service\cryptService;
  13. use Doctrine\Persistence\ManagerRegistry;
  14. use App\Resource\Util\Util;
  15. use App\Resource\Dbal\Error;
  16. use App\Resource\Error\errorDisplay;
  17. use App\Resource\Util\fotoGeneral;
  18. use App\Entity\estudiante\presentacionAprobacionEntity;
  19. use App\Entity\estudiante\registroInicialEntity;
  20. use App\Resource\Util\modelSftp;
  21. /**
  22.  * @Route("/api/planTrabajo",name="API-planTrabajo-")
  23.  */
  24. class planTrabajoController extends AbstractController {
  25.     
  26.     use Util;
  27.     use Error;
  28.     /**
  29.      * @Route("/getPlanTrabajo", name="getPlanTrabajo")
  30.      * @param Request $request
  31.      * @return Response
  32.      */
  33.     public function getPlanTrabajo(Request $request ,cryptService $responManagerRegistry $doctrineValidatorInterface $validator) {
  34.         $error = new ErrorDisplay($request->query->all(), $validator);
  35.         /** @var \App\Entity\estudiante\planTrabajoEntity */
  36.         $entity $error->paramValidate(["codigo","serial"], planTrabajoEntity::class);
  37.         if (method_exists($entity"getstatusCode")) {
  38.             /** @var JsonResponse $entity */
  39.             return $entity;
  40.         }
  41.         /** @var  \App\Repository\estudiante\planTrabajoRepository */
  42.         $repository $doctrine->getRepository(planTrabajoEntity::class, 'default');
  43.         return new JsonResponse($respon->setResponse(
  44.             [
  45.                 'data' => $repository->conexionBD($this->getUser())->getPlanTrabajo($entity->getSerial())
  46.             ]
  47.         ));
  48.     }
  49. /**
  50.      * @Route("/postGuardarPlan", name="postGuardarPlan")
  51.      * @param Request $request
  52.      * @return Response
  53.      */
  54.     public function postGuardarPlan(Request $request ,cryptService $responManagerRegistry $doctrineValidatorInterface $validator) {
  55.         try{
  56.             $error = new ErrorDisplay($request->request->all(), $validator);
  57.             /** @var \App\Entity\estudiante\planTrabajoEntity */
  58.             $entity $error->paramValidate(["idAprobacion","fechaInicio","tipoVinculacion",
  59.             "fechaAfiliacion","fechaFinalizacion","semestre""anyo""titulo""urlVinculacion",
  60.             "observacion""tipo""idPlan","idCarta""idInicial"], planTrabajoEntity::class);
  61.             if (method_exists($entity"getstatusCode")) {
  62.                 /** @var JsonResponse $entity */
  63.                 return $entity;
  64.             }
  65.             $data = new modelSftp();
  66.             $file $request->files->get("file");
  67.           
  68.             if($file !== null){
  69.                 $data->validateFile($file,["pdf","PDF"], 20000000);
  70.                 $nombre '/contrato_'.$entity->getIdAprobacion(). '.'$file->getClientOriginalExtension();
  71.                 $data->setFile(file_get_contents($file), '/data/contrato',$nombre);
  72.             }else{
  73.                 $nombre '/contrato_'.$entity->getIdAprobacion(). '.pdf';
  74.             }        
  75.             /** @var  \App\Repository\estudiante\planTrabajoRepository */
  76.             $repository $doctrine->getRepository(planTrabajoEntity::class, 'default');
  77.             $repository->conexionBD($this->getUser());
  78.             if($entity->getTipo() === 'U'){
  79.                 $result$repository->putPlan($entity->getIdPlan(), $entity->getIdInicial(),$entity->getIdCarta(), 
  80.                 $entity->getIdAprobacion(), $entity->getTipoVinculacion(), $entity->getFechaInicio(), $entity->getFechaAfiliacion() ,  $entity->getObservacion(),
  81.                 $entity->getFechaFinalizacion(), $entity->getAnyo(), $entity->getSemestre(), $entity->getTitulo(),
  82.                 $this->getUser()->getUsername(),$nombre );
  83.             }else{
  84.                 $result $repository->postPlanTrabajo($entity->getIdAprobacion(), $entity->getTipoVinculacion(),
  85.                 $entity->getFechaInicio(), $entity->getFechaAfiliacion(), $entity->getObservacion(),
  86.                 $entity->getFechaFinalizacion(), $entity->getAnyo(), $entity->getSemestre(), $entity->getTitulo(),
  87.                 $this->getUser()->getUsername(),$nombre);
  88.             }
  89.             
  90.             return new JsonResponse($respon->setResponse(
  91.                 [
  92.                     'success' => $result,
  93.                     'data' =>  ($result) ? 'Inserción Correcta' 'se ha presentado un problema'
  94.                 ]
  95.             ));
  96.         }catch(\Exception $e){
  97.             return new JsonResponse($respon->setResponse(['success' => false,'data' => $e->getMessage()]));
  98.         }
  99.     }
  100.     /**
  101.      * @Route("/putExcepcion",  name="putExcepcion", methods={"POST"})
  102.      * @param Request $request
  103.      * @param ValidatorInterface $validator
  104.      * @return JsonResponse
  105.      */
  106.     public function putExcepcion(Request $request ,cryptService $responManagerRegistry $doctrineValidatorInterface $validator) {
  107.         try {
  108.             $error = new ErrorDisplay($request->request->all(), $validator);
  109.             /** @var \App\Entity\estudiante\planTrabajoEntity */
  110.             $entity $error->paramValidate(["idAprobacion","motivo","semestre""anyo""fechaFinalizacion"], planTrabajoEntity::class, 'post');
  111.             if (method_exists($entity"getstatusCode")) {
  112.                 /** @var JsonResponse $entity */
  113.                 return $entity;
  114.             }
  115.             /** @var  \App\Repository\estudiante\planTrabajoRepository */
  116.             $repository $doctrine()->getRepository(estudiante::class, 'default');
  117.             $data =  $repository->conexionBD($this->getUser())->putExcepcion($entity->getIdAprobacion(), $entity->getMotivo(), $entity->getAnyo(), $entity->getFechaFinalizacion(), $entity->getSemestre());
  118.             return new JsonResponse($respon->setResponse([
  119.                 'success' => ($data) ? true false,
  120.                 'data' => ($data) ? 'Excepción agregado' 'No se pudo agregar la excepción'
  121.             ]));
  122.         } catch (\Exception $e){
  123.             return new JsonResponse($respon->setResponse(['success' => false,'data' => $e->getMessage()]));
  124.         }
  125.     }
  126.     
  127.     /**
  128.      * @Route("/getFileVinculacion",  name="getFileVinculacion", methods={"GET"})
  129.      * @param Request $request
  130.      * @param ValidatorInterface $validator
  131.      * @return JsonResponse
  132.      */
  133.     public function getFileVinculacion(Request $request ,cryptService $responManagerRegistry $doctrineValidatorInterface $validator) {
  134.         try {
  135.             $error = new ErrorDisplay($request->query->all(), $validator);
  136.             /** @var \App\Entity\estudiante\planTrabajoEntity */
  137.             $entity $error->paramValidate(["idAprobacion" ], planTrabajoEntity::class, 'post');
  138.             if (method_exists($entity"getstatusCode")) {
  139.                 /** @var JsonResponse $entity */
  140.                 return $entity;
  141.             }
  142.             $data = new modelSftp();
  143.             $nombre 'contrato_'.$entity->getIdAprobacion().'.pdf';
  144.             $archivo $data->getFile('/data/contrato/',$nombre);
  145.             return new Response(base64_decode($archivo), 200,
  146.             [
  147.                 'Content-Type' => 'application/pdf',
  148.                 'Content-Disposition' => 'attachment; filename="'.$nombre.'"',
  149.             ]);
  150.         } catch (\Exception $e){
  151.             return new JsonResponse($respon->setResponse(['success' => false,'data' => $e->getMessage()]));
  152.         }
  153.     }
  154. }