src/Controller/PageController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\Api\ApiService;
  4. use App\Services\SystemPageResources;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use Symfony\Component\Filesystem\Filesystem;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class PageController extends AbstractController
  15. {
  16.     private $router;
  17.     private $parameterBag;
  18.     public function __construct(UrlGeneratorInterface $routerParameterBagInterface $parameterBag)
  19.     {
  20.         $this->router $router;
  21.         $this->parameterBag $parameterBag;
  22.     }
  23.     /**
  24.      * @Route("/", name="homepage" )
  25.      */
  26.     public function homepage(Request $request,  SessionInterface $session)
  27.     {
  28.         if ( !$this->getUser() || $request->getLocale() === "login"){ return $this->redirect('/app/login'); }
  29.         return $this->redirect("/".$this->getParameter("app.default_locale"), 301);
  30.     }
  31.     /**
  32.      * @Route("/{_locale}", name="homepage_localized")
  33.      */
  34.     public function startPage(Request $request) {
  35.         if ( !$this->getUser() || $request->getLocale() === "app"){ return $this->redirect('/app/login'); }
  36.         if (in_array($request->getLocale(),$this->getParameter('app.supported_locales') ) === false)
  37.         {
  38.             return $this->redirect($this->getParameter("app.default_locale"));
  39.         }
  40.         $em $this->getDoctrine()->getManager();
  41.         $pageResources = new SystemPageResources($em);
  42.         $ajaxRequest $request->request->get("ajaxRequest");
  43.         $pageData = [];
  44.         $pageData['data'] = json_decode($pageResources->getResources($request), true);
  45.         if (!$ajaxRequest) {
  46.             $data = [
  47.                 "leftsideMenu" => $this->get('twig')->render("/_pages/partials/leftsideMenu.html.twig"$pageData),
  48.                 "header" => $this->get('twig')->render("/_pages/partials/baseHeader.html.twig"$pageData),
  49.                 "footer" => $this->get('twig')->render("/_pages/partials/baseFooter.html.twig"$pageData)
  50.             ];
  51.             $pageData['html'] = $data;
  52.             return $this->render("/_pages/homepage.html.twig"$pageData);
  53.         } else {
  54.             $data = [
  55.                 "pageTitle" => "xPerto_PLATE",
  56.                 "pageBody" => $this->get('twig')->render("/_bodies/homepage.html.twig"$pageData)
  57.             ];
  58.             $pageData['html'] = $data;
  59.             return new JsonResponse($pageData);
  60.         }
  61.     }
  62.     /**
  63.      * @Route("/analytics/{locale}/{area}", name="area_analytics")
  64.      */
  65.     public function analytics(Request $request$locale$area) {
  66.         if ( !$this->getUser() || $locale === "login"){ return $this->redirect('/app/login'); }
  67.         if ( in_array($locale$this->getParameter('localeSet')) === false  ) {
  68.             return $this->redirect$this->get('router')->generate($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), ['locale' => $this->getParameter('appDefaultLocale')]), ['force_canonical'=>true], 301));
  69.         }
  70.         $em $this->getDoctrine()->getManager();
  71.         $pageResources = new SystemPageResources($em);
  72.         $api = new ApiService($em);
  73.         $ajaxRequest $request->request->get("ajaxRequest");
  74.         $pageData = [];
  75.         $pageData['data'] = json_decode($pageResources->getResources($request$locale), true);
  76.         $pageScripts $this->get('twig')->render("/appArea_analytics/scripts/analytics.html.twig");
  77.         switch ($area) {
  78.             case "developmentBonus":
  79.                 $periodsData json_decode($api->endpointDirect('analytics/getDevelopmentBonusPeriods', ["locale"=>"pl"]), true);
  80.                 $pageData['developmentBonusPeriods'] = $periodsData['periods'];
  81.                 $pageData['developmentBonusPartners'] = $periodsData['partners'];
  82.                 $pageScripts $this->get('twig')->render("/appArea_analytics/scripts/analytics.html.twig");
  83.                 break;
  84.         }
  85.         if (!$ajaxRequest) {
  86.             $data = [
  87.                 "leftsideMenu" => $this->get('twig')->render("/_pages/partials/leftsideMenu.html.twig"$pageData),
  88.                 "header" => $this->get('twig')->render("/_pages/partials/baseHeader.html.twig"$pageData),
  89.                 "footer" => $this->get('twig')->render("/_pages/partials/baseFooter.html.twig"$pageData),
  90.             ];
  91.             $pageData['html'] = $data;
  92.             return $this->render("/appArea_analytics/pages/".$area.".html.twig"$pageData);
  93.         } else {
  94.             $data = [
  95.                 "pageTitle" => "xPerto_PLATE",
  96.                 "pageBody" => $this->get('twig')->render("/appArea_analytics/bodies/".$area.".html.twig"$pageData),
  97.                 "pageScripts" => $pageScripts
  98.             ];
  99.             $pageData['html'] = $data;
  100.             return new JsonResponse($pageData);
  101.         }
  102.     }
  103.     /**
  104.      * @Route("/customer-service/{locale}/{area}", name="area_customer-service")
  105.      */
  106.     public function customerService(Request $request$locale$area) {
  107.         if ( !$this->getUser() || $locale === "login"){ return $this->redirect('/app/login'); }
  108.         if ( in_array($locale$this->getParameter('localeSet')) === false  ) {
  109.              return $this->redirect$this->get('router')->generate($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), ['locale' => $this->getParameter('appDefaultLocale')]), ['force_canonical'=>true], 301));
  110.         }
  111.         $em $this->getDoctrine()->getManager();
  112.         $pageResources = new SystemPageResources($em);
  113.         $ajaxRequest $request->request->get("ajaxRequest");
  114.         $pageData = [];
  115.         $pageData['data'] = json_decode($pageResources->getResources($request$locale), true);
  116.         if (!$ajaxRequest) {
  117.             $data = [
  118.                 "leftsideMenu" => $this->get('twig')->render("/_pages/partials/leftsideMenu.html.twig"$pageData),
  119.                 "header" => $this->get('twig')->render("/_pages/partials/baseHeader.html.twig"$pageData),
  120.                 "footer" => $this->get('twig')->render("/_pages/partials/baseFooter.html.twig"$pageData),
  121.                 "pageScripts" => $this->get('twig')->render("/appArea_customer_service/scripts/customerService.html.twig")
  122.             ];
  123.             $pageData['html'] = $data;
  124.             return $this->render("/appArea_customer_service/pages/".$area.".html.twig"$pageData);
  125.         } else {
  126.             $data = [
  127.                 "pageTitle" => "xPerto_PLATE",
  128.                 "pageBody" => $this->get('twig')->render("/appArea_customer_service/bodies/".$area.".html.twig"$pageData),
  129.                 "pageScripts" => $this->get('twig')->render("/appArea_customer_service/scripts/customerService.html.twig")
  130.             ];
  131.             $pageData['html'] = $data;
  132.             return new JsonResponse($pageData);
  133.         }
  134.     }
  135.     /**
  136.      * @Route("/sandbox/{locale}/{area}", name="area_sandbox")
  137.      */
  138.     public function sandbox(Request $request$locale$area) {
  139.         if ( !$this->getUser() || $locale === "login"){ return $this->redirect('/app/login'); }
  140.         if ( in_array($locale$this->getParameter('localeSet')) === false  ) {
  141.             return $this->redirect$this->get('router')->generate($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), ['locale' => $this->getParameter('appDefaultLocale')]), ['force_canonical'=>true], 301));
  142.         }
  143.         $em $this->getDoctrine()->getManager();
  144.         $pageResources = new SystemPageResources($em);
  145.         $ajaxRequest $request->request->get("ajaxRequest");
  146.         $pageData = [];
  147.         $pageData['data'] = json_decode($pageResources->getResources($request$locale), true);
  148.         if (!$ajaxRequest) {
  149.             $data = [
  150.                 "leftsideMenu" => $this->get('twig')->render("/_pages/partials/leftsideMenu.html.twig"$pageData),
  151.                 "header" => $this->get('twig')->render("/_pages/partials/baseHeader.html.twig"$pageData),
  152.                 "footer" => $this->get('twig')->render("/_pages/partials/baseFooter.html.twig"$pageData),
  153.                 "pageScripts" => $this->get('twig')->render("/appArea_sandbox/scripts/sandbox.html.twig")
  154.             ];
  155.             $pageData['html'] = $data;
  156.             return $this->render("/appArea_sandbox/pages/".$area.".html.twig"$pageData);
  157.         } else {
  158.             $data = [
  159.                 "pageTitle" => "xPerto_PLATE",
  160.                 "pageBody" => $this->get('twig')->render("/appArea_sandbox/bodies/".$area.".html.twig"$pageData),
  161.                 "pageScripts" => $this->get('twig')->render("/appArea_sandbox/scripts/sandbox.html.twig")
  162.             ];
  163.             $pageData['html'] = $data;
  164.             return new JsonResponse($pageData);
  165.         }
  166.     }
  167.     /**
  168.      * @Route("/reports/{locale}/{area}", name="area_reports")
  169.      */
  170.     public function reports(Request $request$locale$area) {
  171.         if ( !$this->getUser() || $locale === "login"){ return $this->redirect('/app/login'); }
  172.         if ( in_array($locale$this->getParameter('localeSet')) === false  ) {
  173.             return $this->redirect$this->get('router')->generate($request->attributes->get('_route'), array_merge($request->attributes->get('_route_params'), ['locale' => $this->getParameter('appDefaultLocale')]), ['force_canonical'=>true], 301));
  174.         }
  175.         $em $this->getDoctrine()->getManager();
  176.         $pageResources = new SystemPageResources($em);
  177.         $filesystem = new Filesystem();
  178.         $ajaxRequest $request->request->get("ajaxRequest");
  179.         $pageData = [];
  180.         $pageData['data'] = json_decode($pageResources->getResources($request$locale), true);
  181.         switch($area) {
  182.             case "dashboard":
  183.                 break;
  184.             case "sales-overal;":
  185.                 break;
  186.             case "report_salesByItems":
  187.                 $api = new ApiService($em);
  188.                 $pageData['assortment'] = json_decode($api->getApiServiceData('getAssortment', ["activeOnly"=>false"locale"=>"pl"]), true);
  189.                 break;
  190.         }
  191.         if (!$ajaxRequest) {
  192.             $data = [
  193.                 "leftsideMenu" => $this->get('twig')->render("/_pages/partials/leftsideMenu.html.twig"$pageData),
  194.                 "header" => $this->get('twig')->render("/_pages/partials/baseHeader.html.twig"$pageData),
  195.                 "footer" => $this->get('twig')->render("/_pages/partials/baseFooter.html.twig"$pageData),
  196.                 "pageScripts" => $this->get('twig')->render("/appArea_reports/scripts/reports.html.twig")
  197.             ];
  198.             $pageData['html'] = $data;
  199.             return $this->render("/appArea_reports/pages/".$area.".html.twig"$pageData);
  200.         } else {
  201.             $data = [
  202.                 "pageTitle" => "xPerto_PLATE",
  203.                 "pageBody" => $this->get('twig')->render("/appArea_reports/bodies/".$area.".html.twig"$pageData),
  204.                 "pageScripts" => $this->get('twig')->render("/appArea_reports/scripts/reports.html.twig")
  205.             ];
  206.             $pageData['html'] = $data;
  207.             return new JsonResponse($pageData);
  208.         }
  209.     }
  210.     /**
  211.      * @Route("/offline.html", name="offline")
  212.      */
  213.     public function offline(Request $request) {
  214.         return $this->render("/_pages/offline.html.twig");
  215.     }
  216.     /**
  217.      * @Route("/app/login", name="login")
  218.      */
  219.     public function login(Request $requestTranslatorInterface $translator) {
  220.         if ( $this->getUser() ){ return $this->redirect('/'); }
  221.         return $this->render("/_pages/login.html.twig", ['locale'=>'pl'] );
  222.     }
  223. }