src/Controller/ContentController.php line 73

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\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Doctrine\DBAL\Connection;
  9. use App\Service\contentservice;
  10. use JasperPHP\JasperPHP;
  11. use App\Service\generalservice;
  12. class ContentController extends AbstractController
  13. {
  14.     /**
  15.     * @var contentservice
  16.     */
  17.     /**
  18.     * @var generalservice
  19.     */
  20.     private $apiContent;
  21.     private $apiGeneral;
  22.   
  23.     public function __construct(contentservice $contentservicegeneralservice $generalservice)
  24.     {
  25.         $this->apiContent $contentservice;
  26.         $this->apiGeneral $generalservice;
  27.     }
  28.     /**
  29.      * @Route("/content", name="content")
  30.      */
  31.     public function index(): Response
  32.     {
  33.         //index
  34.         //se en komentar
  35.         //in se eden
  36.         $this->denyAccessUnlessGranted('ROLE_USER');
  37.         $lUser $this->getUser();
  38.         $lUserID $lUser->getId();
  39.         $lUserCompany $lUser->getCompany();
  40.         $lModul explode(",",$lUser->getModul());
  41.         if (!in_array("Content"$lModul))
  42.         {
  43.             return $this->redirectToRoute('app_homepage');
  44.         }
  45.         $lContent $this->apiContent->getAllContent(1,$lUserCompany);
  46.         $lResponseContent = new JsonResponse(array('data' => $lContent));
  47.         file_put_contents('api/dataContents_'.$lUserCompany.'.json'$lResponseContent->getContent());
  48.         return $this->render('content/content.html.twig', [
  49.             'controller_name' => 'ContentController',
  50.             'company' => $lUserCompany
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/", name="home")
  55.      */
  56.     public function home()
  57.     {
  58.         //index
  59.         //se en komentar
  60.         //in se eden
  61.         $this->denyAccessUnlessGranted('ROLE_USER');
  62.         return $this->redirectToRoute('content');
  63.     }
  64.     /**
  65.      * @Route("/content/refreshcontents", name="content_refreshcontents")
  66.      */
  67.     public function contentRefreshContents(Request $request)
  68.     {        
  69.         
  70.         
  71.         $lUser $this->getUser();
  72.         $lUserID $lUser->getId();
  73.         $lUserCompany $lUser->getCompany();
  74.         $ltab $_POST['tab'];
  75.         if ($ltab ==3)
  76.         {
  77.             $ltab 4;
  78.         }
  79.         file_put_contents("CONTROLER.log"$ltab);
  80.         if ($ltab == 1)
  81.         {
  82.             $lContent $this->apiContent->getAllContent(1,$lUserCompany);
  83.             $lResponseContent = new JsonResponse(array('data' => $lContent));
  84.             file_put_contents('api/dataContents_'.$lUserCompany.'.json'$lResponseContent->getContent());
  85.         }
  86.         elseif ($ltab == 2)
  87.         {
  88.             $lContent $this->apiContent->getAllContent(2,$lUserCompany);
  89.             $lResponseContent = new JsonResponse(array('data' => $lContent));
  90.             file_put_contents('api/dataNews_'.$lUserCompany.'.json'$lResponseContent->getContent());
  91.         }
  92.         elseif ($ltab == 3)
  93.         {
  94.             $lContent $this->apiContent->getAllContent(3,$lUserCompany);
  95.             $lResponseContent = new JsonResponse(array('data' => $lContent));
  96.             file_put_contents('api/dataProducts_'.$lUserCompany.'.json'$lResponseContent->getContent());
  97.         }
  98.         elseif ($ltab == 4)
  99.         {
  100.             $lContent $this->apiContent->getAllContent(4,$lUserCompany);
  101.             $lResponseContent = new JsonResponse(array('data' => $lContent));
  102.             file_put_contents('api/dataEvents_'.$lUserCompany.'.json'$lResponseContent->getContent());
  103.         }
  104.         return new JsonResponse(array('data' => "ok"));
  105.     }
  106.     /**
  107.      * @Route("/content/addcontent", name="content_addcontent")
  108.      */
  109.     public function contentAddContent(Request $request)
  110.     {        
  111.         $lUser $this->getUser();
  112.         $lUserID $lUser->getId();
  113.         $lUserCompany $lUser->getCompany();
  114.         $ltab $_POST['tab'];
  115.         $lengine_id 0;
  116.         if ($ltab == 1)
  117.         {
  118.             $lengine_id 1;
  119.         }
  120.         else if ($ltab == 2)
  121.         {
  122.             $lengine_id 2;
  123.         }
  124.         else if ($ltab == 3)
  125.         {
  126.             $lengine_id 4;
  127.         }
  128.         else if ($ltab == 4)
  129.         {
  130.             $lengine_id 3;
  131.         }
  132.         $this->apiContent->user_id $lUserID;
  133.         $this->apiContent->engine_id $lengine_id;
  134.         $this->apiContent->company_id $lUserCompany;
  135.         
  136.         $lcontent_id $this->apiContent->addContent();
  137.         $this->apiContent->content_id $lcontent_id;
  138.         $lForm $this->apiContent->createForm();
  139.         $this->apiGeneral->ClearLog();
  140.         $this->apiGeneral->content_id $lcontent_id;
  141.         $this->apiGeneral->action_id 1;
  142.         $this->apiGeneral->log_description "";
  143.         $this->apiGeneral->user_id $lUserID;
  144.         $this->apiGeneral->AddLog();
  145.         return new JsonResponse(array('data' => $lcontent_id));
  146.     }
  147.     /**
  148.     * @Route("/content/deletcontent", name="content_deletecontent")
  149.     */
  150.     public function contentDeleteContent(Request $requestConnection $connection)
  151.     {
  152.         $lUser $this->getUser();
  153.         $lUserID $lUser->getId();
  154.         
  155.         $lcontent_id $_POST['content_id'];
  156.         $this->apiContent->content_id $lcontent_id;
  157.         $lok $this->apiContent->deleteContent();
  158.         $this->apiGeneral->ClearLog();
  159.         $this->apiGeneral->content_id $lcontent_id;
  160.         $this->apiGeneral->action_id 2;
  161.         $this->apiGeneral->log_description "";
  162.         $this->apiGeneral->user_id $lUserID;
  163.         $this->apiGeneral->AddLog();
  164.         
  165.         return new JsonResponse($lok);
  166.     }
  167. }