src/Controller/MainController.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Accounting;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  9. use App\Repository\UserRepository;
  10. use App\Repository\PropertyListRepository;
  11. use App\Repository\PropertyDetailsRepository;
  12. use App\Repository\PotentialClientsRepository;
  13. use App\Entity\PropertyList;
  14. use App\Entity\Broker;
  15. use App\Entity\Landlords;
  16. use App\Entity\PotentialClients;
  17. use App\Entity\PropertyDetails;
  18. use App\Entity\User;
  19. use App\Entity\Tenants;
  20. use App\Form\NewUserType;
  21. use App\Form\NewPropertyType;
  22. use App\Form\NewPropertyDetailsType;
  23. use App\Form\PotentialClientsType;
  24. use App\Form\PropertyFilterType;
  25. use Doctrine\ORM\EntityManagerInterface;
  26. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  27. use Vich\UploaderBundle\Handler\UploadHandler;
  28. use App\Repository\AccountingRepository;
  29. use App\Repository\BrokerRepository;
  30. use App\Repository\InterestsRepository;
  31. use App\Repository\LandlordsRepository;
  32. use App\Repository\TenantsRepository;
  33. use App\Service\OperacionesCPPoblacionesYProvincias;
  34. use Flasher\Prime\Flasher;
  35. use Flasher\Symfony\FlasherSymfonyBundle;
  36. use Flasher\Toastr\Symfony\FlasherToastrSymfonyBundle;
  37. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  38. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  39. use Symfony\Component\Form\Extension\Core\Type\TextType;
  40. use Symfony\Component\Security\Core\Security;
  41. use Pagerfanta\Pagerfanta;
  42. use Pagerfanta\Adapter\ArrayAdapter;
  43. use Symfony\Component\HttpFoundation\JsonResponse;
  44. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  45. class MainController extends AbstractController
  46. {
  47.     
  48.     #[Route(path:'/',  name:'app_start_page')]
  49.     public function startPage(): Response
  50.     {
  51.         return $this->render('immobiliaria.html.twig');
  52.     }
  53.     #[Route(path:'/politicaDePrivacidad'name"app_politica_privacidad_immo")]
  54.     public function politicaPrivacidadImmo():response
  55.     {
  56.         return $this->render('politicaDePrivacidadImmo.html.twig');
  57.     }
  58.     #[Route('/immobiliaria'name:"app_homepage")]
  59.     public function homepage(): Response
  60.     {
  61.         return $this->render('homepage.html.twig', [
  62.             "name"=>"HomepageController",
  63.         ]);
  64.     }
  65.     #[Route('/loggedout'name:"logout")]
  66.     public function logout(): Response
  67.     {
  68.         return $this->render('logout.html.twig', [
  69.             "name"=>"LogoutController",
  70.         ]);
  71.     }
  72.    
  73.     #[Route('/about'name:"app_about")]
  74.     public function about(): Response
  75.     {
  76.         return $this->render('about.html.twig', [
  77.             "name"=>"AboutUsController",
  78.         ]);
  79.     }
  80.     
  81.     #[Route('/contact'name'app_contact')]
  82.     public function contact(Request $request, ): Response
  83.     {
  84.         $form $this->createFormBuilder()
  85.             ->add('name',TextType::class,[
  86.                 'label'=>'Nombre'
  87.             ])
  88.             ->add('email'EmailType::class)
  89.             ->add('message'TextareaType::class)
  90.             ->getForm();
  91.         $form->handleRequest($request);
  92.         if ($form->isSubmitted() && $form->isValid()) {
  93.             $data=$form->getData();
  94.             /*
  95.             $email= (new Email())
  96.                 ->from($data['email'])
  97.                 ->to('your-email@example.com')
  98.                 ->subject('New Contact Form Submission')
  99.                 ->text('From: ' . $data['name'] . ' (' . $data['email'] . ")\n\n" . $data['message']);
  100.             $mailer->send($email);
  101.             */
  102.             
  103.             // Redirect or show a success message
  104.             $this->addFlash('success''Tu mensaje ha sido enviado!');
  105.             return $this->redirectToRoute('contact');
  106.         }
  107.         return $this->render('contact.html.twig', [
  108.             'controller_name' => 'ContactController',
  109.             'form'=>$form->createView(),
  110.         ]);
  111.     }
  112.     #[Route('/properties/{idp}/info'name'app_info')]
  113.     public function info(Request $request,
  114.     PropertyListRepository $plr,
  115.     PotentialClientsRepository $ptr,
  116.     int $idp
  117.     ): Response
  118.     {
  119.         $property=$plr->find($idp);
  120.         if (!$property) {
  121.             return $this->render('errors/notfound.html.twig',[
  122.                 'property'=>$property,
  123.             ]);
  124.         }
  125.         $user=$this->getUser();
  126.         $email=$user->getEmail();
  127.         $name=$user->getFirstName();
  128.         $surname=$user->getLastName();
  129.         $number=$user->getPhoneNumber();
  130.         $buildingNumber=$user->getPropertyNumber();
  131.         /*
  132.         $data=[
  133.             'name'=>$name,
  134.             'surname'=>$surname,
  135.             'email'=>$email,
  136.             'number'=>$number,
  137.             'buildingNumber'=>$buildingNumber,
  138.         ];
  139.         */
  140.         $potential $ptr->findOneBy(['potentialEmail' => $email]);
  141.         
  142.         if ($potential) {
  143.             
  144.             $form $this->createForm(PotentialClientsType::class, $potential,[
  145.                 //'data'=>$data,
  146.             ]);
  147.         } else {
  148.             
  149.             $potential = new PotentialClients();
  150.             $data=$this->setPotentialData($potential,$user);
  151.             
  152.             $form $this->createForm(PotentialClientsType::class, $potential,[
  153.                 //'data'=>$data,
  154.             ]);
  155.         }
  156.         $form->handleRequest($request);
  157.             
  158.         if ($form->isSubmitted() && $form->isValid()) { 
  159.             $potential->addProperty($property);
  160.             $ptr->save($potential,true);
  161.             $this->addFlash(
  162.             'success',
  163.             'Mensaje Enviado Correctamente.'
  164.             );
  165.         }
  166.     
  167.         return $this->render('info.html.twig',[
  168.             'form'=>$form->createView(),
  169.             'property'=>$property,
  170.         ]);
  171.     }
  172.     #[Route('/user'name'app_user')]
  173.     public function index(): Response
  174.     {
  175.         
  176.         return $this->render('user/index.html.twig', [
  177.             'name' => 'UserController',
  178.         ]);
  179.     }
  180.     public function __construct(UrlGeneratorInterface $urlGeneratorSecurity $security)
  181.     {
  182.         
  183.     }
  184. /*
  185.     #[Route('/userbyadmin', name: 'admin_newuser')]
  186.     public function newUserByAdmin(UserPasswordHasherInterface $userPasswordHasherInterface, UserRepository $userRepository,
  187.     AccountingRepository $accountingRepository,
  188.     BrokerRepository $brokerRepository,
  189.     LandlordsRepository $landlordsRepository,
  190.     TenantsRepository $tenantsRepository,
  191.      Request $request)
  192.     {
  193.         
  194.         if (!$this->isGranted('ROLE_BROKER')) {
  195.             throw $this->createAccessDeniedException('No access for you! Check your credentials with the ADMIN. Thank you.');
  196.         }
  197.         $user=new User();
  198.         $form = $this->createForm(NewUserType::class, $user);
  199.         $form->handleRequest($request);
  200.         
  201.         if ($form->isSubmitted() && $form->isValid()) { 
  202.             
  203.         }
  204.     }
  205.     */
  206.         private function setLandlordData(Landlords $landlordUser $user)
  207.         {
  208.             $landlord
  209.                 ->setLandlordName($user->getFirstName() ?? '')
  210.                 ->setLandlordSurname($user->getLastName() ?? '')
  211.                 ->setLandlordPhone($user->getPhoneNumber() ?? '')
  212.                 ->setLandlordEmail($user->getEmail() ?? '')
  213.                 ->setLandlordAddress($user->getUserAddress() ?? '')
  214.                 ->setLandlordCity($user->getUserCity() ?? '')
  215.                 ->setLandlordPostcode($user->getUserPostcode() ?? '')
  216.                 ->setCreatedAt(new \DateTimeImmutable());
  217.         }
  218.         private function setAccountantData(Accounting $accountantUser $user)
  219.         {
  220.             $accountant->setAccountingName($user->getFirstName() ?? '');
  221.             $accountant->setAccountingSurname($user->getLastName() ?? '');
  222.             $accountant->setAccountingEmail($user->getEmail() ?? '');
  223.             $accountant->setAccountingPhone($user->getPhoneNumber() ?? '');
  224.         }
  225.         private function setBrokerData(Broker $brokerUser $user)
  226.         {
  227.             $broker
  228.                 ->setBrokerName($user->getFirstName() ?? '')
  229.                 ->setBrokerSurname($user->getLastName() ?? '')
  230.                 ->setBrokerPhone($user->getPhoneNumber() ?? '')
  231.                 ->setBrokerEmail($user->getEmail() ?? '');
  232.         }
  233.         private function setTenantData(Tenants $tenantUser $user)
  234.         {
  235.             $tenant
  236.                 ->setTenantName($user->getFirstName() ?? '')
  237.                 ->setTenantSurname($user->getLastName() ?? '')
  238.                 ->setTenantPhone($user->getPhoneNumber() ?? "")
  239.                 ->setTenantEmail($user->getEmail() ?? '')
  240.                 ->setTenantAddress($user->getUserAddress() ?? '')
  241.                 ->setBuildingNumber($user->getPropertyNumber() ?? '')
  242.                 ->setProvince($user->getProvince() ?? '')
  243.                 ->setFloor($user->getFloor() ?? '')
  244.                 ->setBloque($user->getBloque() ?? '')
  245.                 ->setEscalera($user->getEscalera() ?? '')
  246.                 ->setApartmentNumber($user->getFlatNumber()?? '')
  247.                 ->setTenantCity($user->getUserCity() ?? '')
  248.                 ->setTenantPostcode($user->getUserPostcode() ?? '')
  249.                 ->setStatus(true)
  250.                 ->setCreatedAt(new \DateTimeImmutable());
  251.                 
  252.         }
  253.         private function setPotentialData(PotentialClients $potentialClientUser $user)
  254.         {
  255.             /*
  256.             $potentialClient
  257.                 ->setUsers($user)
  258.                 ->setPotentialName($user->getFirstName() ?: ' ')
  259.                 ->setPotentialSurname($user->getLastName() ?: ' ')
  260.                 ->setPotentialNumber($user->getPhoneNumber() ?: ' ')
  261.                 ->setPotentialEmail($user->getEmail() ?: '')
  262.                 ->setPotentialAddress($user->getUserAddress() ?: ' VACÍO')
  263.                 ->setBuildingNumber($user->getPropertyNumber() ?: ' ')
  264.                 ->setProvince($user->getProvince() ?: ' ')
  265.                 ->setFloor($user->getFloor() ?: ' ')
  266.                 ->setBloque($user->getBloque() ?: ' ')
  267.                 ->setEscalera($user->getEscalera() ?: ' ')
  268.                 ->setApartmentNumber($user->getFlatNumber() ?: ' ')
  269.                 ->setPotentialCity($user->getUserCity() ?: ' ')
  270.                 ->setPotentialPostcode($user->getUserPostcode() ?: ' ');
  271.                 //->setPotentialIban('VACÍO');
  272.             */
  273.             $potentialClient
  274.                 ->setStatus(true)
  275.                 ->setCreatedAt(new \DateTimeImmutable());
  276.             $properties = [
  277.                 'potentialName' => $user->getFirstName(),
  278.                 'potentialSurname' => $user->getLastName(),
  279.                 'potentialNumber' => $user->getPhoneNumber(),
  280.                 'potentialEmail' => $user->getEmail(),
  281.                 'potentialAddress' => $user->getUserAddress(),
  282.                 'buildingNumber'=> $user->getPropertyNumber(),
  283.                 'province'=> $user->getProvince(),
  284.                 'floor'=> $user->getFloor(),
  285.                 'bloque'=> $user->getBloque(),
  286.                 'escalera'=> $user->getEscalera(),
  287.                 'apartmentNumber'=> $user->getFlatNumber(),
  288.                 'potentialCity'=> $user->getUserCity(),
  289.                 'potentialPostcode'=> $user->getUserPostcode(),
  290.                 // Add more properties as needed
  291.             ];
  292.         
  293.             foreach ($properties as $property => $value) {
  294.                 if ($value !== null && $value !== '') {
  295.                     $potentialClient->{'set' ucfirst($property)}($value);
  296.                 }
  297.             }
  298.         }
  299.         private function processUserRoles(User $user,
  300.         array $roles,
  301.         LandlordsRepository $landlordsRepository,
  302.         AccountingRepository $accountingRepository,
  303.         BrokerRepository $brokerRepository,
  304.         TenantsRepository $tenantsRepository)
  305.         {
  306.             foreach ($roles as $role) {
  307.                 switch ($role) {
  308.                     case 'ROLE_LANDLORD':
  309.                         $landlord = new Landlords();
  310.                         $this->setLandlordData($landlord$user);
  311.                         $user->setLandlord($landlord);
  312.                         $landlordsRepository->save($landlordtrue);
  313.                         break;
  314.                     case 'ROLE_ACCOUNTANT':
  315.                         $accountant = new Accounting();
  316.                         $this->setAccountantData($accountant$user);
  317.                         $user->setAccountant($accountant);
  318.                         $accountingRepository->save($accountanttrue);
  319.                         break;
  320.                     case 'ROLE_BROKER':
  321.                         $broker = new Broker();
  322.                         $this->setBrokerData($broker$user);
  323.                         $user->setBroker($broker);
  324.                         $brokerRepository->save($brokertrue);
  325.                         break;
  326.                     case 'ROLE_TENANT':
  327.                         $tenant = new Tenants();
  328.                         $this->setTenantData($tenant$user);
  329.                         $user->setTenant($tenant);
  330.                         $tenantsRepository->save($tenanttrue);
  331.                         break;
  332.                 }
  333.             }
  334.         }
  335.         private function processUserType(User $user,
  336.         ?array $userTypes,
  337.         LandlordsRepository $landlordsRepository,
  338.         AccountingRepository $accountingRepository,
  339.         BrokerRepository $brokerRepository,
  340.         TenantsRepository $tenantsRepository)
  341.         {
  342.             if (!is_array($userTypes)) {
  343.                 return;
  344.             }
  345.             foreach ($userTypes as $userType) {
  346.                 switch ($userType) {
  347.                     case 'ROLE_LANDLORD':
  348.                         $landlord = new Landlords();
  349.                         $this->setLandlordData($landlord$user);
  350.                         $user->setLandlord($landlord);
  351.                         $landlordsRepository->save($landlordtrue);
  352.                         break;
  353.         
  354.                     case 'ROLE_ACCOUNTANT':
  355.                         $accountant = new Accounting();
  356.                         $this->setAccountantData($accountant$user);
  357.                         $user->setAccountant($accountant);
  358.                         $accountingRepository->save($accountanttrue);
  359.                         break;
  360.         
  361.                     case 'ROLE_BROKER':
  362.                         $broker = new Broker();
  363.                         $this->setBrokerData($broker$user);
  364.                         $user->setBroker($broker);
  365.                         $brokerRepository->save($brokertrue);
  366.                         break;
  367.         
  368.                     case 'ROLE_TENANT':
  369.                         $tenant = new Tenants();
  370.                         $this->setTenantData($tenant$user);
  371.                         $user->setTenant($tenant);
  372.                         $tenantsRepository->save($tenanttrue);
  373.                         break;
  374.                 }
  375.             }
  376.         }
  377.         #[Route('/newpotential'name'app_newpotential')]
  378.         public function newPotential(
  379.         UserPasswordHasherInterface $userPasswordHasherInterface,
  380.         UserRepository $userRepository,
  381.         AccountingRepository $accountingRepository,
  382.         BrokerRepository $brokerRepository,
  383.         LandlordsRepository $landlordsRepository,
  384.         TenantsRepository $tenantsRepository,
  385.         Request $request,
  386.         PotentialClientsRepository $ptr
  387.         ) {
  388.                     $user = new User();
  389.                     $userForm $this->createForm(NewUserType::class,$user);
  390.                     $userForm->handleRequest($request);
  391.         
  392.                     if ($userForm->isSubmitted() && $userForm->isValid()) {
  393.                         //$user = $userForm->getData();
  394.                         $password $userForm->get('password')->getData();
  395.         
  396.                         if ($password === null) {
  397.                             return;
  398.                         }
  399.         
  400.                         $hash $userPasswordHasherInterface->hashPassword($user$password);
  401.                         $user->setPassword($hash);
  402.                         $potential= new PotentialClients();
  403.                     
  404.                         $potential->setUsers($user);
  405.                         $this->setPotentialData($potential$user);
  406.                         $potential->setCreatedAt(new \DateTimeImmutable('now'));
  407.                         $potential->setStatus(true);
  408.                         //$user->setPotentialClient($potential);
  409.                         $ptr->save($potential,true);
  410.                         
  411.                         $user->setCreatedAt(new \DateTime('now'));
  412.                         
  413.                         
  414.                         $userType $userForm->get('userType')->getData();
  415.                         if (!$userType) {
  416.                             $user->setUserType(null);
  417.                         } else {
  418.                             $this->processUserType($user$userType$landlordsRepository$accountingRepository$brokerRepository$tenantsRepository);
  419.                         }
  420.                         $userRepository->save($usertrue);
  421.                         $this->addFlash(
  422.                             'success',
  423.                             'Usuario Creado Correctamente.'
  424.                         );
  425.                         return $this->redirectToRoute("app_properties");
  426.                         
  427.                         
  428.                 }
  429.                 return $this->render("/user/newuser.html.twig", [
  430.                     "user_form" => $userForm->createView()
  431.                 ]);
  432.             }
  433.         
  434.         #[Route('/newuser'name'app_newuser')]
  435.         public function newUser(
  436.         UserPasswordHasherInterface $userPasswordHasherInterface,
  437.         UserRepository $userRepository,
  438.         AccountingRepository $accountingRepository,
  439.         BrokerRepository $brokerRepository,
  440.         LandlordsRepository $landlordsRepository,
  441.         TenantsRepository $tenantsRepository,
  442.         Request $request,
  443.         PotentialClientsRepository $ptr,
  444.         SessionInterface $session
  445.         ) {
  446.                 $referer=$request->headers->get('referer');
  447.                 $refererPath=parse_url($referer,PHP_URL_PATH);
  448.                 if ($refererPath==="/properties") {
  449.                     $user = new User();
  450.                     $userForm $this->createForm(NewUserType::class,$user);
  451.                     $userForm->handleRequest($request);
  452.                     if ($userForm->isSubmitted() && $userForm->isValid()) {
  453.                         //$user = $userForm->getData();
  454.                         $password $userForm->get('password')->getData();
  455.         
  456.                         if ($password === null) {
  457.                             return;
  458.                         }
  459.         
  460.                         $hash $userPasswordHasherInterface->hashPassword($user$password);
  461.                         $user->setPassword($hash);
  462.                         $potential= new PotentialClients();
  463.                     
  464.                         $potential->setUsers($user);
  465.                         $this->setPotentialData($potential$user);
  466.                         $potential->setCreatedAt(new \DateTimeImmutable('now'));
  467.                         $potential->setStatus(true);
  468.                         //$user->setPotentialClient($potential);
  469.                         //$ptr->save($potential,true);
  470.                         $user->setCreatedAt(new \DateTime('now'));
  471.                         $userType $userForm->get('userType')->getData();
  472.                         if (!$userType) {
  473.                             $user->setUserType(null);
  474.                         } else {
  475.                             $this->processUserType($user$userType$landlordsRepository$accountingRepository$brokerRepository$tenantsRepository);
  476.                         }
  477.                         $userRepository->save($usertrue);
  478.                         $this->addFlash(
  479.                             'success',
  480.                             'Usuario Creado Correctamente.'
  481.                         );
  482.                         return $this->redirectToRoute("app_properties");
  483.                     }
  484.                 } else {
  485.                     $userForm $this->createForm(NewUserType::class);
  486.                     /*$userForm->add('broker',BrokerType::class,[
  487.                         'label'=>'Comercial',
  488.                     ]);
  489.                     */
  490.                     $userForm->handleRequest($request);
  491.         
  492.                     if ($userForm->isSubmitted() && $userForm->isValid()) {
  493.                         $user $userForm->getData();
  494.                         $password $userForm->get('password')->getData();
  495.         
  496.                         if ($password === null) {
  497.                             return;
  498.                         }
  499.         
  500.                         $hash $userPasswordHasherInterface->hashPassword($user$password);
  501.                         $user->setPassword($hash);
  502.                         $user->setCreatedAt(new \DateTime('now'));
  503.                         
  504.                         $userType $userForm->get('userType')->getData();
  505.                         
  506.                         if ($userForm->has('roles')) {
  507.                             $roles $userForm->get('roles')->getData();
  508.                             $this->processUserRoles($user$roles$landlordsRepository$accountingRepository$brokerRepository$tenantsRepository);
  509.                         } else {
  510.                             $this->processUserType($user$userType$landlordsRepository$accountingRepository$brokerRepository$tenantsRepository);
  511.                             
  512.                         }  
  513.                         if (in_array('ROLE_BROKER'$user->getRoles())) {
  514.                             $broker $user->getBroker();
  515.                             
  516.                             //$manager = $userForm->get('broker')->get('manager')->getData();
  517.                             $manager $userForm->get('broker')->getData();
  518.                             //dd($manager);
  519.                             //die;
  520.                             if ($manager) {
  521.                                 $managerId=$manager->getId();
  522.                             
  523.                                 $manager1 $brokerRepository->find($managerId);
  524.                                 $broker->setManager($manager1);
  525.                                 
  526.                                 $brokerRepository->save($broker,true);
  527.                             }
  528.                            
  529.                         }
  530.                         if ($userType) {
  531.                             $userId=$user->getId();
  532.                             $userRepository->save($usertrue);
  533.                             /*
  534.                             if ($userType ==='ROLE_LANDLORD') {
  535.                                 return $this->redirectToRoute('landlord_profile',['idl'=>$userId]);
  536.                             } elseif ($userType==='ROLE_TENANT') {
  537.                                 return $this->redirectToRoute('tenant_profile',['idt'=>$userId]);
  538.                             } elseif ($userType==='ROLE_POTENTIAL') {
  539.                                 return $this->redirectToRoute('potential_profile',['idp'=>$userId]);
  540.                             } else {
  541.                                 return $this->redirectToRoute("app_homepage");
  542.                             }
  543.                             $this->addFlash(
  544.                                 'success',
  545.                                 'Usuario Creado Correctamente.'
  546.                             );
  547.                            */
  548.                             $userRepository->save($usertrue);
  549.                             return $this->redirectToRoute("app_homepage");
  550.                             //$this->addFlash('success', 'Usuario Creado Correctamente.');
  551.                         } else {
  552.                         
  553.                             $user->setUserType(null);
  554.                             $userRepository->save($usertrue);
  555.                             return $this->redirectToRoute("app_homepage");
  556.                             //$this->addFlash('success', 'Usuario Creado Correctamente.');
  557.                         }
  558.                     }
  559.                 }
  560.                 return $this->render("/user/newuser.html.twig", [
  561.                     "user_form" => $userForm->createView()
  562.                 ]);
  563.         }
  564.         /*
  565.         #[Route('/newuser', name: 'app_newuser')]
  566.         public function newUser(UserPasswordHasherInterface $userPasswordHasherInterface, UserRepository $userRepository,
  567.         AccountingRepository $accountingRepository,
  568.         BrokerRepository $brokerRepository,
  569.         LandlordsRepository $landlordsRepository,
  570.         TenantsRepository $tenantsRepository,
  571.         Request $request)
  572.         {
  573.         
  574.         $user_form=$this->createForm(NewUserType::class);
  575.         $user_form->handleRequest($request);
  576.         if($user_form->isSubmitted() && $user_form->isValid()){
  577.             $user=$user_form->getData();
  578.             
  579.             $password = $user_form->get('password')->getData();
  580.             if ($password === null) 
  581.             {
  582.                 return;
  583.             }
  584.             $hash = $userPasswordHasherInterface->hashPassword($user, $password);
  585.             $user->setPassword($hash);
  586.             //$user->setRoles(['ROLE_USER']);
  587.             $user->setCreatedAt(new \DateTime('now'));
  588.             
  589.            
  590.             //$userRepository->save($user, true);
  591.             if ($user_form->has('roles')) {
  592.                 
  593.             
  594.                 $roles=$user_form->get('roles')->getData();
  595.                 //$otherRoles = array_diff($roles, ['ROLE_USER']);
  596.                 if (!empty($roles)) {
  597.                     foreach ($roles as $role) {
  598.                         if ($role === 'ROLE_LANDLORD') {
  599.                             $landlord = new Landlords();
  600.                             
  601.                             $landlord->setLandlordName($user->getFirstName() ?? '');
  602.                             $landlord->setLandlordSurname($user->getLastName()?? '');
  603.                             $landlord->setLandlordPhone($user->getPhoneNumber()?? '');
  604.                             
  605.                             $landlord->setLandlordEmail($user->getEmail()?? '');
  606.                             $landlord->setLandlordAddress($user->getUserAddress()?? '');
  607.                             $landlord->setLandlordCity($user->getUserCity()?? '');
  608.                             $landlord->setLandlordPostcode($user->getUserPostcode()?? '');
  609.                 
  610.                             // Associate the Landlord entity with the user
  611.                             $user->setLandlord($landlord);
  612.                             $landlordsRepository->save($landlord,true);
  613.                         } elseif ($role === 'ROLE_ACCOUNTANT') {
  614.                             $accountant = new Accounting();
  615.                             
  616.                             $accountant->setAccountingName($user->getFirstName()?? '');
  617.                             $accountant->setAccountingSurname($user->getLastName()?? '');
  618.                             $accountant->setAccountingEmail($user->getEmail()?? '');
  619.                             $accountant->setAccountingPhone($user->getPhoneNumber()?? '');
  620.                             
  621.                             $user->setAccountant($accountant);
  622.                             $accountingRepository->save($accountant,true)             ;
  623.                         } elseif ($role === 'ROLE_BROKER') {
  624.                             $broker = new Broker();
  625.                 
  626.                             $broker->setBrokerName($user->getFirstName()?? '');
  627.                             $broker->setBrokerSurname($user->getLastName()?? '');
  628.                             $broker->setBrokerPhone($user->getPhoneNumber()?? '');
  629.                             $broker->setBrokerEmail($user->getEmail()?? '');
  630.                                         
  631.                             $user->setBroker($broker);
  632.                             $brokerRepository->save($broker,true);
  633.                         } elseif ($role === 'ROLE_TENANT') {
  634.                             $tenant = new Tenants();
  635.                             $tenant->setTenantName($user->getFirstName());
  636.                             $tenant->setTenantSurname($user->getLastName());
  637.                             $tenant->setTenantPhone($user->getPhoneNumber());
  638.                             $tenant->setTenantEmail($user->getEmail());
  639.                             $user->setTenant($tenant);
  640.                             $tenantsRepository->save($tenant,true);
  641.                         }
  642.                     }
  643.                 }
  644.             } else {
  645.                 
  646.             // Retrieve the user's selected userType from the form data
  647.             $userType = $user_form->get('userType')->getData();
  648.     
  649.             
  650.             if ($userType === 'ROLE_LANDLORD') {
  651.                
  652.                 $landlord = new Landlords();
  653.                 
  654.                 $landlord->setLandlordName($user->getFirstName() ?? '');
  655.                 $landlord->setLandlordSurname($user->getLastName()?? '');
  656.                 $landlord->setLandlordPhone($user->getPhoneNumber()?? '');
  657.                 
  658.                 $landlord->setLandlordEmail($user->getEmail()?? '');
  659.                 $landlord->setLandlordAddress($user->getUserAddress()?? '');
  660.                 $landlord->setLandlordCity($user->getUserCity()?? '');
  661.                 $landlord->setLandlordPostcode($user->getUserAddressPostcode()?? '');
  662.     
  663.                 // Associate the Landlord entity with the user
  664.                 $user->setLandlord($landlord);
  665.                 $landlordsRepository->save($landlord,true);
  666.             } else if ($userType === 'ROLE_BROKER') {
  667.                 // Create a new Broker entity object
  668.                 $broker = new Broker();
  669.     
  670.                 $broker->setBrokerName($user->getFirstName()?? '');
  671.                 $broker->setBrokerSurname($user->getLastName()?? '');
  672.                 $broker->setBrokerPhone($user->getPhoneNumber()?? '');
  673.                 $broker->setBrokerEmail($user->getEmail()?? '');
  674.                             
  675.                 $user->setBroker($broker);
  676.                 $brokerRepository->save($broker,true);
  677.             } else if ($userType === 'ROLE_ACCOUNTANT') {
  678.                 $accountant = new Accounting();
  679.                 
  680.                 $accountant->setAccountingName($user->getFirstName()?? '');
  681.                 $accountant->setAccountingSurname($user->getLastName()?? '');
  682.                 $accountant->setAccountingEmail($user->getEmail()?? '');
  683.                 $accountant->setAccountingPhone($user->getPhoneNumber()?? '');
  684.                 $user->setAccounting($accountant);
  685.                 $accountingRepository->save($accountant,true)             ;
  686.                 
  687.             }  else if ($userType === 'ROLE_TENANT') {
  688.                 $tenant = new Tenants();
  689.                 $tenant->setTenantName($user->getFirstName());
  690.                 $tenant->setTenantSurname($user->getLastName());
  691.                 $tenant->setTenantPhone($user->getPhoneNumber());
  692.                 $tenant->setTenantEmail($user->getEmail());
  693.                 $user->setTenant($tenant);
  694.                 $tenantsRepository->save($tenant,true);
  695.             } 
  696.             
  697.             if (!$userType) {
  698.                 $user->setUserType(null);
  699.             }
  700.         }
  701.             
  702.             $userRepository->save($user, true);  
  703.             
  704.               
  705.             return $this->redirectToRoute("app_login");
  706.         }
  707.         return $this->render("/user/newuser.html.twig",[
  708.         "user_form" => $user_form->createView() 
  709.     ])
  710.     ;
  711.        
  712.     }
  713.     */
  714.     
  715. /*
  716.     public function filterProperties(UrlGeneratorInterface $urlGenerator, Request $request, PropertyListRepository $plr,)
  717.     {
  718.         $queryBuilder = $this->$plr->createQueryBuilder('p');
  719.         if ($this->isGranted('ROLE_BROKER')) {
  720.             // Add filters based on form fields
  721.             if ($request->query->get('reference')) {
  722.                 $queryBuilder->andWhere('p.reference = :reference')
  723.                     ->setParameter('reference', $request->query->get('reference'));
  724.             }
  725.             
  726.             if ($request->query->get('propertyAddress')) {
  727.                 $queryBuilder->andWhere('p.propertyAddress = :propertyAddress')
  728.                     ->setParameter('propertyAddress', $request->query->get('propertyAddress'));
  729.             }
  730.         } else {
  731.             if ($request->query->get('property_city')) {
  732.                 $queryBuilder->andWhere('p.property_city = :property_city')
  733.                     ->setParameter('property_city', $request->query->get('property_city'));
  734.             }
  735.             
  736.             if ($request->query->get('propertyType')) {
  737.                 $queryBuilder->andWhere('p.propertyType = :propertyType')
  738.                     ->setParameter('propertyType', $request->query->get('propertyType'));
  739.             }
  740.             
  741.             if ($request->query->get('subType')) {
  742.                 $queryBuilder->andWhere('p.subType = :subType')
  743.                     ->setParameter('subType', $request->query->get('subType'));
  744.             }
  745.             
  746.             if ($request->query->get('property_price')) {
  747.                 $queryBuilder->andWhere('p.property_price <= :property_price')
  748.                     ->setParameter('property_price', $request->query->get('property_price'));
  749.             }
  750.             
  751.             if ($request->query->get('furnished')) {
  752.                 $queryBuilder->andWhere('p.furnished = :furnished')
  753.                     ->setParameter('furnished', $request->query->get('furnished') === 'true');
  754.             }
  755.             
  756.             if ($request->query->get('size')) {
  757.                 $queryBuilder->andWhere('p.size >= :min_size')
  758.                     ->setParameter('min_size', $request->query->get('size'));
  759.             }
  760.             
  761.             if ($request->query->get('rentalType')) {
  762.                 $queryBuilder->andWhere('p.rentalType = :rentalType')
  763.                     ->setParameter('rentalType', $request->query->get('rentalType'));
  764.             }
  765.             
  766.             if ($request->query->get('deliveryType')) {
  767.                 $queryBuilder->andWhere('p.deliveryType = :deliveryType')
  768.                     ->setParameter('deliveryType', $request->query->get('deliveryType'));
  769.             }
  770.             
  771.             if ($request->query->get('precioAlquiler')) {
  772.                 $queryBuilder->andWhere('p.precioAlquiler <= :precioAlquiler')
  773.                     ->setParameter('precioAlquiler', $request->query->get('precioAlquiler'));
  774.             }
  775.             
  776.             if ($request->query->get('precioTraspaso')) {
  777.                 $queryBuilder->andWhere('p.precioTraspaso <= :precioTraspaso')
  778.                     ->setParameter('precioTraspaso', $request->query->get('precioTraspaso'));
  779.             }
  780.             if ($request->query->get('broker')) {
  781.                 $queryBuilder 
  782.                     ->join('p.managingAgent', 'b')
  783.                     ->andWhere('b.brokerid = :broker')
  784.                     ->setParameter('broker', $request->query->get('broker'));
  785.             }
  786.             
  787.             
  788.         
  789.         }
  790.         $properties = $queryBuilder->getQuery()->getResult();
  791.         
  792.         $filters = $request->query->all(); // Get all query parameters as filters
  793.         $url = $urlGenerator->generate('app_properties', $filters);
  794.         // The generated URL will include the filter values as query parameters
  795.         echo $url; // Outputs something like: /properties?type=rent&price_min=1000&price_max=2000&city=London
  796.     }
  797. */
  798.     #[Route('/properties/inactive'name:'app_properties_inactive')]
  799.     public function inactiveProperties(PropertyListRepository $pl): Response
  800.     {
  801.         $inactive=$pl->findBy(['status'=>'Inactivo']);
  802.         
  803.         return $this->render('property_list/inactive.html.twig', [
  804.             'properties' => $inactive,
  805.         ]);
  806.     }
  807.     #[Route('/properties'name'app_properties'methods: ['GET''POST'])]
  808.     public function properties(PropertyListRepository $propertyListRepositoryRequest $requestSessionInterface $session): Response
  809.     {
  810.         if(!$this->isGranted('ROLE_USER')){ return $this->redirectToRoute('app_login'); }
  811.         //$isBroker = $this->security->isGranted('ROLE_BROKER');
  812.         $isBroker $this->isGranted('ROLE_BROKER');
  813.         //$brokers=$propertyListRepository->getAllBrokers();
  814.     
  815.         $form $this->createForm(PropertyFilterType::class, ["status"=>"Activo"]);
  816.         $form->handleRequest($request);
  817.     
  818.         // Retrieve the filters from the session
  819.         $filters $session->get('property_filters', []);
  820.         $propertyList $propertyListRepository->createQueryBuilder('p')
  821.             ->where('LOWER(p.status) LIKE :status')
  822.             ->setParameter('status'strtolower('activo'))
  823.             ->getQuery()
  824.             ->getResult();
  825.         $totalCount count($propertyList);
  826.     /*
  827.         if ($isBroker) {
  828.             $propertyList = $propertyListRepository->createQueryBuilder('p')
  829.                 ->where('LOWER(p.status) LIKE :status')
  830.                 ->setParameter('status', strtolower('activo'))
  831.                 ->getQuery()
  832.                 ->getResult();
  833.             $totalCount = count($propertyList);
  834.         } else {
  835.             $propertyList = $propertyListRepository->createQueryBuilder('p')
  836.                 ->where('LOWER(p.status) LIKE :status')
  837.                 ->setParameter('status', strtolower('activo'))
  838.                 ->getQuery()
  839.                 ->getResult();
  840.             $totalCount = count($propertyList);
  841.         }
  842.     */
  843.          // Apply filters if submitted
  844.          if ($form->isSubmitted() && $form->isValid()) {
  845.             $filters $form->getData();
  846.             
  847.             // Store the filters in the session
  848.             $session->set('property_filters'$filters);
  849.             $propertyList $propertyListRepository->filterProperties($filters);
  850.             $totalCount count($propertyList);
  851.         }
  852.     
  853.         
  854.     
  855.         // Create a Pagerfanta adapter with the property list
  856.         $adapter = new ArrayAdapter($propertyList);
  857.         $paginator = new Pagerfanta($adapter);
  858.         $paginator->setMaxPerPage(20); // Display 20 properties per page
  859.     
  860.         // Get the current page from the request
  861.         //$page = $request->query->getInt('page', 1);
  862.         $page intval($request->query->get("property_filter")["page"] ?? 1);
  863.         if($page===0){ $page=1; }
  864.         $paginator->setCurrentPage($page);
  865.     
  866.         // Get the properties for the current page
  867.         $currentPageProperties $paginator->getCurrentPageResults();
  868.         
  869.     
  870.         return $this->render('property_page2.html.twig', [
  871.             'form' => $form->createView(),
  872.             'name' => 'PropertiesController',
  873.             'propertyList' => $currentPageProperties,
  874.             'totalCount' => $totalCount,
  875.             'currentPage' => $page,
  876.             'totalPages' => $paginator->getNbPages(),
  877.             'request'=>$request,
  878.             //'brokers'=>$brokers,
  879.         ]);
  880.     }
  881.     #[Route('/newproperty'name'app_newproperty')]
  882.     public function newProperty(PropertyListRepository $propertyListRepositoryRequest $request,
  883.     BrokerRepository $brokerRepository,
  884.     UploadHandler $uploadHandlerOperacionesCPPoblacionesYProvincias $opsPobs)
  885.     {
  886.         //try {
  887.         if (!$this->isGranted('ROLE_BROKER')) {
  888.             return $this->render('errors/access.html.twig',[
  889.                 
  890.             ]);
  891.         }
  892.         
  893.         $property = new PropertyList();
  894.         $property->setStatus("Inactivo");
  895.         $property->setTypePropertyAddress("Calle");
  896.         $property_form=$this->createForm(NewPropertyType::class, $property);
  897.         $property_form->handleRequest($request);
  898.         if($property_form->isSubmitted() && $property_form->isValid()){
  899.                 $property=$property_form->getData();
  900.                  /////          captador/vendedor/gestor add here
  901.                  
  902.                 $listingAgent $property_form->get('listingAgent')->getData();
  903.                 $managingAgent $property_form->get('managingAgent')->getData();
  904.                 $sellingAgent $property_form->get('sellingAgent')->getData();
  905.                 $property->setManagingAgent($managingAgent);
  906.                 $property->setListingAgent($listingAgent);
  907.                 $property->setSellingAgent($sellingAgent);
  908.                 //$brokerRepository->save($managingAgent, true);
  909.                 //$brokerRepository->save($listingAgent, true);
  910.                 /*
  911.                 if ($sellingAgent) {
  912.                     $brokerRepository->save($sellingAgent, true);
  913.                 }
  914.                 */
  915.                 
  916.                 $property->setCreatedAt(new \DateTimeImmutable());
  917.                 $property->setIdzona($opsPobs->getObjZona($property->getPostcode(), $property->getPropertyCity(), $property->getProvince(), $property->getBarrio(), $property_form->get("idZona")->getData() ?? "0"));
  918.                 $propertyListRepository->save($propertytrue);
  919.                 $id $property->getId();
  920.                 $this->addFlash("success""El inmueble ha sido añadido correctamente!");
  921.                 
  922.                 if ($request->request->has('exit')) {
  923.             
  924.                     return $this->redirectToRoute('more_details', [
  925.                         'id' => $id,
  926.                     ]);
  927.                 }
  928.         
  929.                 if ($request->request->has('save')) {
  930.                         
  931.                         return $this->redirectToRoute('app_newdetails', [
  932.                             'id' => $id,
  933.                         ]);
  934.                 }
  935.                 //return $this->redirectToRoute('app_newdetails', ['id' => $id]);            
  936.             }
  937.             // Check if the form has been submitted
  938.             if ($request->isMethod('POST') && $property_form->isValid()) {
  939.                 $disableSaveButton true;
  940.             } else {
  941.                 $disableSaveButton false;
  942.             }
  943.             return $this->render("/property_list/newproperty.html.twig", [
  944.                 "property_form" => $property_form->createView(),
  945.                 'disable'=>$disableSaveButton,
  946.                 
  947.             ]);
  948.             
  949.         }
  950.            
  951.     #[Route('/properties/{id}'name:"more_details", )]
  952.     public function moreDetails(EntityManagerInterface $entityManager,
  953.     int $id,
  954.     PropertyListRepository $plr
  955.     Request $request,
  956.     PotentialClientsRepository $pcr,
  957.     InterestsRepository $ir
  958.     )
  959.     {   
  960.         
  961.         if (!$this->isGranted('ROLE_USER')) {
  962.             return $this->render('errors/access.html.twig',[
  963.                 
  964.             ]);
  965.             //throw $this->createAccessDeniedException('No access for you! Check your credentials with the ADMIN. Thank you.');
  966.         }
  967.         $property=$entityManager->getRepository(PropertyList::class)->find($id);
  968.         if(!$property)
  969.         {
  970.             return $this->render('/errors/notfound.html.twig',[
  971.                 
  972.             ]);
  973.         }
  974.         // get the related PropertyDetails entity
  975.         $moreDetails $property->getPropertyDetails();
  976.         if(!$moreDetails) {
  977.             return $this->render('/errors/notfound.html.twig',[
  978.                 
  979.             ]);
  980.         }
  981.         $bedrooms$moreDetails->getBedrooms();
  982.         $landlords=$property->getLandlords();
  983.         $tenants=$property->getTenants();
  984.         $images=$property->getImages();
  985.         $percentages = [];
  986.         foreach ($landlords as $landlord) {
  987.             $percentages[$landlord->getId()] = $landlord->getPercentages();
  988.         }
  989.         $utilities=$property->getUtilities();
  990.         $docs $property->getDocuments();
  991.         $energy false;
  992.         $occupancy false;
  993.         
  994.         foreach ($docs as $doc) {
  995.             if ($doc->getEnergy() ||  $doc->getDocCategory()==="Certificado Eficiencia Energética" || $doc->getDocCategory()==="CEE & CEH") {
  996.                 $energy true;
  997.             }
  998.             if ($doc->getOccupancy() || $doc->getDocCategory()==="Cédula de Habitabilitad") {
  999.                 $occupancy true;
  1000.             }
  1001.         }
  1002.         $noDocs '';
  1003.         if ($energy && $occupancy) {
  1004.             $status=$property->getStatus();
  1005.             
  1006.             if (!$status=='en Captación') {   //Modificació Javier
  1007.                 //$property->setStatus('Activo');
  1008.                 //$plr->save($property, true);
  1009.             }
  1010.             
  1011.         } else {
  1012.             //$property->setStatus('Inactivo');   //Modificació Javier
  1013.             //$plr->save($property, true);
  1014.             if (!$energy && !$occupancy) {
  1015.                 $noDocs'Faltan el Certificado Energético y la Cédula de Habitabilidad.';
  1016.             } elseif (!$occupancy) {
  1017.                 $noDocs 'Falta la Cédula de Habitabilidad.';
  1018.             } else {
  1019.                 $noDocs'Faltan el Certificado Energético.';
  1020.             }
  1021.             
  1022.         }
  1023.         $user=$this->getUser();
  1024.         $useremail=$user->getEmail();
  1025.         $potential=$pcr->findOneBy(
  1026.             ['potentialEmail'=>$useremail]
  1027.         );
  1028.         
  1029.         if ($potential) {
  1030.             
  1031.             
  1032.             $form $this->createForm(PotentialClientsType::class, $potential,[
  1033.                 
  1034.             ]);
  1035.         } else {
  1036.             
  1037.             $potential = new PotentialClients();
  1038.             $this->setPotentialData($potential,$user);
  1039.             $form $this->createForm(PotentialClientsType::class, $potential);
  1040.         }
  1041.         $form->handleRequest($request);
  1042.             
  1043.         if ($form->isSubmitted() && $form->isValid()) { 
  1044.             //$interests=$form->getData()->getInterests();
  1045.           
  1046.             if ($request->isXmlHttpRequest()) {
  1047.                 $pcr->save($potential,true);
  1048.                 //flash()->addSuccess('Precerencias Actualizadas');
  1049.                 
  1050.             } else if ($request->request->has('send')) {
  1051.                 $potential->addProperty($property);
  1052.                 $pcr->save($potential,true);
  1053.                 flash()->addSuccess('Mensaje enviado correctamente');
  1054.             } else {
  1055.                 flash()->addError('Oopsie.Ha habido un problema');
  1056.             }
  1057.             
  1058.         }
  1059.        
  1060.         
  1061.         
  1062.         return $this->render('moreDetails.html.twig', [
  1063.             'property'=>$property,
  1064.             'moreDetails' => $moreDetails,
  1065.             'bedrooms'=>$bedrooms,
  1066.             'tenants'=>$tenants,
  1067.             'landlords'=>$landlords,
  1068.             'percentages'=>$percentages,
  1069.             'utilities'=>$utilities,
  1070.             'images'=>$images,
  1071.             'noDocs'=>$noDocs,
  1072.             'form'=>$form->createView(),
  1073.             
  1074.         ]);
  1075.     }
  1076.     
  1077. /*
  1078.     #[Route('/properties/{id}/edit-propertys' , name:"edit_propertys" ,methods:['GET','POST'])]
  1079.     public function edit(Request $request, $id, 
  1080.     PropertyListRepository $propertyListRepository,
  1081.     EntityManagerInterface $entityManager,
  1082.     PropertyDetailsRepository $propertyDetailsRepository,): Response
  1083.     {
  1084.         if (!$this->isGranted('ROLE_BROKER')) {
  1085.             throw $this->createAccessDeniedException('No access for you! Check your credentials with the ADMIN. Thank you.');
  1086.         }
  1087.         $property = $propertyListRepository->find($id);
  1088.         if (!$property) {
  1089.             throw $this->createNotFoundException('Property' . $id .' not found');
  1090.         }
  1091.         $property_id= $property->getId();
  1092.         $details=$property->getPropertyDetails();
  1093.         
  1094.         //$bedrooms=$property->getPropertyDetails()->getBedrooms();
  1095.         $form = $this->createForm(PropertyFormType::class, $property);
  1096.         $form->handleRequest($request);
  1097.         if ($form->isSubmitted() && $form->isValid()) {
  1098.             $propertyListRepository->save($property, true);
  1099.             $propertyDetailsRepository->save($details,true);
  1100.             return $this->redirectToRoute('edit_property', [
  1101.                 'id' => $property_id,
  1102.             ]);
  1103.         }
  1104.         return $this->render('aa/edit.html.twig', [
  1105.             'property_form' => $form->createView(),
  1106.         ]);
  1107.     }
  1108. */
  1109.     #[Route('/properties/{id}/edit-property' name:"edit_property" ,methods:['GET','POST'])]
  1110.     public function editProperty(Request $request
  1111.     $id,
  1112.     PropertyListRepository $propertyListRepository,
  1113.     PropertyDetailsRepository $propertyDetailsRepository,
  1114.     OperacionesCPPoblacionesYProvincias $opsPobs
  1115.     ) {
  1116.         if (!$this->isGranted('ROLE_BROKER')) {
  1117.             return $this->render('errors/access.html.twig',[
  1118.                 
  1119.             ]);
  1120.         }
  1121.         //$broker=$this->security->getUser()->getBroker();
  1122.         $broker=$this->getUser()->getBroker();
  1123.         $admin=$this->isGranted('ROLE_ADMIN');
  1124.         $property $propertyListRepository->find($id);
  1125.         if (!$property) {
  1126.             return $this->render('errors/notfound.html.twig',[
  1127.                 
  1128.             ]);
  1129.         }
  1130.         $managingAgent=$property->getManagingAgent();
  1131.         /*
  1132.         if (!$admin && $broker !== $managingAgent && $broker !== $property->getListingAgent()) {
  1133.             return $this->render('errors/access.html.twig',[
  1134.                 
  1135.             ]);
  1136.         } else {
  1137.         */
  1138.             $property_id$property->getId();
  1139.         
  1140.             $details $property->getPropertyDetails();
  1141.             $type=$property->getPropertyType();
  1142.             $subtype=$property->getSubType();
  1143.             //$bedrooms= $details->getBedrooms();
  1144.             //$landlords = $property->getLandlords();
  1145.             //$tenants = $property->getTenants();
  1146.             //$images = $property->getImages();
  1147.             //$videos = $property->getVideos();
  1148.             //$documents = $property->getDocuments();
  1149.             $detailsForm $this->createForm(NewPropertyDetailsType::class, $details);
  1150.             $detailsForm->handleRequest($request);
  1151.             
  1152.             if ($detailsForm->isSubmitted() && $detailsForm->isValid()) { 
  1153.                 
  1154.                 $double=$detailsForm->get('doubleBed')->getData() ?? '0';
  1155.                 $single=$detailsForm->get('singleBed')->getData() ?? '0';
  1156.                 $bedrooms=$details->setBedroomNumber($double+$single);
  1157.                 
  1158.                 $details->setPropertyList($property);
  1159.                 $propertyDetailsRepository->save($details,true); 
  1160.             }
  1161.             $propertyForm $this->createForm(NewPropertyType::class, $property);
  1162.             $propertyForm->get("idZona")->setData($property->getIdzona()!== null $property->getIdzona()->getId() : "" );
  1163.             $propertyForm->handleRequest($request);
  1164.             if ($propertyForm->isSubmitted() && $propertyForm->isValid()) { 
  1165.                 //$property=$propertyForm->getData();
  1166.                 $property->setIdzona($opsPobs->getObjZona($property->getPostcode(), $property->getPropertyCity(), $property->getProvince(), $property->getBarrio(), $propertyForm->get("idZona")->getData() ?? "0"));
  1167.                 $propertyListRepository->save($property,true);
  1168.                 $this->addFlash(
  1169.                     'success',
  1170.                     'Inmueble modificado correctamente!'
  1171.                 );
  1172.             
  1173.                 
  1174.             }
  1175.         //}
  1176.         
  1177.         
  1178.         
  1179.     /*
  1180.             //return $this->redirectToRoute('more_details', ['id' => $id]);
  1181.             if ($request->request->has('exit')) {
  1182.                 
  1183.                 return $this->redirectToRoute('more_details', [
  1184.                     'id' => $id,
  1185.                 ]);
  1186.             }
  1187.             if ($request->request->has('save')) {
  1188.                     
  1189.                     return $this->redirectToRoute('edit_property', [
  1190.                         'id' => $id,
  1191.                     ]);
  1192.             }
  1193.             if ($request->request->has('add-tenant')) {
  1194.                     
  1195.                 return $this->redirectToRoute('app_newtenant', [
  1196.                     'id' => $id,
  1197.                 ]);
  1198.         }
  1199.     */
  1200.    
  1201.     
  1202.         return $this->render("/aa/edit.html.twig",[
  1203.             "property_form" => $propertyForm->createView(),
  1204.             //"landlord_forms"=>$landlordForms,
  1205.             "property_details_form"=>$detailsForm->createView(),
  1206.             "property"=>$property,
  1207.             'type'=>$type,
  1208.             'subtype'=>$subtype,
  1209.             //"bedroom_forms" => $bedroomForms,
  1210.             //"image_forms" => $imageForms,
  1211.             //"tenant_forms"=>$tenantForms,
  1212.             //"document_forms" => $documentForms,
  1213.             //"images"=>$images,
  1214.             //"documents"=>$documents,
  1215.             //"bedrooms"=>$bedrooms,
  1216.             //"landlords"=>$landlords,
  1217.             //"tenants"=>$tenants,
  1218.             //"ownership"=>$ownership,
  1219.             //"percentage_forms"=>$percentageForms,
  1220.         ]);
  1221.      
  1222.     
  1223.     }
  1224.     
  1225.     #[Route('/properties/delete/{id}' name:"delete_property")]
  1226.     public function delete(Request $requestEntityManagerInterface $entityManager$id): Response
  1227.     {   
  1228.         if (!$this->isGranted('ROLE_ADMIN')) {
  1229.            return $this->render('errors/access.html.twig',[
  1230.             
  1231.            ]);
  1232.         }
  1233.     
  1234.                
  1235.         $property $entityManager->getRepository(PropertyList::class)->find($id);
  1236.         
  1237.         if (!$property) {
  1238.             return $this->render('errors/notfound.html.twig',[
  1239.                 
  1240.             ]);
  1241.         }
  1242.                 
  1243.         //$property_id= $property->getId();
  1244.        
  1245.         $property->setStatus('Inactivo');
  1246.         $details=$property->getPropertyDetails();
  1247.         $bedrooms=$details->getBedrooms();
  1248.         //dump($details);
  1249.         /*
  1250.         // Remove associated bedrooms
  1251.         foreach ($bedrooms as $bedroom) {
  1252.             $entityManager->remove($bedroom);
  1253.             //set them inactive or not for rent.
  1254.             
  1255.         }
  1256.         
  1257.         
  1258.        /*
  1259.         // Remove associated photos
  1260.         foreach ($property->getImages() as $image) {
  1261.             $entityManager->remove($image);
  1262.         }
  1263.         
  1264.         // 
  1265.         
  1266.         
  1267.         $entityManager->remove($property);
  1268.         //$entityManager->remove($details);
  1269.         $entityManager->flush();
  1270.         */
  1271.     
  1272.         //return new Response('Propiedad Archivada.');
  1273.         $this->addFlash(
  1274.            'success',
  1275.            'Propiedad Archivada.'
  1276.         );
  1277.         return $this->redirectToRoute('more_details',['id'=> $property]);
  1278.     }
  1279.     #[Route('/newproperty/{id}/newdetails'name'app_newdetails')]
  1280.     public function newPropertyDetailsEntityManagerInterface $entityManagerint $idRequest $requestPropertyDetailsRepository $propertyDetailsRepository,)
  1281.     {   
  1282.         if (!$this->isGranted('ROLE_BROKER')) {
  1283.            return $this->render('errors/access.html.twig',[
  1284.             
  1285.            ]);
  1286.         }
  1287.         $property$entityManager->getRepository(PropertyList::class)->find($id);
  1288.         if (!$property) {
  1289.             return $this->render('errors/notfound.html.twig',[
  1290.                 
  1291.             ]);
  1292.         }
  1293.         
  1294.         $idp=$property->getId();
  1295.         $type=$property->getPropertyType();
  1296.         $delivery=$property->getDeliveryType();
  1297.         $subtype=$property->getSubType();
  1298.         
  1299.         
  1300.         $details= new PropertyDetails();
  1301.         $details->setPropertyList($property);
  1302.         $details_form=$this->createForm(NewPropertyDetailsType::class, $details);
  1303.         $details_form->handleRequest($request);
  1304.         if($details_form->isSubmitted() && $details_form->isValid()){
  1305.             
  1306.             //$details=$details_form->getData();
  1307.             //$property_details->setPropertyList($idp);
  1308.             //$property_details=$id->setPropertyList();
  1309.             $double=$details_form->get('doubleBed')->getData() ?? '0';
  1310.             $single=$details_form->get('singleBed')->getData() ?? '0';
  1311.             $addition=$single+$double;
  1312.             $bedrooms=$details->setBedroomNumber($addition);
  1313.             
  1314.             
  1315.             $propertyDetailsRepository->save($detailstrue);
  1316.             //dd($details);
  1317.             //die;
  1318.             //$details_id = $property_details->getId();
  1319.             $this->addFlash("success""Las características han sido guardadas correctamente.");
  1320.             //return $this->redirectToRoute('app_newbedroom', ['id' => $id]);
  1321.         
  1322.            
  1323.             $disableSaveButton true;
  1324.         
  1325.         } else {
  1326.             $disableSaveButton false;
  1327.         
  1328.         }
  1329.         //dd($bedrooms);
  1330.         //die;
  1331.         //if ($request->isMethod('POST') && $details_form->isValid()) {
  1332.             
  1333.         
  1334.         
  1335.         return $this->render("/property_details/newdetails.html.twig",[
  1336.             "details_form" => $details_form->createView(),
  1337.             'type'=>$type,
  1338.             'delivery'=>$delivery,
  1339.             'subtype'=>$subtype,
  1340.             'id'=>$idp,
  1341.             'disable_save_button'=>$disableSaveButton,
  1342.         /*
  1343.         return $this->render("/AAAA/newdets.html.twig",[
  1344.             "details_form" => $details_form->createView(),
  1345.         */
  1346.         ]);
  1347.         
  1348.     }
  1349.    
  1350.     #[Route('/newpotential'name:"new_potential")]
  1351.     public function potentialClient(
  1352.         PotentialClientsRepository $potentialClientsRepository
  1353.         Request $request,
  1354.         EntityManagerInterface $entityManager
  1355.         ): Response {   
  1356.             
  1357.             $property_id $entityManager->getRepository(PropertyList::class)->find($id);
  1358.             dd($property_id);
  1359.             die;
  1360.         
  1361.             if(!$property_id) {
  1362.                 return $this->render('errors/notfound.html.twig',[
  1363.                     
  1364.                 ]);
  1365.             }
  1366.             
  1367.             $this->getUser()->getPotentialClient();
  1368.             
  1369.             //$potentialClient = new PotentialClients();
  1370.             $potentialClient_form=$this->createForm(PotentialClientsType::class);
  1371.             $potentialClient_form->handleRequest($request);
  1372.             if($potentialClient_form->isSubmitted() && $potentialClient_form->isValid()){
  1373.             
  1374.                 $potentialClient=$potentialClient_form->getData();
  1375.                 
  1376.                 $potentialClient->setProperty($property_id); 
  1377.                 $potentialClient->setStatus(true);
  1378.                 
  1379.                 
  1380.                 //$potentialClientsRepository->save($potentialClient, true);
  1381.                 $this->addFlash ("success","You successfully sent your enquiry!");
  1382.                 //return $this->redirectToRoute("app_properties");
  1383.                 
  1384.            
  1385.             }
  1386.        
  1387.             return $this->render('info.html.twig', [
  1388.                 "name"=>"potentialClient",
  1389.                 "potentialClient_form"=>$potentialClient_form->createView(),
  1390.             ]);
  1391.         
  1392.     } 
  1393.     #[Route ('/success'name:'app_success')]
  1394.     public function success(): Response
  1395.     {
  1396.         return $this->render('success/success.html.twig', [
  1397.             "name"=>"SuccessPage",
  1398.         ]);
  1399.     }
  1400.     
  1401.     #[Route('/datosCodigoPostal/{codigoPostal}'name'app_datos_codigo_postal'methods: ['POST''GET'])]
  1402.     public function getDatosCodigoPostal(OperacionesCPPoblacionesYProvincias $opsCpsstring $codigoPostal):JsonResponse{
  1403.         return $this->json($opsCps->getDatosCodigoPostal($codigoPostal));
  1404.     }
  1405.     /////////DASHBOARDS//////////////////////////////////////////////////
  1406.     
  1407. /*
  1408.     #[Route('/broker', name:"broker_dashboard")]
  1409.     public function brokerDashboard(): Response
  1410.     {
  1411.         return $this->render('/dashboards/broker.html.twig', [
  1412.             "name"=>"brokerDashboard",
  1413.         ]);
  1414.     }
  1415.     
  1416.     #[Route('/landlord', name:"landlord_dashboard")]
  1417.     public function landlordDashboard(): Response
  1418.     {
  1419.         return $this->render('/dashboards/landlord.html.twig', [
  1420.             "name"=>"landlordDashboard",
  1421.         ]);
  1422.     }
  1423.     #[Route('/tenant', name:"tenant_dashboard")]
  1424.     public function tenantDashboard(): Response
  1425.     {
  1426.         return $this->render('/dashboards/tenant.html.twig', [
  1427.             "name"=>"tenantDashboard",
  1428.         ]);
  1429.     }
  1430.     */
  1431.     
  1432.     
  1433. }