<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="main")
*/
public function main()
{
return $this->render('page.html.twig', [
]);
}
/**
* @Route("/search", name="search")
*/
public function search()
{
return $this->render('search.html.twig', [
]);
}
/**
* @Route("/share", name="share")
*/
public function share()
{
$data = $_POST['data'];
$decodedData = file_get_contents($data['png']);
file_put_contents("/var/www/smartfiles/public/sharedata/".$data['md'].'.png',$decodedData);
$pdf = file_get_contents('https://tool.lereto.at/sf/'.$data['md'].".pdf");
file_put_contents("/var/www/smartfiles/public/sharedata/".$data['md'].'.pdf',$pdf);
die("OK");
}
/**
* @Route("/shares/{shareid}", name="shares")
*/
public function shares($shareid)
{
return $this->render('shares.html.twig', [
'shareid' => $shareid
]);
}
/**
* @Route("/subjects", name="subjects")
*/
public function subjects()
{
$conn = $this->getDoctrine()->getEntityManager()
->getConnection();
$sql = 'select * from eurlex_metadata where eurlex_metadata.celex in (SELECT celexNumber FROM eurlex where eurlex.id in (:nodeids)) and metadata_name = :val';
$stmt = $conn->prepare($sql);
$stmt->execute(array("val"=>array("Subject matter"),"nodeids"=>$_POST['data']),array(\Doctrine\DBAL\Connection::PARAM_STR_ARRAY,\Doctrine\DBAL\Connection::PARAM_STR_ARRAY));
$data = $stmt->fetchAll();
return new JsonResponse($data);
}
/**
* @Route("/metadata/{nodeid}", name="metadata")
*/
public function metadata($nodeid)
{
header('Content-Type: application/json');
$conn = $this->getDoctrine()->getEntityManager()
->getConnection();
$sql = 'SELECT * FROM eurlex where id = :nodeid';
$stmt = $conn->prepare($sql);
$stmt->execute(array("nodeid"=>$nodeid));
$data = $stmt->fetchAll();
$celex = $data[0]["celexNumber"];
$sql = 'SELECT * FROM eurlex_metadata where celex = :celex';
$stmt = $conn->prepare($sql);
$stmt->execute(array("celex"=>$celex));
$data2 = $stmt->fetchAll();
$data[0]["meta"] = array();
foreach($data2 as $k => $v)
{
$data[0]["meta"][str_replace(" ","",strtolower( $v["metadata_name"])) ] = $v["metadata_value"];
}
die(json_encode($data));
}
}