src/Controller/UserController.php line 100

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Entity\UserData;
  5. use App\Service\CampaignRecurrentService;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use App\Service\UserService
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. use App\Repository\UserRepository;
  14. use App\Repository\PortfolioRepository;
  15. use Symfony\Component\Serializer\SerializerInterface;
  16. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  17. use Twig\Environment;
  18. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  19. #[Route('/user'name"user_")]
  20. class UserController extends AbstractController
  21. {
  22.     public function __construct(
  23.         private EntityManagerInterface $entityManagerInterface,
  24.         private CampaignRecurrentService $campaignRecurrentService,
  25.         private UserRepository $userRepository,
  26.         private PortfolioRepository $portfolioRepository,
  27.         private UserService $userService,
  28.         private SerializerInterface $serializer,
  29.     ){}
  30.     #[Route('/delete/{id}'name"delete")]
  31.     public function deletedUser(User $user) : RedirectResponse 
  32.     {   
  33.         if($this->getUser()->getId() == $user->getId()){
  34.             $this->userService->deleteDataWpAndApp($user);
  35.             return $this->redirectToRoute('app_logout');
  36.         }
  37.         else{
  38.             return $this->redirectToRoute('mission_index');
  39.         }
  40.     }
  41.     #[Route('/my-flow/directory/page/{page}/{query}'name"my_flow_directory"methods: ['GET'],defaults: ['query'=>""])]
  42.     public function myFlowDirectory(Request $request,int $page 1string $query "") : JsonResponse 
  43.     {   
  44.         $data =  $this->userRepository->findByUserAcceptPresentation(preg_replace('/\s+/'' '$query)); 
  45.         $limit 12
  46.         $offset = ($page 1) * $limit;
  47.         $totalItems count($data);
  48.         $totalPages ceil($totalItems $limit);
  49.         $paginatedData array_slice($data$offset$limit);
  50.         
  51.         $jsonData $this->serializer->serialize([
  52.             'users'=>$paginatedData,
  53.             'page'=>$page,
  54.             'next_page'=>  $totalPages <= $page $page+1,
  55.             'total_page'=> $totalPages,
  56.             'list_user_rendered'=> 1,
  57.             'total_item'=> $totalItems,
  58.         ], 'json', ['groups' => ['user_directory']]); 
  59.         $response =  new JsonResponse$jsonData,200, [],true) ;
  60.         $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
  61.         $response->headers->set('Access-Control-Allow-Origin''*');
  62.         $response->headers->set('Access-Control-Allow-Headers''Content-Type');
  63.         return $response ;
  64.     }
  65.     
  66.     #[Route('/my-flow/directory/{id}'name"my_flow_directory_show"methods: ['GET'])]
  67.     public function myFlowDirectoryShow(Request $requeststring $id) : JsonResponse 
  68.     {   
  69.         $user $this->userRepository->findOneBy(['acceptPresentation'=>true'id'=>$id]);
  70.         $jsonData $this->serializer->serialize($user'json', ['groups' => ['user_directory']]);
  71.         $response =  new JsonResponse$jsonData,200, [],true) ;
  72.         $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
  73.         $response->headers->set('Access-Control-Allow-Origin''*');
  74.         $response->headers->set('Access-Control-Allow-Headers''Content-Type');
  75.         
  76.         return $response ;
  77.     }
  78.     #[Route('/my-flow/realisation-subcontractor-{limit}'name"my_flow_realisation_subcontractor"methods: ['GET'])]
  79.     public function realisationShow(Request $request,$limit null) : JsonResponse 
  80.     {   
  81.         $portfolioId $this->portfolioRepository->somePortfolioId($limit);
  82.         shuffle($portfolioId);
  83.         $randomIds array_slice($portfolioId012); 
  84.         $portfolio $this->portfolioRepository->somePortfolioRand($limit,$randomIds);
  85.         $response =  new JsonResponse$portfolio,200, [],false) ;
  86.         $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
  87.         $response->headers->set('Access-Control-Allow-Origin''*');
  88.         $response->headers->set('Access-Control-Allow-Headers''Content-Type');
  89.         return $response ;
  90.     }
  91.     #[Route('/my-flow/realisation-list-subcontractor-{limit}'name"my_flow_list_realisation_subcontractor"methods: ['GET'])]
  92.     public function realisationShowList(Request $request,$limit null) : JsonResponse 
  93.     {   
  94.         $portfolio $this->portfolioRepository->somePortfolio($limit);
  95.         $response =  new JsonResponse$portfolio,200, [],false) ;
  96.         $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
  97.         $response->headers->set('Access-Control-Allow-Origin''*');
  98.         $response->headers->set('Access-Control-Allow-Headers''Content-Type');
  99.         return $response ;
  100.     }
  101.     #[Route('/my-flow/count-realisation-subcontractor'name"my_flow_count_realisation_subcontractor"methods: ['GET'])]
  102.     public function countRealisationShow(Request $request) : JsonResponse 
  103.     {   
  104.         $portfolio $this->portfolioRepository->countsomePortfolio();
  105.         $response =  new JsonResponse$portfolio,200, [],false) ;
  106.         $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
  107.         $response->headers->set('Access-Control-Allow-Origin''*');
  108.         $response->headers->set('Access-Control-Allow-Headers''Content-Type');
  109.         return $portfolio ;
  110.     }
  111.      #[Route('/my-flow/realisation-html-list-{limit}-{offset}'name"my_flow_realisation_subcontractor_html_results"methods: ['GET'])]
  112.     public function realisationShowHtmlResults(Request $request,$limit null,$offset null
  113.     {   
  114.         $categorie $request->query->get('cat');
  115.         $keys $request->query->get('keys');
  116.         $job $request->query->get('job');
  117.         $filter = [
  118.             'cat' => $categorie,
  119.             'keys' => $keys,
  120.             'job' => $job,
  121.         ];
  122.         $portfolio $this->portfolioRepository->somePortfolio($limit,$offset);
  123.         $portfolio $this->portfolioRepository->somePortfolioFilter($limit,$offset,$filter);
  124.         $portfolioAll $this->portfolioRepository->somePortfolioFilter(null,$offset,$filter);
  125.         $nb count($portfolioAll);
  126.         return $this->render('sub_contractor/portfolio/portfolio_results_list.html.twig', [
  127.             'portfolio'=> $portfolio,
  128.             'offset'=> $offset,
  129.             'nb'=> $nb,
  130.         ]);
  131.     }
  132.     #[Route('/my-flow/{id}/realisation-list-subcontractor-{limit}'name"my_flow_realisation_user_subcontractor_results"methods: ['GET'])]
  133.     public function realisationUserShowResults(string $idRequest $request,$limit null
  134.     {   
  135.         $portfolio $this->portfolioRepository->somePortfolio($limit,null$id);
  136.         $response =  new JsonResponse$portfolio,200, [],false) ;
  137.         $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
  138.         $response->headers->set('Access-Control-Allow-Origin''*');
  139.         $response->headers->set('Access-Control-Allow-Headers''Content-Type');
  140.         return $response ;
  141.     }
  142.     #[Route('/my-flow/{id}/realisation-html-list-{limit}-{offset}'name"my_flow_realisation_user_subcontractor_html_results"methods: ['GET'])]
  143.     public function realisationUserShowHtmlResults(string $idRequest $request,$limit null,$offset null
  144.     {   
  145.          $categorie $request->query->get('cat');
  146.         $keys $request->query->get('keys');
  147.         $job $request->query->get('job');
  148.         $filter = [
  149.             'cat' => $categorie,
  150.             'keys' => $keys,
  151.             'job' => $job,
  152.         ];
  153.         $portfolio $this->portfolioRepository->somePortfolioFilter($limit,$offset$id);
  154.          $portfolioAll $this->portfolioRepository->somePortfolioFilter(null,$offset,$filter);
  155.         $nb count($portfolioAll);
  156.         return $this->render('sub_contractor/portfolio/portfolio_results_list.html.twig', [
  157.             'portfolio'=> $portfolio,
  158.             'offset'=> $offset,
  159.             'nb'=> $nb,
  160.             'limit'=> 16,
  161.         ]);
  162.     }
  163.     #[Route('/my-flow/realisation-filter-html-list-{limit}-{offset}'name"my_flow_realisation_user_subcontractor_html_all_in_filter_results"methods: ['GET'])]
  164.     public function filterRealisationResults(Request $request,$limit null,$offset null
  165.     {   
  166.         $categorie $request->query->get('cat');
  167.         $keys $request->query->get('keys');
  168.         $job $request->query->get('job');
  169.         $filter = [
  170.             'cat' => $categorie,
  171.             'keys' => $keys,
  172.             'job' => $job,
  173.         ];
  174.         $portfolio $this->portfolioRepository->somePortfolioFilter($limit,$offset,$filter);
  175.         $portfolioAll $this->portfolioRepository->somePortfolioFilter(null,$offset,$filter);
  176.         $nb count($portfolioAll);
  177.         return $this->render('sub_contractor/portfolio/filter_result.html.twig', [
  178.             'portfolio'=> $portfolio,
  179.             'limit'=> 24,
  180.             'offset'=> $offset,
  181.             'nb'=> $nb,
  182.         ]);
  183.     }
  184.     #[Route('/my-flow/realisation-filter-count-number-html-list-{limit}-{offset}'name"my_flow_realisation_user_subcontractor_count_number_html_all_in_filter_results"methods: ['GET'])]
  185.     public function filterRealisationResultsCountNumber(Request $request,$limit null,$offset null
  186.     {   
  187.         $categorie $request->query->get('cat');
  188.         $keys $request->query->get('keys');
  189.         $job $request->query->get('job');
  190.         $filter = [
  191.             'cat' => $categorie,
  192.             'keys' => $keys,
  193.             'job' => $job,
  194.         ];
  195.         $portfolioAll $this->portfolioRepository->somePortfolioFilter(null,$offset,$filter);
  196.         $nb count($portfolioAll);
  197.         return new JsonResponse([
  198.             'status'=>'OK',
  199.             'nb'=>$nb
  200.         ]);   
  201.     }
  202.     #[Route('/my-flow/user-menu/{id}'name""methods: ['GET'])]
  203.     public function menuSave(User $userRequest $request) : JsonResponse 
  204.     {  
  205.         $active $request->query->get('active') == "true" true false;
  206.         if($user?->getUserData() == null) {
  207.             $userData = new UserData();
  208.             $userData->setMenuState($active);
  209.            
  210.         }else{
  211.             $userData $user->getUserData();
  212.              $userData->setMenuState($active);
  213.         }
  214.         $this->entityManagerInterface->persist($userData);
  215.         $user->setUserData($userData);
  216.         $this->entityManagerInterface->persist($user);
  217.         $this->entityManagerInterface->flush();
  218.         return new JsonResponse('ok');
  219.     }
  220.     #[Route('/my-flow/detail-realisation/{id}',name:'get_this_realisation'methods:'GET')]
  221.     public function getThisRealisation(int $id,Environment $twig){
  222.         $detailPortfolio = [];
  223.         $portfolio $this->portfolioRepository->findOneBy(['id'=>$id]);
  224.         if(!is_null($portfolio)){
  225.             $detailPortfolio['id'] = $portfolio->getID();
  226.             $detailPortfolio['title'] = $portfolio->getTitle();
  227.             $detailPortfolio['fileCategory'] = $portfolio->getFileCategory();
  228.             $detailPortfolio['fileUrl'] = $portfolio->getFileUrl();
  229.             $detailPortfolio['thumbnail'] = $portfolio->getThumbnail();
  230.         }
  231.         $response = new JsonResponse($detailPortfolio) ;
  232.         return  $response;
  233.     }
  234.     #[Route('/my-flow/update-user-filter-state/{opened}',name:"update_user_filter_button_state", )]
  235.     public function updateFilterButtonManagerState(string $opened,SessionInterface $session ){
  236.         $session->set('is_filter_open',$opened);
  237.         $isFilterOpened $session->get('is_filter_open');
  238.         return new JsonResponse($isFilterOpened);
  239.     }
  240.     
  241.     #[Route('/my-flow/user-job-related-to-realisation',name:'get_user_job_related_to_realisation')]
  242.     public function getUserJobRelatedToRealisation(): JsonResponse {
  243.         $listJobToSend = [];
  244.         $listJobRelatedToRealisation $this->portfolioRepository->getJobRelatedToRealisation();
  245.         $listJobToSend['job'] = $listJobRelatedToRealisation;
  246.         $response =  new JsonResponse$listJobToSend,200, [],false) ;
  247.         return $response;
  248.     }
  249.     #[Route('/my-flow/get-this-realisation/{id}',name:'get_this_realisation'methods:'GET')]
  250.     public function get_this_realisation(int $idRequest $request){
  251.         $portfolio $this->portfolioRepository->findOneBy(['id'=>$id]);
  252.        
  253.         return new JsonResponse($portfolio);
  254.     }
  255. }