src/Controller/PJAController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Valtozat;
  4. use App\Model\ArchiveAttachment;
  5. use App\Model\ArchiveLegislation;
  6. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  7. use Symfony\Component\HttpFoundation\HeaderUtils;
  8. use Symfony\Component\HttpFoundation\StreamedResponse;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use App\Tools\RendeletListaParams;
  12. use App\Entity\Wadmin;
  13. use Psr\Log\LoggerInterface;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use App\Entity\Temakor;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. class PJAController extends AbstractController
  19. {
  20.     /**
  21.      * @Route("/restapi/temakorok", name="temakorlista")
  22.      */
  23.     public function temakorok(Request $request)
  24.     {
  25.         $temas $this->getDoctrine()->getRepository(Temakor::class)->getRestapiTemakor();
  26.         return new JsonResponse($temas);
  27.     }
  28.     /**
  29.      * @Route("/restapi/dokumentumok/lista{token}", defaults={"_format"="xml"}, name="rendeletlista")
  30.      */
  31.     public function lista($tokenRequest $request)
  32.     {
  33.         $params = new RendeletListaParams();
  34.         $rquery $request->query;
  35.         if (!$rquery->has('kod') && !($rquery->has('kibocsato_kod') && $params->setKibocsatoKod($rquery->get('kibocsato_kod')))) {
  36.             return $this->render('pja/lista.xml.twig', [
  37.                 'wcount' => 0,
  38.                 'wadmin' => array()
  39.             ]);
  40.         }
  41.         if ($rquery->has('tipus_kod')) {
  42.             $params->setTipusKod($rquery->get('tipus_kod'));
  43.         }
  44.         if ($rquery->has('include_archive')) {
  45.             $params->setIncArchive($rquery->get('include_archive'));
  46.         }
  47.         if ($rquery->has('include_hatkiv')) {
  48.             $params->setIncHatkiv($rquery->get('include_hatkiv'));
  49.         }
  50.         if ($rquery->has('fromoffset')) {
  51.             $params->setFromoffset($rquery->get('fromoffset'));
  52.         }
  53.         if ($rquery->has('tolimit')) {
  54.             $params->setTolimit($rquery->get('tolimit'));
  55.         }
  56.         if ($rquery->has('evszam')) {
  57.             $params->setEvszam($rquery->get('evszam'));
  58.         }
  59.         if ($rquery->has('sorszam')) {
  60.             $params->setSorszam($rquery->get('sorszam'));
  61.         }
  62.         if ($rquery->has('cim_part')) {
  63.             $params->setCimPart($rquery->get('cim_part'));
  64.         }
  65.         if ($rquery->has('vis')) {
  66.             $params->setVis($rquery->get('vis'));
  67.         }
  68.         if ($rquery->has('kod')) {
  69.             $params->setKod($rquery->get('kod'));
  70.         }
  71.         if (null !== $params->getKod()) {
  72.             $wcount $this->getDoctrine()->getRepository(Wadmin::class)->countOfPubWKodByPja($params);
  73.             $wadmin $this->getDoctrine()->getRepository(Wadmin::class)->getPubWKodByPja($params);
  74.         } else {
  75.             $wcount $this->getDoctrine()->getRepository(Wadmin::class)->countOfPublicatedByPja($params);
  76.             $wadmin $this->getDoctrine()->getRepository(Wadmin::class)->getPublicatedByPja($params);
  77.         }
  78.         $response $this->render('pja/lista.xml.twig', [
  79.             'wcount' => $wcount,
  80.             'wadmin' => $wadmin,
  81.         ]);
  82.         $response->headers->set('Content-Type''text/xml');
  83.         return $response;
  84.     }
  85.     /**
  86.      * @Route("/api/v1/njt/hivatkozasok", defaults={"_format"="xml"}, name="hivatkozasok")
  87.      */
  88.     public function hivatkozasValidator(Request $requestLoggerInterface $logger)
  89.     {
  90.         $content $request->getContent();
  91.         if (strlen($content) == || null === $content) {
  92.             throw $this->createNotFoundException();
  93.         }
  94.         $xml simplexml_load_string($content);
  95.         if (false === $xml) {
  96.             throw $this->createNotFoundException();
  97.         }
  98.         // Egyelőre csak WADMINT ellenőriz.
  99.         $wids = array();
  100.         foreach ($xml->children() as $hiv) {
  101.             if (!in_array((string)($hiv['wAdminId']), $wids)) {
  102.                 $wids[] = (string)($hiv['wAdminId']);
  103.             }
  104.         }
  105.         $result $this->getDoctrine()->getRepository(Wadmin::class)->checkWadminKeys($wids);
  106.         foreach ($xml->children() as $hiv) {
  107.             $logger->debug('XML_ATTR: ' . (string)($hiv['wAdminId']));
  108.             $hiv->addAttribute('valid', (in_array((string)($hiv['wAdminId']), array_column($result'jogszabalyId'))) ? 'true' 'false');
  109.         }
  110.         $strxml $xml->asXML();
  111.         $response = new Response($strxml);
  112.         $response->headers->set('Content-Type''text/xml');
  113.         return $response;
  114.     }
  115.     /**
  116.      * @Route("/restapi/migrate/download/archive/html/{legislationId}/{archiveId}", name="migrate_archive_html", methods={"GET"})
  117.      */
  118.     public function migrateArchiveHtml($legislationId$archiveId): StreamedResponse
  119.     {
  120.         /** @var Valtozat $legislation */
  121.         $legislation $this->getDoctrine()->getRepository(Valtozat::class)->findArchiveVersion($legislationId$archiveId);
  122.         if (null === $legislation) {
  123.             throw $this->createNotFoundException('Nincs ilyen változat!');
  124.         }
  125.         $disposition HeaderUtils::makeDisposition(
  126.             HeaderUtils::DISPOSITION_ATTACHMENT,
  127.             $legislationId '.html'
  128.         );
  129.         $response = new StreamedResponse();
  130.         $response->headers->set('Content-Type''text/html');
  131.         $response->headers->set('Content-Disposition'$disposition);
  132.         $response->setCallback(function () use ($legislation) {
  133.             if (is_resource($legislation->getHtml())) {
  134.                 fpassthru($legislation->getHtml());
  135.             } else {
  136.                 echo $legislation->getHtml();
  137.             }
  138.         });
  139.         return $response->send();
  140.     }
  141.     /**
  142.      * @Route("/restapi/migrate/download/archive/attachments/list/{legislationId}/{archiveId}", name="migrate_archive_attachment_list", methods={"GET"})
  143.      */
  144.     public function migrateArchiveAttachmentsList($legislationId$archiveId): JsonResponse
  145.     {
  146.         /** @var Valtozat $legislation */
  147.         $legislation $this->getDoctrine()->getRepository(Valtozat::class)->findArchiveVersionAttachments($legislationId$archiveId);
  148.         if (null === $legislation) {
  149.             throw $this->createNotFoundException('Legislation not found!');
  150.         }
  151.         $result = new ArchiveLegislation();
  152.         $result->archiveId $archiveId;
  153.         $result->legislationId $legislationId;
  154.         foreach ($legislation->getDocuments() as $document) {
  155.             $attachment = new ArchiveAttachment();
  156.             $attachment->title $document->getTitle();
  157.             $attachment->filename $document->getFilename();
  158.             $attachment->filesize $document->getFilesize();
  159.             $attachment->filehash $document->getFilehash();
  160.             $attachment->downloadID implode('_', array($attachment->filehash$document->getId()));
  161.             $result->attachments[] = $attachment;
  162.         }
  163.         return new JsonResponse($result);
  164.     }
  165. }