<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\DBAL\Connection;
use App\Service\contentservice;
use JasperPHP\JasperPHP;
use App\Service\generalservice;
class ContentController extends AbstractController
{
/**
* @var contentservice
*/
/**
* @var generalservice
*/
private $apiContent;
private $apiGeneral;
public function __construct(contentservice $contentservice, generalservice $generalservice)
{
$this->apiContent = $contentservice;
$this->apiGeneral = $generalservice;
}
/**
* @Route("/content", name="content")
*/
public function index(): Response
{
//index
//se en komentar
//in se eden
$this->denyAccessUnlessGranted('ROLE_USER');
$lUser = $this->getUser();
$lUserID = $lUser->getId();
$lUserCompany = $lUser->getCompany();
$lModul = explode(",",$lUser->getModul());
if (!in_array("Content", $lModul))
{
return $this->redirectToRoute('app_homepage');
}
$lContent = $this->apiContent->getAllContent(1,$lUserCompany);
$lResponseContent = new JsonResponse(array('data' => $lContent));
file_put_contents('api/dataContents_'.$lUserCompany.'.json', $lResponseContent->getContent());
return $this->render('content/content.html.twig', [
'controller_name' => 'ContentController',
'company' => $lUserCompany
]);
}
/**
* @Route("/", name="home")
*/
public function home()
{
//index
//se en komentar
//in se eden
$this->denyAccessUnlessGranted('ROLE_USER');
return $this->redirectToRoute('content');
}
/**
* @Route("/content/refreshcontents", name="content_refreshcontents")
*/
public function contentRefreshContents(Request $request)
{
$lUser = $this->getUser();
$lUserID = $lUser->getId();
$lUserCompany = $lUser->getCompany();
$ltab = $_POST['tab'];
if ($ltab ==3)
{
$ltab = 4;
}
file_put_contents("CONTROLER.log", $ltab);
if ($ltab == 1)
{
$lContent = $this->apiContent->getAllContent(1,$lUserCompany);
$lResponseContent = new JsonResponse(array('data' => $lContent));
file_put_contents('api/dataContents_'.$lUserCompany.'.json', $lResponseContent->getContent());
}
elseif ($ltab == 2)
{
$lContent = $this->apiContent->getAllContent(2,$lUserCompany);
$lResponseContent = new JsonResponse(array('data' => $lContent));
file_put_contents('api/dataNews_'.$lUserCompany.'.json', $lResponseContent->getContent());
}
elseif ($ltab == 3)
{
$lContent = $this->apiContent->getAllContent(3,$lUserCompany);
$lResponseContent = new JsonResponse(array('data' => $lContent));
file_put_contents('api/dataProducts_'.$lUserCompany.'.json', $lResponseContent->getContent());
}
elseif ($ltab == 4)
{
$lContent = $this->apiContent->getAllContent(4,$lUserCompany);
$lResponseContent = new JsonResponse(array('data' => $lContent));
file_put_contents('api/dataEvents_'.$lUserCompany.'.json', $lResponseContent->getContent());
}
return new JsonResponse(array('data' => "ok"));
}
/**
* @Route("/content/addcontent", name="content_addcontent")
*/
public function contentAddContent(Request $request)
{
$lUser = $this->getUser();
$lUserID = $lUser->getId();
$lUserCompany = $lUser->getCompany();
$ltab = $_POST['tab'];
$lengine_id = 0;
if ($ltab == 1)
{
$lengine_id = 1;
}
else if ($ltab == 2)
{
$lengine_id = 2;
}
else if ($ltab == 3)
{
$lengine_id = 4;
}
else if ($ltab == 4)
{
$lengine_id = 3;
}
$this->apiContent->user_id = $lUserID;
$this->apiContent->engine_id = $lengine_id;
$this->apiContent->company_id = $lUserCompany;
$lcontent_id = $this->apiContent->addContent();
$this->apiContent->content_id = $lcontent_id;
$lForm = $this->apiContent->createForm();
$this->apiGeneral->ClearLog();
$this->apiGeneral->content_id = $lcontent_id;
$this->apiGeneral->action_id = 1;
$this->apiGeneral->log_description = "";
$this->apiGeneral->user_id = $lUserID;
$this->apiGeneral->AddLog();
return new JsonResponse(array('data' => $lcontent_id));
}
/**
* @Route("/content/deletcontent", name="content_deletecontent")
*/
public function contentDeleteContent(Request $request, Connection $connection)
{
$lUser = $this->getUser();
$lUserID = $lUser->getId();
$lcontent_id = $_POST['content_id'];
$this->apiContent->content_id = $lcontent_id;
$lok = $this->apiContent->deleteContent();
$this->apiGeneral->ClearLog();
$this->apiGeneral->content_id = $lcontent_id;
$this->apiGeneral->action_id = 2;
$this->apiGeneral->log_description = "";
$this->apiGeneral->user_id = $lUserID;
$this->apiGeneral->AddLog();
return new JsonResponse($lok);
}
}