src/Controller/ClinicsController.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Addresses;
  4. use App\Entity\Baskets;
  5. use App\Entity\ClinicCommunicationMethods;
  6. use App\Entity\Clinics;
  7. use App\Entity\ClinicUserPermissions;
  8. use App\Entity\ClinicUsers;
  9. use App\Entity\CommunicationMethods;
  10. use App\Entity\Countries;
  11. use App\Entity\Distributors;
  12. use App\Entity\DistributorUsers;
  13. use App\Entity\Lists;
  14. use App\Entity\RestrictedDomains;
  15. use App\Entity\Species;
  16. use App\Entity\UserPermissions;
  17. use App\Form\AddressesFormType;
  18. use App\Form\ClinicCommunicationMethodsFormType;
  19. use App\Form\ClinicFormType;
  20. use App\Form\ClinicUsersFormType;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Nzo\UrlEncryptorBundle\Encryptor\Encryptor;
  23. use phpDocumentor\Reflection\Types\This;
  24. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  25. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  26. use Symfony\Component\HttpFoundation\HeaderUtils;
  27. use Symfony\Component\HttpFoundation\JsonResponse;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  31. use Symfony\Component\Mailer\MailerInterface;
  32. use Symfony\Component\Mime\Email;
  33. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  34. use Symfony\Component\Routing\Annotation\Route;
  35. class ClinicsController extends AbstractController
  36. {
  37.     const ITEMS_PER_PAGE 12;
  38.     private $em;
  39.     private $plainPassword;
  40.     private $encryptor;
  41.     private $mailer;
  42.     public function __construct(EntityManagerInterface $emEncryptor $encryptorMailerInterface $mailer) {
  43.         $this->em $em;
  44.         $this->encryptor $encryptor;
  45.         $this->mailer $mailer;
  46.     }
  47.     #[Route('/clinics/register'name'clinic_reg')]
  48.     public function clinicReg(Request $request): Response
  49.     {
  50.         $clinics = new Clinics();
  51.         $clinicUsers = new ClinicUsers();
  52.         $clinics->getClinicUsers()->add($clinicUsers);
  53.         $form $this->createForm(ClinicFormType::class, $clinics)->createView();
  54.         $countries $this->em->getRepository(Countries::class)->findBy([
  55.             'isActive' => 1,
  56.         ]);
  57.         return $this->render('frontend/clinics/register.html.twig', [
  58.             'form' => $form,
  59.             'countries' => $countries,
  60.         ]);
  61.     }
  62.     protected function createClinicForm()
  63.     {
  64.         $clinics = new Clinics();
  65.         return $this->createForm(ClinicFormType::class, $clinics);
  66.     }
  67.     public function createClinicsAddressesForm()
  68.     {
  69.         $methods = new Addresses();
  70.         return $this->createForm(AddressesFormType::class, $methods);
  71.     }
  72.     public function createClinicCommunicationMethodsForm()
  73.     {
  74.         $communicationMethods = new ClinicCommunicationMethods();
  75.         return $this->createForm(ClinicCommunicationMethodsFormType::class, $communicationMethods);
  76.     }
  77.     public function createClinicUserForm()
  78.     {
  79.         $clinicUsers = new ClinicUsers();
  80.         return $this->createForm(ClinicUsersFormType::class, $clinicUsers);
  81.     }
  82.     #[Route('/clinics/register/create'name'clinic_create')]
  83.     public function clinicsCreateAction(Request $requestUserPasswordHasherInterface $passwordHasherMailerInterface $mailer): Response
  84.     {
  85.         $data $request->request;
  86.         $clinics $this->em->getRepository(Clinics::class)->findOneBy(['hashedEmail' => md5($data->get('email'))]);
  87.         if($clinics == null) {
  88.             $clinics = new Clinics();
  89.             $plainTextPwd $this->generatePassword();
  90.             if (!empty($plainTextPwd)) {
  91.                 $domainName explode('@'$data->get('email'));
  92.                 $country $this->em->getRepository(Countries::class)->find($data->get('country'));
  93.                 $clinics->setClinicName($this->encryptor->encrypt($data->get('clinicName')));
  94.                 $clinics->setEmail($this->encryptor->encrypt($data->get('email')));
  95.                 $clinics->setHashedEmail(md5($data->get('email')));
  96.                 $clinics->setDomainName(md5($domainName[1]));
  97.                 $clinics->setTelephone($this->encryptor->encrypt($data->get('clinic-telephone')));
  98.                 $clinics->setIntlCode($this->encryptor->encrypt($data->get('clinic-intl-code')));
  99.                 $clinics->setIsoCode($this->encryptor->encrypt($data->get('clinic-iso-code')));
  100.                 $clinics->setCountry($country);
  101.                 $clinics->setIsApproved(0);
  102.                 $this->em->persist($clinics);
  103.                 $this->em->flush();
  104.                 // Create user
  105.                 $clinic $this->em->getRepository(Clinics::class)->findOneBy([
  106.                     'hashedEmail' => md5($data->get('email')),
  107.                 ]);
  108.                 $clinicUsers = new ClinicUsers();
  109.                 $hashedPwd $passwordHasher->hashPassword($clinicUsers$plainTextPwd);
  110.                 $clinicUsers->setClinic($clinic);
  111.                 $clinicUsers->setFirstName($this->encryptor->encrypt($data->get('firstName')));
  112.                 $clinicUsers->setLastName($this->encryptor->encrypt($data->get('lastName')));
  113.                 $clinicUsers->setPosition($this->encryptor->encrypt($data->get('position')));
  114.                 $clinicUsers->setEmail($this->encryptor->encrypt($data->get('email')));
  115.                 $clinicUsers->setHashedEmail(md5($data->get('email')));
  116.                 $clinicUsers->setTelephone($this->encryptor->encrypt($data->get('user-telephone')));
  117.                 $clinicUsers->setIntlCode($this->encryptor->encrypt($data->get('clinic-intl-code')));
  118.                 $clinicUsers->setIsoCode($this->encryptor->encrypt($data->get('clinic-iso-code')));
  119.                 $clinicUsers->setRoles(['ROLE_CLINIC']);
  120.                 $clinicUsers->setPassword($hashedPwd);
  121.                 $clinicUsers->setIsPrimary(1);
  122.                 $this->em->persist($clinicUsers);
  123.                 // Assign Full Permissions
  124.                 $userPermissions $this->em->getRepository(UserPermissions::class)->findBy([
  125.                     'isClinic' => 1,
  126.                 ]);
  127.                 foreach($userPermissions as $userPermission){
  128.                     $clinicUserPermissions = new ClinicUserPermissions();
  129.                     $clinicUserPermissions->setClinic($clinic);
  130.                     $clinicUserPermissions->setUser($clinicUsers);
  131.                     $clinicUserPermissions->setPermission($userPermission);
  132.                     $this->em->persist($clinicUserPermissions);
  133.                 }
  134.                 // Create Default Basket
  135.                 $basket = new Baskets();
  136.                 $firstName $this->encryptor->decrypt($clinicUsers->getFirstName());
  137.                 $lastName $this->encryptor->decrypt($clinicUsers->getLastName());
  138.                 $basket->setClinic($clinic);
  139.                 $basket->setName('Fluid Commerce');
  140.                 $basket->setTotal(0);
  141.                 $basket->setStatus('active');
  142.                 $basket->setIsDefault(1);
  143.                 $basket->setSavedBy($this->encryptor->encrypt($firstName .' '$lastName));
  144.                 $this->em->persist($basket);
  145.                 // Create In App Communication Method
  146.                 $clinicCommunicationMethod = new ClinicCommunicationMethods();
  147.                 $communicationMethod $this->em->getRepository(CommunicationMethods::class)->find(1);
  148.                 $clinicCommunicationMethod->setClinic($clinic);
  149.                 $clinicCommunicationMethod->setCommunicationMethod($communicationMethod);
  150.                 $clinicCommunicationMethod->setSendTo($this->encryptor->encrypt($data->get('email')));
  151.                 $clinicCommunicationMethod->setIsDefault(1);
  152.                 $clinicCommunicationMethod->setIsActive(1);
  153.                 $this->em->persist($clinicCommunicationMethod);
  154.                 // Create Favourites List
  155.                 $favourite = new Lists();
  156.                 $favourite->setClinic($clinic);
  157.                 $favourite->setListType('favourite');
  158.                 $favourite->setName('Favourite Items');
  159.                 $favourite->setItemCount(0);
  160.                 $favourite->setIsProtected(1);
  161.                 $this->em->persist($favourite);
  162.                 $this->em->flush();
  163.                 // Send Email
  164.                 $body '<table style="padding: 8px; border-collapse: collapse; border: none; font-family: arial">';
  165.                 $body .= '<tr><td colspan="2">Hi '$this->encryptor->decrypt($clinicUsers->getFirstName()) .',</td></tr>';
  166.                 $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  167.                 $body .= '<tr><td colspan="2">Please use the credentials below login to the Fluid Backend.</td></tr>';
  168.                 $body .= '<tr><td colspan="2">&nbsp;</td></tr>';
  169.                 $body .= '<tr>';
  170.                 $body .= '    <td><b>URL: </b></td>';
  171.                 $body .= '    <td><a href="https://'$_SERVER['HTTP_HOST'] .'/clinics/login">https://'$_SERVER['HTTP_HOST'] .'/clinics/login</a></td>';
  172.                 $body .= '</tr>';
  173.                 $body .= '<tr>';
  174.                 $body .= '    <td><b>Username: </b></td>';
  175.                 $body .= '    <td>'$this->encryptor->decrypt($clinicUsers->getEmail()) .'</td>';
  176.                 $body .= '</tr>';
  177.                 $body .= '<tr>';
  178.                 $body .= '    <td><b>Password: </b></td>';
  179.                 $body .= '    <td>'$plainTextPwd .'</td>';
  180.                 $body .= '</tr>';
  181.                 $body .= '</table>';
  182.                 $subject 'Fluid Login Credentials';
  183.                 $to $data->get('email');
  184.                 exec(__DIR__ '/../../bin/console app:send-email "'$subject .'" "'addslashes($body) .'" "'$to .'" "'serialize([]) .'" "'serialize([]) .'" "'true .'" > /dev/null 2>&1 &');
  185.             }
  186.             $response 'Your Fluid account was successfully created, an email with your login credentials has been sent to your inbox.';
  187.         } else {
  188.             $response false;
  189.         }
  190.         return new JsonResponse($response);
  191.     }
  192.     #[Route('/clinics/register/check-email'name'clinic_check_email')]
  193.     public function clinicsCheckEmailAction(Request $request): Response
  194.     {
  195.         $email $request->request->get('email');
  196.         $domainName explode('@'$email);
  197.         $response['response'] = true;
  198.         $restrictedDomains $this->em->getRepository(RestrictedDomains::class)->arrayFindAll();
  199.         $firstName '';
  200.         foreach($restrictedDomains as $restrictedDomain)
  201.         {
  202.             if(md5($domainName[1]) == md5($restrictedDomain->getName()))
  203.             {
  204.                 $response['response'] = false;
  205.                 $response['restricted'] = true;
  206.                 return new JsonResponse($response);
  207.             }
  208.         }
  209.         $distributor $this->em->getRepository(Distributors::class)->findOneBy([
  210.             'hashedEmail' => md5($email),
  211.         ]);
  212.         $distributorDomain $this->em->getRepository(Distributors::class)->findOneBy([
  213.             'domainName' => md5($domainName[1]),
  214.         ]);
  215.         $distributorUsers $this->em->getRepository(DistributorUsers::class)->findOneBy([
  216.             'hashedEmail' => md5($email),
  217.         ]);
  218.         $clinic $this->em->getRepository(Clinics::class)->findOneBy([
  219.             'hashedEmail' => md5($email),
  220.         ]);
  221.         $clinicDomain $this->em->getRepository(Clinics::class)->findOneBy([
  222.             'domainName' => md5($domainName[1]),
  223.         ]);
  224.         $clinicUsers $this->em->getRepository(ClinicUsers::class)->findOneBy([
  225.             'hashedEmail' => md5($email),
  226.         ]);
  227.         if($clinicDomain != null)
  228.         {
  229.             $user $this->em->getRepository(ClinicUsers::class)->findOneBy([
  230.                 'clinic' => $clinicDomain->getId(),
  231.                 'isPrimary' => 1
  232.             ]);
  233.             $firstName $this->encryptor->decrypt($user->getFirstName());
  234.         }
  235.         if($distributorDomain != null)
  236.         {
  237.             $user $this->em->getRepository(DistributorUsers::class)->findOneBy([
  238.                 'distributor' => $distributorDomain->getId(),
  239.                 'isPrimary' => 1
  240.             ]);
  241.             $firstName $this->encryptor->decrypt($user->getFirstName());
  242.         }
  243.         $response['firstName'] = $firstName;
  244.         if($distributor != null || $distributorUsers != null || $clinic != null || $clinicUsers != null || $clinicDomain != null || $distributorDomain != null){
  245.             $response['response'] = false;
  246.         }
  247.         return new JsonResponse($response);
  248.     }
  249.     #[Route('/clinics/user/check-email'name'clinic_user_check_email')]
  250.     public function clinicsUserCheckEmailAction(Request $request): Response
  251.     {
  252.         $email $request->request->get('email');
  253.         $domainName explode('@'$email);
  254.         $response['response'] = true;
  255.         $restrictedDomains $this->em->getRepository(RestrictedDomains::class)->arrayFindAll();
  256.         $firstName '';
  257.         foreach($restrictedDomains as $restrictedDomain)
  258.         {
  259.             if(md5($domainName[1]) == md5($restrictedDomain->getName()))
  260.             {
  261.                 $response['response'] = false;
  262.                 $response['restricted'] = true;
  263.                 return new JsonResponse($response);
  264.             }
  265.         }
  266.         $distributor $this->em->getRepository(Distributors::class)->findOneBy([
  267.             'hashedEmail' => md5($email),
  268.         ]);
  269.         $distributorDomain $this->em->getRepository(Distributors::class)->findOneBy([
  270.             'domainName' => md5($domainName[1]),
  271.         ]);
  272.         $distributorUsers $this->em->getRepository(DistributorUsers::class)->findOneBy([
  273.             'hashedEmail' => md5($email),
  274.         ]);
  275.         $clinicUsers $this->em->getRepository(ClinicUsers::class)->findOneBy([
  276.             'hashedEmail' => md5($email),
  277.         ]);
  278.         if($distributorDomain != null)
  279.         {
  280.             $user $this->em->getRepository(DistributorUsers::class)->findOneBy([
  281.                 'distributor' => $distributorDomain->getId(),
  282.                 'isPrimary' => 1
  283.             ]);
  284.             $firstName $this->encryptor->decrypt($user->getFirstName());
  285.         }
  286.         $response['firstName'] = $firstName;
  287.         if($distributor != null || $distributorUsers != null || $clinicUsers != null || $distributorDomain != null){
  288.             $response['response'] = false;
  289.         }
  290.         return new JsonResponse($response);
  291.     }
  292.     #[Route('/clinics/update/personal-information'name'clinic_update_personal_information')]
  293.     public function clinicsUpdatePersonalInformationAction(Request $request): Response
  294.     {
  295.         $data $request->request;
  296.         $username $this->get('security.token_storage')->getToken()->getUser()->getUserIdentifier();
  297.         $clinics $this->em->getRepository(Clinics::class)->findOneBy(['email' => $username]);
  298.         if($clinics != null) {
  299.             $clinics->setFirstName($data->get('first_name'));
  300.             $clinics->setLastName($data->get('last_name'));
  301.             $clinics->setTelephone($data->get('telephone'));
  302.             $clinics->setPosition($data->get('position'));
  303.             $this->em->persist($clinics);
  304.             $this->em->flush();
  305.             $response '<b><i class="fa-solid fa-circle-check"></i></i></b> Personal details successfully updated.<div class="flash-close"><i class="fa-solid fa-xmark"></i></div>';
  306.         } else {
  307.             $response '<b><i class="fas fa-check-circle"></i> Personal details successfully updated.<div class="flash-close"><i class="fa-solid fa-xmark"></i></div>';
  308.         }
  309.         return new JsonResponse($response);
  310.     }
  311.     #[Route('/clinics/update/company-information'name'clinic_update_company_information')]
  312.     public function clinicsUpdateCompanyInformationAction(Request $request): Response
  313.     {
  314.         $data $request->request->get('clinic_form');
  315.         $clinicId $this->getUser()->getClinic()->getId();
  316.         $clinics $this->em->getRepository(Clinics::class)->find($clinicId);
  317.         $isApproved = (bool) $clinics->getIsApproved() ?? false;
  318.         $tradeLicense $_FILES['clinic_form']['name']['trade-license-file'];
  319.         $tradeLicenseNo $data['trade-license-no'];
  320.         $tradeLicenseExpDate $data['trade-license-exp-date'];
  321.         // Account approval required if reg docs change
  322.         if(
  323.             !empty($tradeLicense) || $tradeLicenseNo != $this->encryptor->decrypt($clinics->getTradeLicenseNo()) ||
  324.             $tradeLicenseExpDate != $clinics->getTradeLicenseExpDate()->format('Y-m-d')
  325.         )
  326.         {
  327.             $clinics->setIsApproved(0);
  328.             $isApproved false;
  329.         }
  330.         if($clinics != null)
  331.         {
  332.             $domainName explode('@'$data['email']);
  333.             $clinics->setClinicName($this->encryptor->encrypt($data['clinic-name']));
  334.             $clinics->setEmail($this->encryptor->encrypt($data['email']));
  335.             $clinics->setDomainName(md5($domainName[1]));
  336.             $clinics->setTelephone($this->encryptor->encrypt($data['telephone']));
  337.             $clinics->setIsoCode($this->encryptor->encrypt($data['iso-code']));
  338.             $clinics->setIntlCode($this->encryptor->encrypt($data['intl-code']));
  339.             $clinics->setManagerFirstName($this->encryptor->encrypt($data['manager-first-name']));
  340.             $clinics->setManagerLastName($this->encryptor->encrypt($data['manager-last-name']));
  341.             $clinics->setManagerIdNo($this->encryptor->encrypt($data['manager-id-no']));
  342.             $clinics->setManagerIdExpDate(new \DateTime($data['manager-id-exp-date']));
  343.             $clinics->setTradeLicenseNo($this->encryptor->encrypt($data['trade-license-no']));
  344.             $clinics->setTradeLicenseExpDate(new \DateTime($data['trade-license-exp-date']));
  345.             // Trade License
  346.             if(!empty($_FILES['clinic_form']['name']['trade-license-file']))
  347.             {
  348.                 $extension pathinfo($_FILES['clinic_form']['name']['trade-license-file'], PATHINFO_EXTENSION);
  349.                 $file $clinics->getId() . '-' uniqid() . '.' $extension;
  350.                 $targetFile __DIR__ '/../../public/documents/' $file;
  351.                 if(move_uploaded_file($_FILES['clinic_form']['tmp_name']['trade-license-file'], $targetFile)) {
  352.                     $clinics->setTradeLicense($file);
  353.                 }
  354.             }
  355.             // Logo
  356.             if(!empty($_FILES['clinic_form']['name']['logo']))
  357.             {
  358.                 $extension pathinfo($_FILES['clinic_form']['name']['logo'], PATHINFO_EXTENSION);
  359.                 $file $clinics->getId() . '-' uniqid() . '.' $extension;
  360.                 $targetFile __DIR__ '/../../public/images/logos/' $file;
  361.                 if(move_uploaded_file($_FILES['clinic_form']['tmp_name']['logo'], $targetFile)) {
  362.                     $clinics->setLogo($file);
  363.                 }
  364.             }
  365.             $this->em->persist($clinics);
  366.             $this->em->flush();
  367.             // Send Approval Email
  368.             if(!$isApproved)
  369.             {
  370.                 $orderUrl $this->getParameter('app.base_url') . '/admin/clinic/'$clinics->getId();
  371.                 $html '<p>Please <a href="'$orderUrl .'">click here</a> the clinics details.</p><br>';
  372.                 $html $this->forward('App\Controller\ResetPasswordController::emailFooter', [
  373.                     'html'  => $html,
  374.                 ])->getContent();
  375.                 $subject 'Fluid - Account Approval Request';
  376.                 $to $this->getParameter('app.email_admin');
  377.                 exec(__DIR__ '/../../bin/console app:send-email "'$subject .'" "'addslashes($html) .'" "'$to .'" "'serialize([]) .'" "'serialize([]) .'" "'true .'" > /dev/null 2>&1 &');
  378.             }
  379.             $response '<b><i class="fa-solid fa-circle-check"></i></i></b> Company details successfully updated.<div class="flash-close"><i class="fa-solid fa-xmark"></i></div>';
  380.         }
  381.         else
  382.         {
  383.             $response '<b><i class="fas fa-check-circle"></i> An error occurred.<div class="flash-close"><i class="fa-solid fa-xmark"></i></div>';
  384.         }
  385.         return new JsonResponse($response);
  386.     }
  387.     #[Route('/clinics/update/copy'name'clinic_update_copy')]
  388.     public function clinicsUpdateCopyAction(Request $request): Response
  389.     {
  390.         $response = [];
  391.         if($this->getUser() == null)
  392.         {
  393.             return new JsonResponse('Please login..');
  394.         }
  395.         $clinic $this->getUser()->getClinic();
  396.         $copy $request->request->get('copy');
  397.         $method $request->request->get('method');
  398.         $clinic->$method($copy);
  399.         $this->em->persist($clinic);
  400.         $this->em->flush();
  401.         $response['flash'] = '<b><i class="fa-solid fa-circle-check"></i></i></b> Successfully saved.<div class="flash-close"><i class="fa-solid fa-xmark"></i></div>';
  402.         return new JsonResponse($response);
  403.     }
  404.     #[Route('/clinics/get-company-information'name'get_clinic_company_information')]
  405.     public function clinicsGetCompanyInformationAction(Request $request): Response
  406.     {
  407.         $species $this->em->getRepository(Species::class)->findByNameAsc();
  408.         $permissions json_decode($request->request->get('permissions'), true);
  409.         $countries $this->em->getRepository(Countries::class)->findBy([
  410.             'isActive' => 1,
  411.         ]);
  412.         $clinic $this->em->getRepository(Clinics::class)->find($this->getUser()->getClinic()->getId());
  413.         $response $this->render('frontend/clinics/company_information.html.twig', [
  414.             'permissions' => $permissions,
  415.             'species' => $species,
  416.             'countries' => $countries,
  417.             'clinic' => $clinic,
  418.         ])->getContent();
  419.         return new JsonResponse($response);
  420.     }
  421.     #[Route('/clinics/addresse-refresh'name'clinic_refresh_addresses')]
  422.     public function clinicRefreshAddressesAction(Request $request): Response
  423.     {
  424.         $clinicId $this->get('security.token_storage')->getToken()->getUser()->getClinic()->getId();
  425.         $methods $this->em->getRepository(Clinics::class)->getClinicAddresses($clinicId);
  426.         $html '';
  427.         foreach($methods[0]->getAddresses() as $address){
  428.             $class 'address-icon';
  429.             if($address->getIsDefault() == 1){
  430.                 $class 'is-default-address-icon';
  431.             }
  432.             $html .= '<div class="row t-row">
  433.                     <div class="col-md-10" id="string_address_clinic_name_'$address->getId() .'">
  434.                         <div class="row">
  435.                             <div class="col-md-2 t-cell text-truncate" id="string_address_clinic_name_'$address->getId() .'">
  436.                                 '$address->getClinicName() .'
  437.                             </div>
  438.                             <div class="col-md-2 t-cell text-truncate" id="string_address_telephone_'$address->getId() .'">
  439.                                 '$address->getTelephone() .'
  440.                             </div>
  441.                             <div class="col-md-4 t-cell text-truncate" id="string_address_address_'$address->getId() .'">
  442.                                 '$address->getAddress() .'
  443.                             </div>
  444.                             <div class="col-md-2 t-cell text-truncate" id="string_address_city_'$address->getId() .'">
  445.                                 '$address->getCity() .'
  446.                             </div>
  447.                             <div class="col-md-2 t-cell text-truncate" id="string_address_state_'$address->getId() .'">
  448.                                 '$address->getState() .'
  449.                             </div>
  450.                         </div>
  451.                     </div>
  452.                     <div class="col-md-2" id="string_address_postal)_code'$address->getId() .'">
  453.                         <div class="row">
  454.                             <div class="col-md-4 t-cell text-truncate" id="string_address_postal_code'$address->getId() .'">
  455.                                 '$address->getPostalCode() .'
  456.                             </div>
  457.                             <div class="col-md-8 t-cell">
  458.                                 <a href="" class="float-end" data-bs-toggle="modal" data-bs-target="#modal_address" id="address_update_'$address->getId() .'">
  459.                                     <i class="fa-solid fa-pen-to-square edit-icon"></i>
  460.                                 </a>
  461.                                 <a href="" class="delete-icon float-end" data-bs-toggle="modal" data-value="'$address->getId() .'" data-bs-target="#modal_address_delete" id="address_delete_'$address->getId() .'">
  462.                                     <i class="fa-solid fa-trash-can"></i>
  463.                                 </a>
  464.                                 <a href="#" id="address_default_'$address->getId() .'">
  465.                                     <i class="fa-solid fa-star float-end '$class.'"></i>
  466.                                 </a>
  467.                             </div>
  468.                         </div>
  469.                     </div>
  470.                 </div>';
  471.         }
  472.         return new JsonResponse($html);
  473.     }
  474.     #[Route('/clinics/communication-refresh'name'clinic_refresh_communication')]
  475.     public function clinicRefreshCommunicationMethodsAction(Request $request): Response
  476.     {
  477.         $clinicId $this->get('security.token_storage')->getToken()->getUser()->getClinic()->getId();
  478.         $methods $this->em->getRepository(Clinics::class)->getClinicCommunicationMethods($clinicId);
  479.         $html '';
  480.         //dd($methods[0]->getClinicCommunicationMethods());
  481.         foreach($methods[0]->getClinicCommunicationMethods() as $method){
  482.             $html .= '
  483.             <div class="row t-row">
  484.                 <div class="col-md-4 t-cell text-truncate" id="">
  485.                     '$method->getCommunicationMethod()->getMethod() .'
  486.                 </div>
  487.                 <div class="col-md-4 t-cell text-truncate" id="">
  488.                     '$method->getSendTo() .'
  489.                 </div>
  490.                 <div class="col-md-4 t-cell text-truncate" id="">
  491.                     <a href="" class="float-end" data-bs-toggle="modal" data-bs-target="#modal_communication_methods" id="communication_method_update_'$method->getId() .'">
  492.                         <i class="fa-solid fa-pen-to-square edit-icon"></i>
  493.                     </a>
  494.                     <a href="" class="delete-icon float-end" data-bs-toggle="modal" data-value="'$method->getId() .'" data-bs-target="#modal_method_delete" id="method_delete_'$method->getId() .'">
  495.                         <i class="fa-solid fa-trash-can"></i>
  496.                     </a>
  497.                 </div>
  498.             </div>';
  499.         }
  500.         return new JsonResponse($html);
  501.     }
  502.     #[Route('/clinics/download/trade-license/{tradeLicense}'name'clinics_download_trade_license')]
  503.     public function downloadTradeLicenseAction(Request $request)
  504.     {
  505.         $path __DIR__ '/../../public/documents/';
  506.         $tradeLicense $path $request->get('tradeLicense');
  507.         $response = new BinaryFileResponse($tradeLicense);
  508.         $response->setContentDisposition(
  509.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  510.             basename($tradeLicense)
  511.         );
  512.         return $response;
  513.     }
  514.     #[Route('/clinics/error'name'clinic_error_500')]
  515.     public function clinic500ErrorAction(Request $request): Response
  516.     {
  517.         $username $this->getUser();
  518.         $id '';
  519.         if($username != null) {
  520.             $id $this->getUser()->getClinic()->getId();
  521.         }
  522.         return $this->render('bundles/TwigBundle/Exception/error500.html.twig', [
  523.             'type' => 'clinics',
  524.             'id' => $id,
  525.         ]);
  526.     }
  527.     private function generatePassword()
  528.     {
  529.         $sets = [];
  530.         $sets[] = 'abcdefghjkmnpqrstuvwxyz';
  531.         $sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ';
  532.         $sets[] = '23456789';
  533.         $sets[] = '!@$%*?';
  534.         $all '';
  535.         $password '';
  536.         foreach ($sets as $set) {
  537.             $password .= $set[array_rand(str_split($set))];
  538.             $all .= $set;
  539.         }
  540.         $all str_split($all);
  541.         for ($i 0$i 16 count($sets); $i++) {
  542.             $password .= $all[array_rand($all)];
  543.         }
  544.         $this->plainPassword str_shuffle($password);
  545.         return $this->plainPassword;
  546.     }
  547. }