src/Controller/DefaultController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. class DefaultController extends AbstractController
  7. {
  8.     /**
  9.      * @Route("/", name="main")
  10.      */
  11.     public function main()
  12.     {
  13.         return $this->render('page.html.twig', [
  14.         ]);
  15.     }
  16.     /**
  17.      * @Route("/search", name="search")
  18.      */
  19.     public function search()
  20.     {
  21.         return $this->render('search.html.twig', [
  22.         ]);
  23.     }
  24.     /**
  25.      * @Route("/share", name="share")
  26.      */
  27.     public function share()
  28.     {
  29.         $data $_POST['data'];
  30.         $decodedData file_get_contents($data['png']);
  31.         file_put_contents("/var/www/smartfiles/public/sharedata/".$data['md'].'.png',$decodedData);
  32.         $pdf file_get_contents('https://tool.lereto.at/sf/'.$data['md'].".pdf");
  33.         file_put_contents("/var/www/smartfiles/public/sharedata/".$data['md'].'.pdf',$pdf);
  34.         die("OK");
  35.     }
  36.     /**
  37.      * @Route("/shares/{shareid}", name="shares")
  38.      */
  39.     public function shares($shareid)
  40.     {
  41.         return $this->render('shares.html.twig', [
  42.             'shareid' => $shareid
  43.         ]);
  44.     }
  45.     /**
  46.      * @Route("/subjects", name="subjects")
  47.      */
  48.     public function subjects()
  49.     {
  50.         $conn $this->getDoctrine()->getEntityManager()
  51.             ->getConnection();
  52.         $sql 'select * from eurlex_metadata where eurlex_metadata.celex in (SELECT celexNumber FROM eurlex where eurlex.id in (:nodeids)) and metadata_name = :val';
  53.         $stmt $conn->prepare($sql);
  54.         $stmt->execute(array("val"=>array("Subject matter"),"nodeids"=>$_POST['data']),array(\Doctrine\DBAL\Connection::PARAM_STR_ARRAY,\Doctrine\DBAL\Connection::PARAM_STR_ARRAY));
  55.         $data $stmt->fetchAll();
  56.         return new JsonResponse($data);
  57.     }
  58.     /**
  59.      * @Route("/metadata/{nodeid}", name="metadata")
  60.      */
  61.     public function metadata($nodeid)
  62.     {
  63.         header('Content-Type: application/json');
  64.         $conn $this->getDoctrine()->getEntityManager()
  65.             ->getConnection();
  66.         $sql 'SELECT * FROM eurlex where id = :nodeid';
  67.         $stmt $conn->prepare($sql);
  68.         $stmt->execute(array("nodeid"=>$nodeid));
  69.         $data $stmt->fetchAll();
  70.         $celex $data[0]["celexNumber"];
  71.         $sql 'SELECT * FROM eurlex_metadata where celex = :celex';
  72.         $stmt $conn->prepare($sql);
  73.         $stmt->execute(array("celex"=>$celex));
  74.         $data2 $stmt->fetchAll();
  75.         $data[0]["meta"] = array();
  76.         foreach($data2 as $k => $v)
  77.         {
  78.             $data[0]["meta"][str_replace(" ","",strtolower$v["metadata_name"])) ] = $v["metadata_value"];
  79.         }
  80.         die(json_encode($data));
  81.     }
  82. }