src/Controller/ProfileController.php line 563

Open in your IDE?
  1. <?php namespace App\Controller;
  2. use App\Entity\Clients;
  3. use App\Entity\Credits;
  4. use App\Entity\Training;
  5. use App\Entity\Trainings;
  6. use App\Repository\ClientsRepository;
  7. use App\Services\ImageService;
  8. use App\Services\PdfService;
  9. use JsonSchema\Constraints\Factory;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Intervention\Image\ImageManagerStatic as Image;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  18. class ProfileController extends AbstractController {
  19.     /**
  20.      * Display a listing of the resource.
  21.      * GET /client
  22.      *
  23.      * @return Response
  24.      */
  25.     public function index(Request $request)
  26.     {
  27.         $client $this->getUser();
  28.         if (is_null($client))
  29.         {
  30.             return \Redirect::to('login');
  31.         }
  32.         return $this->render('theme::bs.client.profile'compact('client'));
  33.     }
  34.     /**
  35.      * Show the form for creating a new resource.
  36.      * GET /client/create
  37.      *
  38.      * @return Response
  39.      */
  40.     public function create()
  41.     {
  42.         return $this->render('users.create');
  43.     }
  44.     /**
  45.      * Store a newly created resource in storage.
  46.      * POST /client
  47.      *
  48.      * @return Response
  49.      */
  50.     public function store(Request $request)
  51.     {
  52.         $input $request->request->all();
  53.         $validation = \Validator::make($inputClient::$rules);
  54.         if ($validation->passes())
  55.         {
  56.             $input['password'] = \Hash::make($input['username']);
  57.             $client ClientFactory::create($input);
  58.             $this->getDoctrine()->getManager()->persist($client);
  59.             $this->getDoctrine()->getManager()->flush();
  60.             return "ok";
  61.         }
  62.         return "not ok";
  63.     }
  64.     /**
  65.      * Display the specified resource.
  66.      * GET /client/{id}
  67.      *
  68.      * @param  int  $id
  69.      * @return Response
  70.      */
  71.     public function show($id 0)
  72.     {
  73.     //    dd("ds");
  74. //        dd($this->getUser());
  75.         if($id == 0$id $this->getUser()->getId();
  76.         $client =
  77.         $paysite $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')->find($id);
  78.         //dd($paysite);
  79.         return $this->render('bs/client/profile.html.twig', ['client' => $paysite])
  80.             ;
  81.     }
  82.     public function showCropper($url 0)
  83.     {
  84.         return "cropping";
  85.         if($id == 0$id $this->getUser()->getId();
  86.         $paysite $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')->find($id);
  87.         //dd($paysite);
  88.         return $this->render('theme::bs.client.cropper')
  89.             ->with('client',$paysite)
  90.             ;
  91.     }
  92.     /**
  93.      * Show the form for editing the specified resource.
  94.      * GET /client/{id}/edit
  95.      *
  96.      * @param  int  $id
  97.      * @return Response
  98.      */
  99.     public function edit($id)
  100.     {
  101.         return "showing profile $id";
  102.     }
  103.     /**
  104.      * Update the specified resource in storage.
  105.      * PUT /client/{id}
  106.      *
  107.      * @param  int  $id
  108.      * @return Response
  109.      */
  110.     public function update(Request $request$id)
  111.     {
  112.         //
  113.     }
  114.     /**
  115.      * Remove the specified resource from storage.
  116.      * DELETE /client/{id}
  117.      *
  118.      * @param  int  $id
  119.      * @return Response
  120.      */
  121.     public function destroy($id)
  122.     {
  123.         //
  124.     }
  125.     public function removeCredits(Request $request){
  126.         /** @var Credits $credit */
  127.         $credit $this->getDoctrine()->getRepository('App\Entity\Credits')->findOneById($request->request->all()['id']);
  128.         /** @var Clients $client */
  129.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  130.             ->find($request->request->all()['user']);
  131.         $new_creds str_replace($credit->getId().',',''$client->getCredits());
  132.         $client->setCredits($new_creds);
  133.         $client->removeNewCredit($credit);
  134.         $this->getDoctrine()->getManager()->remove($credit);
  135.         $this->getDoctrine()->getManager()->persist($client);
  136.         $this->getDoctrine()->getManager()->flush();
  137.         return  new JsonResponse($client->getId());
  138.     }
  139.     public function saveCredits(Request $request){
  140.         /** @var Credits $credit */
  141.         $credit $this->getDoctrine()->getRepository('App\Entity\Credits')->findOneById($request->request->all()['id']);
  142.         $credit->setCompanyName($request->request->all()['company_name'] ?? $credit->getCompanyName());
  143.         $credit->setDescription($request->request->all()['description'] ?? $credit->getDescription());
  144.         $credit->setProductionType($request->request->all()['production_type'] ?? $credit->getProductionName());
  145.         $credit->setProductionName($request->request->all()['production_name'] ?? $credit->getProductionName());
  146.         $credit->setProductionYear($request->request->all()['production_year'] ?? $credit->getProductionYear());
  147.         $credit->setRole($request->request->all()['role'] ?? $credit->getRole());
  148.         $credit->setRoleType($request->request->all()['role_type'] ?? $credit->getRoleType());
  149.         $credit->setUserId($request->request->all()['user'] ?? $credit->getUserId());
  150.         $this->getDoctrine()->getManager()->persist($credit);
  151.         $this->getDoctrine()->getManager()->flush();
  152.         return  new JsonResponse($credit->getProductionYear());
  153.     }
  154.     public function removeImageFeatured(Request $request)
  155.     {
  156.         /** @var Clients $client */
  157.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  158.             ->find($request->request->all()['user']);
  159.         $client->setFeaturedImage("");
  160.         $client->setAdminImage("");
  161.         $this->getDoctrine()->getManager()->persist($client);
  162.         $this->getDoctrine()->getManager()->flush();
  163.         return new JsonResponse(['status'=>'ok']);
  164.     }
  165.     public function removeImage(Request $request)
  166.     {
  167.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  168.             ->find($request->request->all()['user']);
  169.         ;
  170.         $new = [];
  171.         $u 0;
  172.         $a 0;
  173.         $removedImage basename($request->request->all()['image_url']);
  174.         $removedImage str_replace("thumb_"""$removedImage);
  175.         foreach($client->getPortfolioImagesArray() as $img)
  176.         {
  177.             if(! stristr(basename($img),$removedImage))
  178.             {
  179.                 $u++;
  180.                 $new[] = $img;
  181.             }
  182.             else
  183.             {$a++;}
  184.         }
  185.         $client->setPortfolioImagesArray($new);
  186.         $this->getDoctrine()->getManager()->persist($client);
  187.         $this->getDoctrine()->getManager()->flush();
  188.         return new JsonResponse("$u - $a - ".basename($request->request->all()['image_url']));
  189.     }
  190.     public function featureImage(Request $request)
  191.     {
  192.         $img $request->request->all()['image_url'];
  193.         /** @var Clients $client */
  194.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  195.             ->find($request->request->all()['user']);
  196.         $client->setFeaturedImage($img);
  197.         $client->setAdminImage($img);
  198.         $this->getDoctrine()->getManager()->persist($client);
  199.         $this->getDoctrine()->getManager()->flush();
  200.         return new JsonResponse($img);
  201.     }
  202.     public function addImage(Request $requestImageService $image_service) {
  203.         //dd();
  204.         $base64img str_replace('data:image/jpeg;base64,'''$request->request->all()['img_data']);
  205.         $base64img str_replace('data:image/png;base64,'''$base64img);
  206.         $data base64_decode($base64img);
  207.         $file =  $this->getParameter('portfolio_images_dir').
  208.                  time().".jpg";
  209.         ;
  210.         $thumb str_replace(["port_images/"],
  211.             "port_images/thumb_",
  212.             $file);
  213.         //todo: test on move
  214. //        var_dump('file', $file);
  215. //        var_dump('thumb', $thumb);
  216. //        var_dump('cwd', getcwd());
  217. //        var_dump('dir', __DIR__ );
  218. //
  219. //        exit;
  220. //        exit;
  221.         Image::configure(array('driver' => 'imagick'));
  222.         $image Image::make($data);
  223.         $image->resize(15001500, function ($constraint) {
  224.             $constraint->aspectRatio();
  225.         });
  226.         $ram =  $image->save($file);
  227.         $image_service->resize_to_fit($file);
  228.         $image->resize(400400, function ($constraint) {
  229.             $constraint->aspectRatio();
  230.         });
  231.         $image->crop(400400
  232.         );
  233.         $image->save($thumb);
  234.         $image->save($thumb);
  235.         //var_dump($base64img);
  236.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  237.             ->find($request->request->all()['user']);
  238.         $new_portfolio $client->getPortfolioImages()."\n".$file;
  239.         $client->setPortfolioImages($new_portfolio);
  240.        // $client->setCredits($new_creds);
  241.         $this->getDoctrine()->getManager()->persist($client);
  242.         $this->getDoctrine()->getManager()->flush();
  243.         return new JsonResponse(str_replace($this->getParameter('public_dir'),
  244.                             $this->getParameter('url'),
  245.                             $file)
  246.         );
  247.     }
  248.     public function rotateImage(Request $request$direction)
  249.     {
  250.         $img $request->get('image');
  251.         $path str_replace("https://fusionmng.com/""/usr/share/nginx/fusion/public/"$img);
  252.         Image::configure(array('driver' => 'imagick'));
  253.         $workImage Image::make($path);
  254.         if($direction == 'right'$workImage->rotate(-90);
  255.         if($direction == 'left'$workImage->rotate(90);
  256.         $workImage->save($path100);
  257.         //do thumb
  258.         $fname basename($path);
  259.         $thumb str_replace($fname"thumb_".$fname$path);
  260.         if(is_file($thumb)) {
  261.             $workImage Image::make($thumb);
  262.             if($direction == 'right'$workImage->rotate(-90);
  263.             if($direction == 'left'$workImage->rotate(90);
  264.             $workImage->save($thumb);
  265.         }
  266.         return new JsonResponse(['done']);
  267.     }
  268.     public function saveImage(Request $request) {
  269.         //dd();
  270.         $base64img str_replace('data:image/jpeg;base64,'''$request->request->all()['img_data']);
  271.         $base64img str_replace('data:image/png;base64,'''$base64img);
  272.         $data base64_decode($base64img);
  273.         $replaced str_replace("new/public/port_images/","thumbs/",$request->request->all()['img_id']);
  274.         $replaced str_replace("https://fusionmng.com/","/usr/share/nginx/fusion/public/"$replaced);
  275.         $replaced str_replace("http://fusionmng.com/","/usr/share/nginx/fusion/public/"$replaced);
  276.         $image_location str_replace("https://fusionmng.com/","/usr/share/nginx/fusion/public/"$replaced);
  277.         $thumb_location str_replace("port_images/","port_images/thumb_"$replaced);
  278. //        dump($replaced);
  279. //        dump($image_location);
  280. //        dump($thumb_location);
  281. //        dump($request->request->all()['img_id']);
  282. //        die;
  283. //        $is = $this->container->get('image_service');
  284.         Image::configure(array('driver' => 'imagick'));
  285.         $image Image::make($data);
  286.         $image2 Image::make($data);
  287.         $image->resize(15001500, function ($constraint) {
  288.             $constraint->aspectRatio();
  289.             $constraint->upsize();
  290.         });
  291.         $image->save($image_location100);
  292.         $image2->resize(200200, function ($constraint) {
  293.             $constraint->aspectRatio();
  294.             $constraint->upsize();
  295.         });
  296.         $image2->crop(200200
  297.         );
  298.         $image2->save($thumb_location100);
  299.         return new Response($request->request->all()['img_id']);
  300.     }
  301.     public function addFeaturedImage(Request $requestImageService $image_service) {
  302.         //dd();
  303.         $base64img str_replace('data:image/jpeg;base64,'''$request->request->all()['img_data']);
  304.         $base64img str_replace('data:image/png;base64,'''$base64img);
  305.         $data base64_decode($base64img);
  306.         $mainPicLocation =  $this->getParameter('portfolio_images_dir').
  307.             time().".jpg";
  308.         ;
  309.         Image::configure(array('driver' => 'imagick'));
  310.         $mainPic Image::make($data);
  311.         $mainPic->save($mainPicLocation);
  312. //
  313.         $mainPic->resize(450450, function ($constraint) {
  314.             $constraint->aspectRatio();
  315.         });
  316.         $mainPic->crop(400400);
  317. //        $mainPic =  $mainPic->save($mainPicLocation);
  318.         $thumbLocation str_replace("port_images/","port_images/thumb_",$mainPicLocation);
  319.         $mainPic->save($thumbLocation);
  320.         $image_service->resize_to_fit($mainPicLocation);
  321. //        dump($thumbLocation);
  322. //        dump($mainPicLocation);
  323. //        die;
  324.         //var_dump($base64img);
  325.         /** @var Clients $client */
  326.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  327.             ->find($request->request->all()['user']);
  328.         //$new_portfolio = $client->featured_image."\n".$mainPicLocation;
  329.         $client->setFeaturedImage($mainPicLocation);
  330.         $client->setAdminImage($thumbLocation);
  331.         // $client->setCredits($new_creds);
  332.         $this->getDoctrine()->getManager()->persist($client);
  333.         $this->getDoctrine()->getManager()->flush();
  334.         return
  335.             new JsonResponse(
  336.                 str_replace($this->getParameter('public_dir'),'https://fusionmng.com',$mainPicLocation)
  337.             );
  338.     }
  339.     public function addCredits(Request $request){
  340.         $credit = new Credits();
  341. //        $credit->company_name = $request->request->all()['company_name'];
  342. //        $credit->description = $request->request->all()['description'];
  343.         $credit->setCompanyName($request->request->all()['company_name'] ?? $credit->getCompanyName());
  344.         $credit->setDescription($request->request->all()['description'] ?? $credit->getDescription());
  345.         $credit->setProductionName($request->request->all()['production_name'] ?? $credit->getProductionName());
  346.         $credit->setProductionYear($request->request->all()['production_year'] ?? $credit->getProductionYear());
  347.         $credit->setProductionType($request->request->all()['production_type'] ?? $credit->getProductionType());
  348.         $credit->setRole($request->request->all()['role'] ?? $credit->getRole());
  349.         $credit->setRoleType($request->request->all()['role_type'] ?? $credit->getRoleType());
  350. //        $credit->setRoleName($request->request->all()['role_name'] ?? $credit->getRoleName());
  351.         $credit->setUserId($request->request->all()['user'] ?? $credit->getUserId());
  352.         /** @var Clients $client */
  353.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  354.             ->find($request->request->all()['user']);
  355.         $credit->setClient($client);
  356.         $client->addNewCredit($credit);
  357.         $this->getDoctrine()->getManager()->persist($credit);
  358.         $this->getDoctrine()->getManager()->flush();
  359.         $this->getDoctrine()->getManager()->persist($client);
  360.         $this->getDoctrine()->getManager()->flush();
  361.         return new JsonResponse($credit->getId());
  362.     }
  363.     public function removeTraining(Request $request){
  364.         $credit $this->getDoctrine()->getRepository('App\Entity\Trainings')->findOneById($request->request->all()['id']);
  365.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  366.             ->find($request->request->all()['user']);
  367.         $new_creds str_replace($credit->getId().',',''$client->getTrainings());
  368.         $client->setTrainings($new_creds);
  369.         $this->getDoctrine()->getManager()->remove($credit);
  370.         $this->getDoctrine()->getManager()->persist($client);
  371.         $this->getDoctrine()->getManager()->flush();
  372.     }
  373.     public function saveTraining(Request $request){
  374.         /** @var Trainings $credit */
  375.         $credit $this->getDoctrine()->getRepository('App\Entity\Trainings')->findOneById($request->request->all()['id']);
  376.         $credit->setTrainingType($request->get('training_type'));
  377.         $credit->setTrainingLocation($request->get('training_location'));
  378. //        $credit->set$request->request->all()['user'];
  379.         $this->getDoctrine()->getManager()->persist($credit);
  380.         $this->getDoctrine()->getManager()->flush();
  381.         return new JsonResponse($credit->getId());
  382.     }
  383.     public function addTraining(Request $request){
  384.         $credit = new Trainings();
  385.         $credit->setTrainingType($request->request->all()['training_type']);
  386.         $credit->setTrainingLocation($request->request->all()['training_location']);
  387.         $client $this->getDoctrine()->getManager()->getRepository('App\Entity\Clients')
  388.             ->find($request->request->all()['user']);
  389.         $credit->setClients($client);
  390.         $this->getDoctrine()->getManager()->persist($credit);
  391.         $this->getDoctrine()->getManager()->flush();
  392.         $new_creds $client->getTrainings()."".$credit->getId().",";
  393. //        dump('$new_creds', $new_creds);
  394. //        die;
  395.         $client->setTrainings($new_creds);
  396.         $this->getDoctrine()->getManager()->persist($client);
  397.         $this->getDoctrine()->getManager()->flush();
  398.         return new JsonResponse($credit->getId());
  399.     }
  400.     protected function getSettings() {
  401.         $settings $this->getDoctrine()->getRepository('App\Entity\SiteSetting')->findAll()[0];
  402.         return $settings;
  403.     }
  404.     public function showInvoice(Request $requestPdfService $pdfService$idClientsRepository $clientsRepo)
  405.     {
  406.         if(!$this->getUser()) {
  407.             die('');
  408.         }
  409.         if($this->getUser()) {
  410.                 if(!$this->getUser()->getIsAdmin()) {
  411.                     die('access error');
  412.                 }
  413.         }
  414. //        var_dump($id);
  415. //        die;
  416.         $client $clientsRepo
  417.             ->find($id);
  418.         $invoices $client->getInvoices();
  419.         if(count($invoices) > 0) {
  420.             $invoice $invoices->toArray()[0];
  421. //            dump($client->getId());
  422. //            dump($invoice->getId());
  423. //            $id = "12497";
  424.             $invoiceFile "/usr/share/nginx/fusion/public/pdfs_invoices/{$id}_page.html";
  425.             if(is_file($invoiceFile)) {
  426.                 $content file_get_contents($invoiceFile);
  427.                 return new Response($content);
  428.             } else {
  429.                 return new Response("Can't find invoice");
  430.             }
  431.         }
  432.         die;
  433. //        $response = new BinaryFileResponse($pdf);
  434. //        $response->setContentDisposition(
  435. //            ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  436. //            $userNicename.".pdf"
  437. //        );
  438.     }
  439.     public function generatePdf(Request $requestPdfService $pdfService$userNicenameClientsRepository $clientsRepo)
  440.     {
  441.         $client $clientsRepo
  442.             ->findOneBy(array('userNicename' => $userNicename));
  443.         if($client->getIsArchived() == true) {
  444.             return $this->redirect("https://fusionmng.com"301);
  445.         }
  446.         
  447.         $credits $this->getDoctrine()->getRepository('App\Entity\Credits')
  448.             ->findBy(array('userId' => $client->getId()));
  449.         $trainings $this->getDoctrine()->getRepository('App\Entity\Trainings')
  450.             ->findBy(array('id' => $client->getTrainings()));
  451.         $talent_groups $this->getDoctrine()->getRepository('App\Entity\TalentGroup')->findAll();
  452.         $content =
  453.             $this->render('/new/client_public_pdf.html.twig', ['talent_groups' => $talent_groups'client' => $client'credits' => $credits'trainings' => $trainings'settings' => $this->getSettings()] );
  454.         if(isset($_GET["dourl"])) {
  455.             echo $content;
  456.             die;
  457.         }
  458.         $pdf $pdfService->generate_url($content->getContent(), $userNicename);
  459.         $response = new BinaryFileResponse($pdf);
  460.         $response->setContentDisposition(
  461.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  462.             $userNicename.".pdf"
  463.         );
  464.         return $response;
  465.     }
  466.     public function generatePdfSignature(Request $request$userNicenameClientsRepository $clientsRepo)
  467.     {
  468.         $client $clientsRepo
  469.             ->findOneBy(array('userNicename' => $userNicename));
  470.         return $this->render('pdf_head.html.twig', ['client' => $client]);
  471.     }
  472.     public function makeClientPermanent(ClientsRepository $clientsRepo$id)
  473.     {
  474.         $client $clientsRepo->find($id);
  475.         $client->setIsPermanent(true);
  476.         $em $this->getDoctrine()->getManager();
  477.         $em->persist($client);
  478.         $em->flush();
  479.         return new JsonResponse(['ok']);
  480.     }
  481.     const CONTENT_TYPE 'image/gif';
  482.     public function setExpiryEmailToRead(ClientsRepository $clientsRepo$id)
  483.     {
  484. //        die('ss');
  485. //        $pdf = $pdfService->generate_url($content->getContent(), $userNicename);
  486.         $client $clientsRepo->find($id);
  487.         $client->setIsExpiryEmailRead(true);
  488.         $em $this->getDoctrine()->getManager();
  489.         $em->persist($client);
  490.         $em->flush();
  491.         $img "/usr/share/nginx/fusion/public/logo5px.png";
  492.         $response = new BinaryFileResponse($img);
  493.         $response->setContentDisposition(
  494.             ResponseHeaderBag::DISPOSITION_INLINE,
  495.             "$id.gif"
  496.         );
  497.         $response->headers->set('Content-Type''image/png');
  498.         $response->headers->addCacheControlDirective('no-cache'true);
  499.         $response->headers->addCacheControlDirective('must-revalidate'true);
  500. //        die("done");
  501. //        die($content->getContent());
  502.         return $response;
  503.     }
  504.     public function clientExpiryStayAction(ClientsRepository $clientsRepository$clientId)
  505.     {
  506.         /** @var Clients $client */
  507.         $client $clientsRepository->find($clientId);
  508.         if ($client) {
  509.             $em $this->getDoctrine()->getManager();
  510.             $client->setIsStaying(null);
  511.             $client->setExpireActionId(null);
  512.             $client->setExpiryDate(null);
  513.             $client->setIsExpiryEmailRead(null);
  514.             $client->setIsExpiryNotificationSent(null);
  515.             $client->setIsLeaving(null);
  516. //            $date_of_expiry  = \DateTime::createFromFormat("Y-m-d H:i:s", $client->getUserRegistered());
  517.             $date_of_expiry  = new \DateTime('now');
  518.             $date_of_expiry->modify("+2 years");
  519.             $client->setExpiryDate($date_of_expiry);
  520. //                        $date_of_expiry2  = \DateTime::createFromFormat("Y-m-d H:i:s", $client->getUserRegistered());
  521.             $client->setUserRegistered((new \DateTime('now'))->format("Y-m-d H:i:s"));
  522.             $client->setExpireActionId(null);
  523.             $client->setIsExpiryEmailRead(null);
  524.             $client->setIsExpiryNotificationSent(null);
  525.             $client->setIsStaying(null);
  526.             $client->setIsLeaving(null);
  527. //            dump($client);
  528. //        var_dump($clientId);
  529. //
  530.             $em->persist($client);
  531.             $em->flush();
  532.         }
  533.         return new RedirectResponse($_SERVER['HTTP_REFERER']);
  534.     }
  535.     public function clientExpiryAction(ClientsRepository $clientsRepo$expiry_id$expiry_action)
  536.     {
  537.         if(!$this->getUser()) {
  538.             die("Please <A href='https://fusionmng.com/login'>log-in first in here </A>.");
  539.         }
  540.         $em $this->getDoctrine()->getManager();
  541.         $client $clientsRepo->findOneBy(['expire_action_id' => $expiry_id]);
  542. //        die($expiry_id);
  543.         if($client->getId() !== $this->getUser()->getId()) {
  544.             if(!$this->getUser()->getIsAdmin()) {
  545.                 die("Access Denied");
  546.             }
  547.         }
  548.         if($expiry_action == "stay") {
  549.             $client->setIsStaying(true);
  550.             $client->setIsLeaving(null);
  551.             $em->persist($client);
  552.             $em->flush();
  553.             return $this->render('new/stay-confirmed.html.twig');
  554.         } else {
  555.             $client->setIsLeaving(true);
  556.             $client->setIsStaying(null);
  557.             $em->persist($client);
  558.             $em->flush();
  559.             return $this->render('new/leave-confirmed.html.twig');
  560.         }
  561.         return new JsonResponse(['ok']);
  562.     }
  563. }