src/Controller/MainController.php line 70

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\App\Payments;
  4. use App\Entity\App\Travel;
  5. use App\Entity\App\TravelMembers;
  6. use App\Entity\App\TravelMembersParticipant;
  7. use App\Repository\Tools\AppSettingsRepository;
  8. use App\Repository\Tools\PtoolsRepository;
  9. use App\Services\TpayService;
  10. use App\Entity\App\Users;
  11. use Doctrine\ORM\Query\Expr\Join;
  12. use Symfony\Bundle\FrameworkBundle\Console\Application;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\Console\Input\ArrayInput;
  15. use Symfony\Component\Console\Output\BufferedOutput;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use Symfony\Component\HttpFoundation\RedirectResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\HttpKernel\KernelInterface;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  23. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  24. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  25. use Symfony\Component\Asset\Packages;
  26. use Doctrine\ORM\EntityManagerInterface;
  27. use App\Services\MailerService;
  28. use App\Entity\App\SystemError;
  29. use App\Entity\App\Logs;
  30. class MainController extends AbstractController
  31. {
  32.     private $_AppSettings;
  33.     public function _getAppSettings($apRepository){
  34.         $this->_AppSettings $apRepository->getAppSettings();
  35.     }
  36.     public function __construct(
  37.         AppSettingsRepository  $apRepository,
  38.         EntityManagerInterface $entityManager,
  39.         MailerService          $mailerService,
  40.     ) {
  41.         $this->entityManager $entityManager;
  42.         $this->mailerService $mailerService;
  43.         $this->_getAppSettings($apRepository);
  44.     }
  45.     // TEST
  46.     #[Route('/run-reminder'name'run_reminder'methods: ['GET'])]
  47.     public function runReminderCommand(KernelInterface $kernel): Response
  48.     {
  49.         $application = new Application($kernel);
  50.         $application->setAutoExit(false);
  51.         $input = new ArrayInput(['command' => 'app:reminderOrderPreview']);
  52.         $output = new BufferedOutput();
  53.         $application->run($input$output);
  54.         return new Response('<pre>' $output->fetch() . '</pre>');
  55.     }
  56.     /**
  57.      * @Route("/", name="main")
  58.      */
  59.     public function index(): Response
  60.     {
  61.         $user $this->getUser();
  62.         if(!$user) return $this->redirectToRoute('app_login');
  63.         if(in_array('ROLE_ADMIN',$user->getRoles())){
  64.             return $this->redirectToRoute('web.admin.trip');
  65.         }
  66.         if(in_array('ROLE_EMPLOYEE',$user->getRoles())){
  67.             return $this->redirectToRoute('web.admin.trip');
  68.         }
  69.         if(in_array('ROLE_ACCOUNTANT',$user->getRoles())){
  70.             return $this->redirectToRoute('web.admin.trip');
  71.         }
  72.         if(in_array('ROLE_COORDINATOR',$user->getRoles())){
  73.             return $this->redirectToRoute('web.coordinator.trip.list');
  74.         }
  75.         if(in_array('ROLE_AGENT',$user->getRoles())){
  76.             return $this->redirectToRoute('admin_agent_travel_grid');
  77.         }
  78.     }
  79.     private function create_file_response($filePath){
  80.         if (!is_file($filePath)) {
  81.             return new Response(''Response::HTTP_NOT_FOUND);
  82.         }
  83.         $finfo finfo_open(FILEINFO_MIME_TYPE);
  84.         $mimeType finfo_file($finfo$filePath);
  85.         finfo_close($finfo);
  86.         $response = new BinaryFileResponse($filePath);
  87.         $response->headers->set('Content-Type'$mimeType);
  88.         $response->setContentDisposition(
  89.             ResponseHeaderBag::DISPOSITION_INLINE,
  90.             basename($filePath)
  91.         );
  92.         return $response;
  93.     }
  94.     /**
  95.      * @Route("wycieczka/pobierz/zalacznik-do-umowy/{_travel_focus_id}/{_travel_id}", 
  96.      * name="travel_download_course", 
  97.      * methods={"GET"}, 
  98.      * requirements={"_travel_focus_id"="\d+","_travel_id"="\d+"})
  99.      * @param integer $_travel_focus_id id wycieczki focus    
  100.      * @param integer $_travel_id id wycieczki
  101.      */
  102.     public function travel_download_course(int $_travel_focus_idint $_travel_idPtoolsRepository $ptoolsRepository)
  103.     {
  104.         $data $ptoolsRepository->getTravelFile($_travel_focus_id$_travel_id3);
  105.         if(!empty($data['travel_file_name'])){
  106.             $filePath $this->getParameter('kernel.project_dir').'/public/userfiles/'.$_travel_focus_id.'/'.$data['travel_file_name'];
  107.             return $this->create_file_response($filePath);
  108.         } else {
  109.             return new Response(''Response::HTTP_NOT_FOUND);
  110.         }
  111.     }
  112.     /**
  113.      * @Route("wycieczka/pobierz/program/{_travel_focus_id}/{_travel_id}", 
  114.      * name="travel_download_program", 
  115.      * methods={"GET"}, 
  116.      * requirements={"_travel_focus_id"="\d+","_travel_id"="\d+"})
  117.      * @param integer $_travel_focus_id id wycieczki focus    
  118.      * @param integer $_travel_id id wycieczki
  119.      */
  120.     public function travel_download_program(int $_travel_focus_idint $_travel_idPtoolsRepository $ptoolsRepository)
  121.     {
  122.         $data $ptoolsRepository->getTravelFile($_travel_focus_id$_travel_id2);
  123.         if(!empty($data['travel_file_name'])){
  124.             $filePath $this->getParameter('kernel.project_dir').'/public/userfiles/'.$_travel_focus_id.'/'.$data['travel_file_name'];
  125.             return $this->create_file_response($filePath);
  126.         } else {
  127.             return new Response(''Response::HTTP_NOT_FOUND);
  128.         }
  129.     }
  130.         
  131.     /**
  132.      * @Route("wycieczka/pobierz/zalacznik-do-umowy-dodatkowy/{_travel_focus_id}/{_travel_id}", 
  133.      * name="travel_download_the_annex_to_the_contract", 
  134.      * methods={"GET"}, 
  135.      * requirements={"_travel_focus_id"="\d+","_travel_id"="\d+"})
  136.      * @param integer $_travel_focus_id id wycieczki focus    
  137.      * @param integer $_travel_id id wycieczki
  138.      */
  139.     public function travel_download_the_annex_to_the_contract(int $_travel_focus_idint $_travel_idPtoolsRepository $ptoolsRepository)
  140.     {
  141.         $data $ptoolsRepository->getTravelFile($_travel_focus_id$_travel_id4);
  142.         if(!empty($data['travel_file_name'])){
  143.             $filePath $this->getParameter('kernel.project_dir').'/public/userfiles/'.$_travel_focus_id.'/'.$data['travel_file_name'];
  144.             return $this->create_file_response($filePath);
  145.         } else {
  146.             return new Response(''Response::HTTP_NOT_FOUND);
  147.         }
  148.     }
  149.     
  150.     /**
  151.      * @Route("pobierz/zgoda-marketingowa", 
  152.      * name="public_download_marketing_consent", 
  153.      * methods={"GET"})
  154.      */
  155.     public function public_download_marketing_consent(PtoolsRepository $ptoolsRepository)
  156.     {
  157.         $_data $ptoolsRepository->getAppFile('marketing');
  158.         $filePath $this->getParameter('kernel.project_dir').'/public'.$_data[0]['file_ff'];
  159.         return $this->create_file_response($filePath);
  160.     }
  161.     /**
  162.      * @Route("pobierz/regulamin-serwisu",
  163.      * name="public_download_statute",
  164.      * methods={"GET"})
  165.      */
  166.     public function public_download_statute(PtoolsRepository $ptoolsRepository)
  167.     {
  168.         $_data $ptoolsRepository->getAppFile('statute');
  169.         $filePath $this->getParameter('kernel.project_dir').'/public'.$_data[0]['file_ff'];
  170.         return $this->create_file_response($filePath);
  171.     }
  172.     
  173.     /**
  174.      * @Route("pobierz/warunki-uczestnictwa", 
  175.      * name="public_download_conditions_of_participation", 
  176.      * methods={"GET"})
  177.      */
  178.     public function public_download_conditions_of_participation(PtoolsRepository $ptoolsRepository)
  179.     {
  180.         $_data $ptoolsRepository->getAppFile('warunki');
  181.         $filePath $this->getParameter('kernel.project_dir').'/public'.$_data[0]['file_ff'];
  182.         return $this->create_file_response($filePath);
  183.     }
  184.     
  185.     /**
  186.      * @Route("pobierz/rodo", 
  187.      * name="public_download_rodo", 
  188.      * methods={"GET"})
  189.      */
  190.     public function public_download_rodo(PtoolsRepository $ptoolsRepository)
  191.     {
  192.         $_data $ptoolsRepository->getAppFile('rodo');
  193.         $filePath $this->getParameter('kernel.project_dir').'/public'.$_data[0]['file_ff'];
  194.         return $this->create_file_response($filePath);
  195.     }
  196.     #[Route(
  197.         'manager/{key}/t/{id}/sum-payments',
  198.         name'manager.travel.sumpayments',
  199.         methods: ['GET'],
  200.         requirements: [ "id" => "\d+"]
  201.     )]
  202.     public function managerTravelSumpayments(string $keyint $idPtoolsRepository $ptoolsRepository) {
  203.         if ($key == $_ENV['TRAVEL_CREDITS_CODE']) {
  204.             if ($id 2147483647) return $this->redirectToRoute('app_login', []);
  205.             $result $ptoolsRepository->getManagerSmartTravelData($id);
  206.             return new JsonResponse([
  207.                 'data' => $result,
  208.             ]);
  209.         }
  210.         return $this->redirectToRoute('app_login', []);
  211.     }
  212.     #[Route(
  213.         'test-tpay',
  214.         name'test-tpay',
  215.         methods: ['GET'],
  216.         requirements: [ "id" => "\d+"]
  217.     )]
  218.     public function testTpay(TpayService $tpayService) {
  219.         $test = [
  220.             'travel_member_id' => 987,
  221.             'amount' => 123.45,
  222.             'description' => 'Testowa płatność',
  223.             'continueUrl' => '',
  224.             'email' => 'pawel@travelpay.online',
  225.             'firstName' => 'Jan',
  226.             'lastName' => 'Kowalski',
  227.         ];
  228.         $result $tpayService->createTransaction($test);
  229.         dd($result);
  230.     }
  231. }