src/Controller/WebController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AppSharing;
  4. use App\Entity\Flow;
  5. use App\Entity\Page;
  6. use App\Form\FlowFormType;
  7. use App\Service\AlgorithmService;
  8. use App\Service\FlowService;
  9. use App\Service\PageGeneratorService;
  10. use DeviceDetector\DeviceDetector;
  11. use DeviceDetector\Parser\Client\Browser;
  12. use DeviceDetector\Parser\OperatingSystem;
  13. use Doctrine\Persistence\ManagerRegistry;
  14. use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. use Symfony\Component\HttpKernel\KernelInterface;
  18. use Twig\Environment;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class WebController extends EasyAdminController  {
  21.     public function __construct(ManagerRegistry $managerRegistryPageGeneratorService $pageGeneratorService) {
  22.         $this->doctrine $managerRegistry;
  23.         $this->pageGeneratorService $pageGeneratorService;
  24.     }
  25.     public function index(Request $requestFlowService $flowServiceAlgorithmService $algorithmService )
  26.     {
  27.         $em $this->doctrine->getManager();
  28.         $form $this->createFormFlowFormType::class, null, array('custom'=>) );
  29.         $form->handleRequest$request );
  30.         if ($form->isSubmitted()) {
  31.             $fuuid  $form['fuuid']->getData();
  32.             $query_input_data $request->query->all();
  33.             $post_input_data $request->request->all();
  34.             //$input_data = array('query'=>$query_input_data,'form'=>$post_input_data['flow_form'] );
  35.             $input_data array_merge($post_input_data['flow_form'], $query_input_data);
  36.             $Flow $em->getRepository(Flow::class)->findOneBy(['Fuuid'=>$fuuid]);
  37.             $Flow $flowService->executeFlow($Flow$input_data,'pl');
  38.             return $this->render('website/index.html.twig', [
  39.                 'form' => $form->createView(),
  40.                 'fuuid' => $fuuid,
  41.             ]);
  42.         } else {
  43.             return $this->render('website/index.html.twig', [
  44.                 'form' => $form->createView(),
  45.                 'fuuid'=>null
  46.             ]);
  47.         }
  48.     }
  49.     /**
  50.      * @Route("/r/{appid}/{code}", name="url_redirect")
  51.      */
  52.     public function url_redirect(Request $request$code=''$appid='') {
  53.         $data  $request->query->get'd' );
  54.         $pageid  $request->query->get'pageid' );
  55.         $uri $request->getUri();
  56.         $em $this->doctrine->getManager();
  57.         $AppSharing $em->getRepository(AppSharing::class)->findOneBy(array('Code' => $code));
  58.         $App $AppSharing->getApp();
  59.         if (!empty( $AppSharing)) {
  60.             $showLink $AppSharing->getShowLink();
  61.             $showQr $AppSharing->getShowQr();
  62.             $showAppstores $AppSharing->getShowAppStores();
  63.             $webUrl $AppSharing->getWebUrl();
  64.             $pageId $AppSharing->getPage()->getId();
  65.             $appSettings $AppSharing->getApp()->getSettings();
  66.             $linkCode $AppSharing->getCode();
  67.             $type $AppSharing->getType();
  68.             $redirectMobile $AppSharing->getRedirectMobile();
  69.             $redirectWeb $AppSharing->getRedirectWeb();
  70.             $pages $AppSharing->getPages();
  71.             $childpages = array();
  72.             $clientLocale strtolower(str_split($_SERVER['HTTP_ACCEPT_LANGUAGE'], 2)[0]);
  73.             if ($pageid 0) { // pageid is used in the mobile's page menu to access individual pages of the
  74.                 $Page $em->getRepository(Page::class)->findOneBy(array('id'=>$pageid'App'=>$App));
  75.             }
  76.             foreach ($pages as $page) {
  77.                 $childId $page['Child'];
  78.                 $childPage $em->getRepository(Page::class)->find($childId);
  79.                 $childpages[$childId] = $childPage->translate($clientLocale)->getName();
  80.             }
  81.             if (!empty($Page)) {
  82.                 $pageTitle $Page->translate($clientLocale)->getName();
  83.                 $pageBody $Page->translate($clientLocale)->getBody();
  84.                 return $this->render('website/redirect.html.twig',
  85.                     ['childpages'=>$childpages,'appid'=>$appid'code' => $code'data' => $data'title' => $pageTitle'body' => $pageBody'link' => '''qr' => '''osFamily' => '''browser' => '''showAppstores' => false'urlAppStore' => '''urlGooglePlay' => '''urlHuaweiAppGallery' => '']);
  86.             } else {
  87.                 $userAgent $_SERVER['HTTP_USER_AGENT'];
  88.                 $dd = new DeviceDetector($userAgent);
  89.                 $dd->parse();
  90.                 $osFamily OperatingSystem::getOsFamily($dd->getOs('name'));
  91.                 $browserFamily Browser::getBrowserFamily($dd->getClient('name'));
  92.                 $isSmartphone $dd->isSmartphone();
  93.                 $pageTitle $AppSharing->translate($clientLocale)->getName();
  94.                 $pageBody $AppSharing->translate($clientLocale)->getBody();
  95.                 $urlAppStore = (isset($appSettings['urlAppStore'])) ? $appSettings['urlAppStore'] : '';
  96.                 $urlGooglePlay = (isset($appSettings['urlGooglePlay'])) ? $appSettings['urlGooglePlay'] : '';
  97.                 $urlHuaweiAppGallery = (isset($appSettings['urlHuaweiAppGallery'])) ? $appSettings['urlHuaweiAppGallery'] : '';
  98.                 $link $webUrl '#/page/' $this->pageGeneratorService->buildPageId($pageId11null);
  99.                 if ($type == "db") {
  100.                     $link .= '?c=' $code;
  101.                 } elseif ($type == "qr") {
  102.                     $link .= '?d=' $data;
  103.                 }
  104.                 if (($dd->isSmartphone()) && ($redirectMobile)) {
  105.                     return $this->redirect($link);
  106.                 } elseif ($redirectWeb) {
  107.                     return $this->redirect($link);
  108.                 }
  109.                 if (!$showLink) {
  110.                     $link '';
  111.                 }
  112.                 if (($showQr) && (!$isSmartphone)) {
  113.                     $qr '/qr/' $linkCode '.png';
  114.                 } else {
  115.                     $qr '';
  116.                 }
  117.                 return $this->render('website/redirect.html.twig',
  118.                     ['childpages'=>$childpages,'appid'=>$appid'code' => $code'data' => $data'title' => $pageTitle'body' => $pageBody'link' => $link'qr' => $qr'osFamily' => $osFamily'browser' => $browserFamily'showAppstores' => $showAppstores'urlAppStore' => $urlAppStore'urlGooglePlay' => $urlGooglePlay'urlHuaweiAppGallery' => $urlHuaweiAppGallery]);
  119.             }
  120.         }
  121.         return $this->render('website/redirect.html.twig',
  122.             ['childpages'=>'''appid'=>$appid'code' => '''data' => '''title' => 'redirect_code_not_found_title''body' => 'redirect_code_not_found_full_message''link' => '''qr' => '''osFamily' => '''browser' => '''showAppstores' =>false'urlAppStore' => '''urlGooglePlay' => '''urlHuaweiAppGallery' => '']);
  123.     }
  124. }