src/Controller/MainController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Entity\Office;
  5. use App\Entity\Organization;
  6. use App\Entity\Objective;
  7. use App\Entity\Appraisal;
  8. use App\Entity\Notification;
  9. use App\Entity\AppraisalQuestionnaire;
  10. use App\Entity\Certification;
  11. use App\Entity\FlexiWorkArrangementRequest;
  12. use App\Form\ObjectiveType;
  13. use App\Form\CVType;
  14. use App\Form\CertificationType;
  15. use App\Form\AppraisalRequestType;
  16. use App\Form\FlexiWorkArrangementRequestType;
  17. use App\Form\FlexiWorkArrangementSigningType;
  18. use App\Repository\UserRepository;
  19. use App\Service\NotificationService;
  20. use App\Service\UtilsService;
  21. use App\Service\MailgunService;
  22. use App\Service\UploadService;
  23. use Doctrine\ORM\EntityManagerInterface;
  24. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  25. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  26. use Symfony\Component\Form\Extension\Core\Type\FileType;
  27. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  28. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  29. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\HttpFoundation\Response;
  33. use Symfony\Component\HttpFoundation\JsonResponse;
  34. use Symfony\Component\Yaml\Yaml;
  35. use Symfony\Contracts\Translation\TranslatorInterface;
  36. class MainController extends AbstractController
  37. {
  38.     private $entityManager;
  39.     public function __construct(EntityManagerInterface $entityManager)
  40.     {
  41.         $this->entityManager $entityManager;
  42.     }
  43.     #[Route(path'/'name'index')]
  44.     public function index(EntityManagerInterface $entityManager): \Symfony\Component\HttpFoundation\Response
  45.     {
  46.         $user $this->getUser();
  47.         //$notification->check($user);
  48.         $emailForm $this->createFormBuilder()
  49.             ->add('email'HiddenType::class, [
  50.                 'required' => true,
  51.             ])->add('subject'HiddenType::class, [
  52.                 'required' => true,
  53.             ])->add('message'TextareaType::class, [
  54.                 'required' => true,
  55.                 'attr' => array('rows' => 12),
  56.                 'label' => 'Message',
  57.             ])->add('anonymous'HiddenType::class, [
  58.                 'required' => true,
  59.             /*])->add('attachment', FileType::class, [
  60.                 'required' => false,
  61.                 'mapped' => false,
  62.                 'attr' => array('maxlength' => 255),*/
  63.             ])->add('submit'SubmitType::class, array('label' => 'form.send'))
  64.             ->getForm();
  65.         return $this->render('private/dashboard.html.twig', [
  66.             'offices' => $user->assignedCompany()->getOffices(),
  67.             'emailForm' => $emailForm->createView()
  68.         ]);
  69.         //return $this->redirectToRoute('index');
  70.     }
  71.     #[Route(path'/404'name'error_404')]
  72.     public function error_404(NotificationService $notification): \Symfony\Component\HttpFoundation\Response
  73.     {
  74.         $user $this->getUser();
  75.         //$notification->check($user);
  76.         return $this->render('private/dashboard.html.twig', [
  77.             'offices' => $user->assignedCompany()->getOffices()
  78.         ]);
  79.         //return $this->redirectToRoute('index');
  80.     }
  81.     #[Route(path'/assets/translation.js'name'js_translations')]
  82.     public function jsTranslations(Request $request)
  83.     {
  84.         $locale $request->getLocale();
  85.         $file   $this->getParameter('root') . '/translations/messages.' $locale '.yaml';
  86.         $parsed Yaml::parse(file_get_contents($file));
  87.         $translations $this->renderView(
  88.             'assets/translations.js.twig',
  89.             array(
  90.                 'json' => json_encode($parsed)
  91.             )
  92.         );
  93.         return new Response(
  94.             $translations,
  95.             \Symfony\Component\HttpFoundation\Response::HTTP_OK,
  96.             array('Content-Type' => 'text/javascript')
  97.         );
  98.     }
  99.     #[Route(path'/team'name'team')]
  100.     function team(): \Symfony\Component\HttpFoundation\Response
  101.     {
  102.         $user $this->getUser();
  103.         return $this->render('private/team/overview.html.twig', [
  104.             'offices' => $user->assignedCompany()->getOffices()
  105.         ]);
  106.     }
  107.     #[Route(path'/qna'name'qna')]
  108.     function qna(): \Symfony\Component\HttpFoundation\Response
  109.     {
  110.         $user $this->getUser();
  111.         return $this->render('private/team/overview.html.twig', [
  112.             'offices' => $user->assignedCompany()->getOffices()
  113.         ]);
  114.     }
  115.     #[Route(path'/manager'name'manager')]
  116.     function manager(): \Symfony\Component\HttpFoundation\Response
  117.     {
  118.         $user $this->getUser();
  119.         $fwa = new FlexiWorkArrangementRequest();
  120.         $formFWA $this->createForm(FlexiWorkArrangementRequestType::class, $fwa, [
  121.             'action' => $this->generateUrl('request_fwa')
  122.         ]);
  123.         $formFWA $formFWA->createView();
  124.         $formSignFWA $this->createForm(FlexiWorkArrangementSigningType::class, $fwa, [
  125.             'action' => $this->generateUrl('sign_fwa')
  126.         ]);
  127.         $formSignFWA $formSignFWA->createView();
  128.         
  129.         return $this->render('private/manager/overview.html.twig', [
  130.             'subordinates' => $user->getSubordinates(),
  131.             'formSignFWA' => isset($formSignFWA) ? $formSignFWA false,
  132.         ]);
  133.     }
  134.     #[Route(path'/settings/fwa'name'fwa_settings')]
  135.     function settingsFWA(): \Symfony\Component\HttpFoundation\Response
  136.     {
  137.         $user $this->getUser();
  138.         $fwa = new FlexiWorkArrangementRequest();
  139.         $formFWA $this->createForm(FlexiWorkArrangementRequestType::class, $fwa, [
  140.             'action' => $this->generateUrl('request_fwa')
  141.         ]);
  142.         $formFWA $formFWA->createView();
  143.         $formSignFWA $this->createForm(FlexiWorkArrangementSigningType::class, $fwa, [
  144.             'action' => $this->generateUrl('sign_fwa')
  145.         ]);
  146.         $formSignFWA $formSignFWA->createView();
  147.         $subordinates '';
  148.         if($this->isGranted('ROLE_HR')){
  149.             $subordinates $user->assignedCompany()->getAllUser();
  150.         }else{
  151.             $subordinates $user->getSubordinates();
  152.         }
  153.         // $subordinates = $user->getSubordinates();
  154.         return $this->render('private/fwa/overview.html.twig', [
  155.             'subordinates' => $subordinates,
  156.             // 'subordinates' => $user->getSubordinates(),
  157.             'formSignFWA' => isset($formSignFWA) ? $formSignFWA false,
  158.         ]);
  159.     }
  160.     #[Route(path'/profile/{_id}'defaults: ['_id' => 'default'], name'user_profile')]
  161.     public function userProfile(string $_idTranslatorInterface $translatorRequest $request)
  162.     {
  163.         $user $this->getUser();
  164.         $objective = new Objective();
  165.         $appraisal = new Appraisal();
  166.         $appraisalQuestionnaire = new AppraisalQuestionnaire();
  167.         $certification = new Certification();
  168.         if ($_id == "default") {
  169.             $userData =  $user;
  170.         } else if (is_numeric($_id)) {
  171.             $userData =  $this->getDoctrine()->getRepository(User::class)->find($_id);
  172.         } else {
  173.             $userData =  $this->getDoctrine()->getRepository(User::class)->findByEmail($_id);
  174.         };
  175.         
  176.         if ($userData == null || $userData->assignedCompany() != $user->assignedCompany()) {
  177.             // return $this->redirectToRoute('user_preview_profile', ['_id' => $_id]);
  178.             throw new \Exception($translator->trans('messages.security.forbidden'));
  179.         }
  180.         if ($user->getOffice()->getWorkPermitType() && $user->getOffice()->getWorkPermitType() != '') {
  181.             $workPermitTypes array_map('trim'explode(PHP_EOL$user->getOffice()->getWorkPermitType()));
  182.             $workPermit $user->getPersonalInfo()->getWorkPermitType() != '' && in_array($user->getPersonalInfo()->getWorkPermitType(), $workPermitTypes) ? $user->getPersonalInfo()->getWorkPermitType() : null;
  183.         } else {
  184.             $workPermit null;
  185.         };
  186.         $formObjective $this->createForm(ObjectiveType::class, $objective);
  187.         $formAppraisal $this->createForm(AppraisalRequestType::class, $appraisal);
  188.         $formCV $this->createForm(CVType::class, $userData->getPersonalInfo(), [
  189.             'action' => $this->generateUrl('upload_cv')
  190.         ]);
  191.         $formCertification $this->createForm(CertificationType::class, $certification);
  192.         $questionnaires $this->getDoctrine()->getRepository(AppraisalQuestionnaire::class)->findByUser($userData);
  193.         $defaultQuestions $this->getDoctrine()->getRepository(AppraisalQuestionnaire::class)->findByUser($userData);
  194.         if ($userData->getOffice()->getWidget()->getFwaVisibility()) {
  195.             $fwa = new FlexiWorkArrangementRequest();
  196.             $formFWA $this->createForm(FlexiWorkArrangementRequestType::class, $fwa, [
  197.                 'action' => $this->generateUrl('request_fwa')
  198.             ]);
  199.             $formFWA $formFWA->createView();
  200.             if ($userData->getManager() == $user || $user->hasRole('ROLE_HR')) {
  201.                 $formSignFWA $this->createForm(FlexiWorkArrangementSigningType::class, $fwa, [
  202.                     'action' => $this->generateUrl('sign_fwa')
  203.                 ]);
  204.                 $formSignFWA $formSignFWA->createView();
  205.             }
  206.         };
  207.         $start $request->query->get('week') ?: null;
  208.         if ($user->getId() == $userData->getID() || in_array($user$userData->getAllManager()) || $this->isGranted('ROLE_HR') && $user->getOffice() == $userData->getOffice() ||  $this->isGranted('ROLE_HR') && $this->isGranted('ROLE_ACCESS_ALL_OFFICE')) {
  209.             return $this->render('private/user/profile.html.twig', [
  210.                 'userData' => $userData,
  211.                 'formObjective' => $formObjective->createView(),
  212.                 'formEditAppraisal' => $formAppraisal->createView(),
  213.                 'formNewAppraisal' => $formAppraisal->createView(),
  214.                 'questionnaires' => $questionnaires $questionnaires null,
  215.                 'defaultQuestions' => $defaultQuestions $defaultQuestions null,
  216.                 'formCV' => $formCV->createView(),
  217.                 'formCertification' => $formCertification->createView(),
  218.                 'formFWA' => isset($formFWA) ? $formFWA false,
  219.                 'formSignFWA' => isset($formSignFWA) ? $formSignFWA false,
  220.                 //'restrictedContent' => $user->getId() == $userData->getID() || $userData->getManager() == $user || $user->isSubordinate($userData->getId()) || $this->isGranted('ROLE_HR') ? true : false,
  221.                 //'restrictedContent' => $user->getId() == $userData->getID() || $userData->getManager() == $user || $this->isGranted('ROLE_HR') ? true : false,
  222.                 'workPermit' => isset($workPermit) ? $workPermit false,
  223.                 'start' => $start,
  224.             ]);
  225.         } else if($this->isGranted('ROLE_FINANCE') && $user->getOffice() == $userData->getOffice() || $this->isGranted('ROLE_FINANCE') && $this->isGranted('ROLE_ACCESS_ALL_OFFICE')){
  226.             return $this->render('private/user/profile-limited.html.twig', [
  227.                 'userData' => $userData
  228.             ]);
  229.         } else {
  230.             return $this->render('private/user/profile-public.html.twig', [
  231.                 'userData' => $userData,
  232.                 'formCV' => $formCV->createView(),
  233.             ]);
  234.         }
  235.     }
  236.     #[Route(path'/preview/profile/{_id}'defaults: ['_id' => 'default'], name'user_preview_profile')]
  237.     public function userProfilePreview(string $_idTranslatorInterface $translator): \Symfony\Component\HttpFoundation\Response
  238.     {
  239.         $user $this->getUser();
  240.         if ($_id == "default") {
  241.             $userData =  $user;
  242.         } else if (is_int($_id)) {
  243.             $userData =  $this->getDoctrine()->getRepository(User::class)->find($_id);
  244.         } else {
  245.             $userData =  $this->getDoctrine()->getRepository(User::class)->findByEmail($_id);
  246.         };
  247.         if ($userData == null || $userData->assignedCompany() != $user->assignedCompany() || $userData->getIsActive() == false) {
  248.             throw new \Exception($translator->trans('messages.security.forbidden'));
  249.         }
  250.         $formCV $this->createForm(CVType::class, $userData->getPersonalInfo(), [
  251.             'action' => $this->generateUrl('upload_cv')
  252.         ]);
  253.         return $this->render('private/user/profile-public.html.twig', [
  254.             'userData' => $userData,
  255.             'formCV' => $formCV->createView(),
  256.             'preview' => true
  257.         ]);
  258.     }
  259.     #[Route(path'/ajax/filter-user'name'ajax_filter_user'methods'POST')]
  260.     function ajaxFilterUser(Request $requestTranslatorInterface $translatorUtilsService $utilsServiceUserRepository $userRepository): JsonResponse
  261.     {
  262.         $user $this->getUser();
  263.         $data null;
  264.         $result['status'] = 'OK';
  265.         /*if ($request->get("o") && $user->assignedCompany() != $office->getCompany()) {  
  266.             $result['status'] = 'ERROR';
  267.             $result['message'] = $translator->trans('messages.security.forbidden');
  268.         };*/
  269.         if ($result['status'] == 'OK') {
  270.             $result['content'] = [];
  271.             $registered_users = [];
  272.             
  273.             if($request->get("o") && $request->get("o") == 'team' && $request->get("d") == ''){
  274.                 $data $user->getSubordinates();
  275.                 // $data = $userRepository->findSubordinatesForUser($user);
  276.                 // dd($data);
  277.             }
  278.             else if ($request->get("o") && $request->get("o") == 'team' && $request->get("d") != ''){
  279.                 $subordinatesData $user->getSubordinates();
  280.                 $data = [];
  281.                 foreach ($subordinatesData as $userData) {
  282.                     $departmentData $userData->getDepartment()->getId();
  283.                     if ($departmentData == $request->get("d")) {
  284.                         $data[] = $userData;
  285.                     }
  286.                 }
  287.             }
  288.             else if ($request->get("o") && $request->get("o") != 'all' && $request->get("d") == '') {
  289.                 /*$office = $this->getDoctrine()->getRepository(Office::class)->find($request->get("o"));
  290.                 $data = $office->getUsers();*/
  291.                 $data $userRepository->findBy(array('office'=>$request->get("o"),'isActive'=>true));
  292.             } 
  293.             else if ($request->get("d") && $request->get("o") == '') {
  294.                 if($request->get("d")=='other'){
  295.                     $data $userRepository->findBy(array('department'=>null,'isActive'=>true));
  296.                 }else{
  297.                     $data $userRepository->findBy(array('department'=>$request->get("d"),'isActive'=>true));
  298.                 }
  299.             } 
  300.             else if ($request->get("d") && $request->get("o") && $request->get("o") != 'all') {
  301.                 if($request->get("d")=='other'){
  302.                     $data $userRepository->findBy(array('department'=>null,'office'=>$request->get("o"),'isActive'=>true));
  303.                 }else{    
  304.                     $data $userRepository->findBy(array('department'=>$request->get("d"),'office'=>$request->get("o"),'isActive'=>true));
  305.                 }
  306.                     /*$office = $this->getDoctrine()->getRepository(Office::class)->find($request->get("o"));
  307.                 $data =  $office->getUserByOfficeDepartment($request->get("d"));*/    
  308.             
  309.             else {
  310.                 $data = [];
  311.                 $office_id = [];
  312.                 $offices $user->assignedCompany()->getOffices();
  313.                 foreach ($offices as $office) {
  314.                     array_push($office_id$office->getId());
  315.                     //array_push($data, $this->getDoctrine()->getRepository(Organization::class)->findByOffice($office->getId()));
  316.                 };
  317.                 $data $user->assignedCompany()->getAllUser();
  318.             };
  319.             //dd($data);
  320.             foreach ($data as $d) {
  321.                 
  322.                 /*if (method_exists($d, 'getUser')) {
  323.                     $d = $d->getUser();
  324.                 }*/
  325.                 if (method_exists($d'getId') && in_array($d->getId(), $registered_users) == false && $d->getIsActive() == true) {
  326.                     if ($d->getPersonalInfo()->getProfilePicture() == null) {
  327.                         $image $d->getTemporaryPicture() ? $d->getTemporaryPicture() : "";
  328.                     } else {
  329.                         $image $utilsService->getFileFromAWS($d->getPersonalInfo()->getProfilePicture());
  330.                     };
  331.                     $managerList '';
  332.                     $i 0;
  333.                     foreach($d->getAllManager() as $manager){
  334.                         $managerList.= $i == 'Supervised by ':', ';
  335.                         $managerList.= '<a href="'.$this->generateUrl('user_profile',['id'=>$manager->getEmail()]).'">'.$manager->getPersonalInfo()->getFirstName().'</a>';
  336.                         $i++;
  337.                     }
  338.                     if ($request->get("s") == '0' || $d->getStatus() == $request->get("s")) {
  339.                         if(!is_null($d->getOffice())){
  340.                             array_push($result['content'], [
  341.                                 'id' => $d->getId(),
  342.                                 'status' => $d->getStatus(),
  343.                                 'statusLabel' => $translator->trans($d->statusLabel()),
  344.                                 'statusColor' => $translator->trans($d->statusColor()),
  345.                                 'image' => $image,
  346.                                 'name' => $d->getPersonalInfo()->getFullName(),
  347.                                 'email' => $d->getEmail(),
  348.                                 'title' => $d->organizationTitles(),
  349.                                 'department' => $d->organizationDepartmentNames(),
  350.                                 'officeId' => $d->getOffice()->getId(),
  351.                                 'officeName' => $d->getOffice()->getFullName(),
  352.                                 'manager' => $managerList,
  353.                             ]);
  354.                             array_push($registered_users$d->getId());
  355.                         }     
  356.                     };
  357.                 };
  358.             };
  359.             if (count($result['content']) == 0) {
  360.                 $result['status'] = 'FAIL';
  361.             } else {
  362.                 $byName array_column($result['content'], 'name');
  363.                 array_multisort($byNameSORT_ASC$result['content']);
  364.             }
  365.         }
  366.         return new JsonResponse($result);
  367.     }
  368.     #[Route(path'/ajax/search-user'name'ajax_search_user'methods'POST')]
  369.     function ajaxSearchUser(Request $requestTranslatorInterface $translatorUtilsService $utilsServiceUserRepository $userRepository): JsonResponse
  370.     {
  371.         $user $this->getUser();
  372.         $data null;
  373.         $result['status'] = 'OK';
  374.         //$data = $this->getDoctrine()->getRepository(PersonalInfo::class)->findByAnyName($request->get("u"));
  375.         if ($request->get("o")) {
  376.             
  377.             if ($request->get("o") == 'team'){
  378.                 $searchTerm $request->get('u');
  379.                 $subordinatesData $user->getSubordinates();
  380.                 $data = [];
  381.                 foreach ($subordinatesData as $userData) {
  382.                     $personalInfo $userData->getPersonalInfo();
  383.                     $firstName $personalInfo->getFirstName();
  384.                     $middleName $personalInfo->getMiddleName();
  385.                     $lastName $personalInfo->getLastName();
  386.                     $fullName $personalInfo->getFullName();
  387.                     if (
  388.                         stripos($firstName$searchTerm) !== false ||
  389.                         stripos($middleName$searchTerm) !== false ||
  390.                         stripos($lastName$searchTerm) !== false ||
  391.                         stripos($fullName$searchTerm) !== false
  392.                     ) {
  393.                         $data[] = $userData;
  394.                     }
  395.                 }
  396.             }else{
  397.                 //$office = $this->getDoctrine()->getRepository(Office::class)->find($request->get("o"));
  398.             $data $userRepository->findByAnyNameOnSameOffice($request->get("u"),  $request->get("o"));
  399.             }
  400.         } else {
  401.             $data $userRepository->findByAnyNameOnSameCompany($request->get("u"), $user->assignedCompany());
  402.         }
  403.         if ($data != null) {
  404.             $result['content'] = [];
  405.             foreach ($data as $d) {
  406.                 $office $request->get("o") ? $request->get("o") : true;
  407.                 if ($d->getIsActive() == true) {
  408.                     if ($d->getPersonalInfo()->getProfilePicture() == null) {
  409.                         $image $d->getTemporaryPicture() ? $d->getTemporaryPicture() : "";
  410.                     } else {
  411.                         $image $utilsService->getFileFromAWS($d->getPersonalInfo()->getProfilePicture());
  412.                     };
  413.                     $managerList '';
  414.                     $i 0;
  415.                     foreach($d->getAllManager() as $manager){
  416.                         $managerList.= $i == '<br/>Supervised by ':', ';
  417.                         $managerList.= '<a href="'.$this->generateUrl('user_profile',['id'=>$manager->getEmail()]).'">'.$manager->getPersonalInfo()->getFirstName().'</a>';
  418.                         $i++;
  419.                     }
  420.                     array_push($result['content'], [
  421.                         'id' => $d->getId(),
  422.                         'statusLabel' => $translator->trans($d->statusLabel()),
  423.                         'statusColor' => $translator->trans($d->statusColor()),
  424.                         'image' => $image,
  425.                         'name' => $d->getPersonalInfo()->getFullName(),
  426.                         'email' => $d->getEmail(),
  427.                         'title' => $d->organizationTitles(),
  428.                         'department' => $d->organizationDepartmentNames(),
  429.                         'officeId' => $d->getOffice()->getId(),
  430.                         'officeName' => $d->getOffice()->getFullName(),
  431.                         'manager' => $managerList,
  432.                     ]);
  433.                 };
  434.             };
  435.             if (count($result['content']) > 0) {
  436.                 $byName array_column($result['content'], 'name');
  437.                 array_multisort($byNameSORT_ASC$result['content']);
  438.             } else {
  439.                 $result['status'] = 'FAIL';
  440.             }
  441.         } else {
  442.             $result['status'] = 'FAIL';
  443.         }
  444.         return new JsonResponse($result);
  445.     }
  446.     #[Route(path'/image/{type}/{file}'name'get_image')]
  447.     public function getImage($type$fileTranslatorInterface $translatorUtilsService $utilsService)
  448.     {
  449.         //$awsFile = $utilsService->getFileFromAWS('/uploads/document/' .$file);
  450.         //$headers = get_headers($awsFile);
  451.         //if(substr($headers[0], 9, 3) == '200'){
  452.         switch ($type) {
  453.             case "profile":
  454.                 $path $this->getParameter('profilePicture');
  455.                 break;
  456.             case "logo":
  457.                 $path $this->getParameter('companyLogo');
  458.                 break;
  459.         }
  460.         if ($awsFile $utilsService->getFileFromAWS($this->getParameter('documentFile') . '/' $file)) {
  461.             $fileName preg_replace('/^[^_.]{8}_/'''$file);
  462.             $fileName preg_replace('/_[^_.]*\./''.'$fileName);
  463.             $response = new Response();
  464.             $response->headers->set('Content-type''image');
  465.             $response->headers->set('Content-Disposition'sprintf('attachment; filename="%s"'$fileName));
  466.             $response->setContent(file_get_contents($awsFile));
  467.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
  468.             $response->headers->set('Content-Transfer-Encoding''binary');
  469.             $response->headers->set('Pragma''no-cache');
  470.             $response->headers->set('Expires''0');
  471.             return $response;
  472.         } else {
  473.             return new Response(null\Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
  474.         };
  475.     }
  476.     #[Route(path'/download/{type}/{file}'requirements: ['file' => '.+'], name'download_file')]
  477.     public function downloadFile($typestring $fileTranslatorInterface $translatorUtilsService $utilsService)
  478.     {
  479.         //$awsFile = $utilsService->getFileFromAWS('/uploads/document/' .$file);
  480.         //$headers = get_headers($awsFile);
  481.         //if(substr($headers[0], 9, 3) == '200'){
  482.            
  483.         switch ($type) {
  484.             case "document":
  485.                 $path $this->getParameter('documentFile');
  486.                 $fileName preg_replace('/^[^_.]{8}_/'''$file);
  487.                 $fileName preg_replace('/_[^_.]*\./''.'$fileName);
  488.                 $fullPath $path '/' $file;
  489.                 break;
  490.             case "file":
  491.                 $_file explode('/'$file);
  492.                 $fileName preg_replace('/^[^_.]{8}_/'''$_file[2]);
  493.                 $fileName preg_replace('/_[^_.]*\./''.'$fileName);
  494.                 $fullPath $file;
  495.                 break;
  496.             default:
  497.                 $path $this->getParameter($type);
  498.                 $fileName preg_replace('/^[^_.]{8}_/'''$file);
  499.                 $fileName preg_replace('/_[^_.]*\./''.'$fileName);
  500.                 $fullPath $path '/' $file;
  501.                 break;
  502.         }
  503.        
  504.         if ($awsFile $utilsService->getFileFromAWS($fullPath)) {
  505.             $response = new Response();
  506.             $response->headers->set('Content-type''application/octet-stream');
  507.             $response->headers->set('Content-Disposition'sprintf('attachment; filename="%s"'$fileName));
  508.             $response->setContent(file_get_contents($awsFile));
  509.             $response->setStatusCode(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
  510.             $response->headers->set('Content-Transfer-Encoding''binary');
  511.             $response->headers->set('Pragma''no-cache');
  512.             $response->headers->set('Expires''0');
  513.             return $response;
  514.         } else {
  515.             return new Response(null\Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
  516.         };
  517.     }
  518.     #[Route(path'/view/{type}/{file}'requirements: ['file' => '.+'], name'view_file')]
  519.     public function viewFile($typestring $fileTranslatorInterface $translatorUtilsService $utilsService)
  520.     {
  521.            
  522.         switch ($type) {
  523.             case "document":
  524.                 $path $this->getParameter('documentFile');
  525.                 $fileName preg_replace('/^[^_.]{8}_/'''$file);
  526.                 $fileName preg_replace('/_[^_.]*\./''.'$fileName);
  527.                 $fullPath $path '/' $file;
  528.                 break;
  529.             case "file":
  530.                 $_file explode('/'$file);
  531.                 $fileName preg_replace('/^[^_.]{8}_/'''$_file[2]);
  532.                 $fileName preg_replace('/_[^_.]*\./''.'$fileName);
  533.                 $fullPath $file;
  534.                 break;
  535.             default:
  536.                 $path $this->getParameter($type);
  537.                 $fileName preg_replace('/^[^_.]{8}_/'''$file);
  538.                 $fileName preg_replace('/_[^_.]*\./''.'$fileName);
  539.                 $fullPath $path '/' $file;
  540.                 break;
  541.         }
  542.        
  543.         if ($awsFile $utilsService->getFileFromAWS($fullPath)) {
  544.             return $this->redirect($awsFile);
  545.         } else {
  546.             return new Response(null\Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
  547.         };
  548.     }
  549.     #[Route(path'/ajax/send-internal-email'name'ajax_send_internal_email'methods'POST')]
  550.     function ajaxSendInternalEmail(Request $requestMailgunService $mailgunServiceTranslatorInterface $translator)
  551.     {
  552.         $user $this->getUser();
  553.         $form $this->createFormBuilder()
  554.             ->add('email'HiddenType::class, [
  555.                 'required' => true,
  556.             ])->add('subject'HiddenType::class, [
  557.                 'required' => true,
  558.             ])->add('message'TextareaType::class, [
  559.                 'required' => true,
  560.                 'attr' => array('rows' => 10),
  561.                 'label' => 'Message',
  562.             ])->add('anonymous'HiddenType::class, [
  563.                 'required' => true,
  564.             /*])->add('attachment', FileType::class, [
  565.                 'required' => false,
  566.                 'mapped' => false,
  567.                 'attr' => array('maxlength' => 255),*/
  568.             ])->add('submit'SubmitType::class, array('label' => 'form.send'))
  569.             ->getForm();
  570.         $form->handleRequest($request);
  571.         $result['status'] = 'OK';
  572.         if ($result['status'] == 'OK') {
  573.             $subject $form->get('subject')->getData();
  574.             $email_data explode('?'$form->get('email')->getData());
  575.             $email $email_data[0];
  576.             $email_cc null;
  577.             $message $form->get('message')->getData();
  578.             //$sent = true;
  579.             //$attachment = $form->get('attachment');
  580.             $anonymous $form->get('anonymous')->getData();
  581.             $sent $mailgunService->sendEmailAdvanced([
  582.                 'subject' => $subject,
  583.                 'to' => [$email],
  584.                 'reply' => $anonymous == 'true' ? [] : [$user->getEmail()],
  585.                 'template' => 'email/email-internal/default.html.twig',
  586.                 'params' => [
  587.                     'message' => $message,
  588.                     'user' => $user
  589.                 ],
  590.                 //'attachments' => $attachment != null ? new UploadedBase64EncodedFile(new Base64EncodedFile($attachment->getData())) : null
  591.             ]);
  592.             $mailgunService->sendEmailAdvanced([
  593.                 'subject' => $translator->trans('email.system.copy').' '.$subject,
  594.                 'to' => [$user->getEmail()],
  595.                 'reply' => $anonymous == 'true' ? [] : [$email],
  596.                 'template' => 'email/email-internal/respond.html.twig',
  597.                 'params' => [
  598.                     'message' => $message,
  599.                     'user' => $user
  600.                 ],
  601.                 //'attachments' => $attachment != null ? new UploadedBase64EncodedFile(new Base64EncodedFile($attachment->getData())) : null
  602.             ]);
  603.             $result['content'] = [
  604.                 'sent' => $sent,
  605.                 'subject' => $subject,
  606.                 'to' => $email,
  607.                 'cc' => $email_cc,
  608.                 'message' => $message
  609.             ];
  610.         } else {
  611.             $result['status'] = 'ERROR';
  612.         }
  613.         return new JsonResponse($result);
  614.     }
  615.      #[Route(path'/ajax/file-collector'name'ajax_file_collector'methods'POST')]
  616.     function ajaxFileCollector(Request $requestUploadService $uploadService)
  617.     {
  618.         return new JsonResponse($uploadService->fileCollector($request->files->get('file'), $this->getParameter('collectorFile')));
  619.     }
  620.     #[Route(path'/disabledate/{id}'name'ajax_disable_date'methods'GET')]
  621.      function _disableDate($id):JsonResponse
  622.      {
  623.         $result=array();
  624.         $user=$this->getDoctrine()->getRepository(\App\Entity\User::class)->find($id);
  625.         if(!is_null($user)){
  626.             $country=$user->getOffice()->getCountry();
  627.             $holiday=$this->getDoctrine()->getRepository(\App\Entity\LeaveBankHoliday::class)->findBy(array('location'=>$country));
  628.             $leaves=$this->getDoctrine()->getRepository(\App\Entity\LeaveRequest::class)->findBy(array('user'=>$id));
  629.             
  630.             if(!is_null($holiday)){
  631.                 foreach($holiday as $h){
  632.                     $start=new \DateTime($h->getDate()->format('Y-m-d'));
  633.                     $end=$h->getEndDate();
  634.                     if(is_null($end)){
  635.                         $end=new \DateTime($h->getDate()->format('Y-m-d'));
  636.                     }else{
  637.                         $end=new \DateTime($h->getEndDate()->format('Y-m-d'));
  638.                     }
  639.                     
  640.                     $int=date_diff($end,$start);
  641.                     if($int->0){
  642.                         $tmpend=new \DateTime($end->format('Y-m-d'));
  643.                         $end=new \DateTime($start->format('Y-m-d'));
  644.                         $start=new \DateTime($tmpend->format('Y-m-d'));
  645.                     }
  646.                     $int=abs($int->d)+1;
  647.                     for($i=0;$i<$int;$i++){
  648.                         $result[count($result)]=$start->format('Y-m-d');
  649.                         $start->modify('+1 day');
  650.                     }
  651.                     
  652.                 }
  653.             }
  654.             if(!is_null($leaves)){
  655.                 foreach($leaves as $l){
  656.                     $start=new \DateTime($l->getStartDate()->format('Y-m-d'));
  657.                     $end=new \DateTime($l->getEndDate()->format('Y-m-d'));
  658.                     $int=date_diff($end,$start);
  659.                     if($int->0){
  660.                         $end=new \DateTime($l->getStartDate()->format('Y-m-d'));
  661.                         $start=new \DateTime($l->getEndDate()->format('Y-m-d'));
  662.                     }
  663.                     $int=abs($int->d)+1;
  664.                     for($i=0;$i<$int;$i++){
  665.                         $result[count($result)]=$start->format('Y-m-d');
  666.                         $start->modify('+1 day');
  667.                     }
  668.                 }    
  669.             }
  670.         }
  671.         
  672.         return new JsonResponse($result);
  673.      }
  674.      #[Route(path'/ajax/session'name'ajax_session'methods'POST')]
  675.      function ajaxSession(Request $requestNotificationService $notification): JsonResponse
  676.      {
  677.         $firewall $this->isGranted('ROLE_CLIENT_CONTACT') ? 'client' 'main';
  678.          if (!$this->isGranted('ROLE_STAFF')) {
  679.              return new JsonResponse([
  680.                  'status' => "TIMEOUT",
  681.                  'firewall' => $firewall
  682.              ]);
  683.          }
  684.          $entityManager $this->getDoctrine()->getManager();
  685.          $user $this->getUser();
  686.          $notification->check($user);
  687.          $user->setLastActivityAt(new \DateTime());
  688.          $entityManager->flush();
  689.          $result['status'] = 'OK';
  690.          $result['notification'] = $this->getDoctrine()->getRepository(Notification::class)->countLimitedUnread($user->getId());
  691.          $result['firewall'] = $firewall;
  692.          return new JsonResponse($result);
  693.      }
  694. }