src/Controller/RoomController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use App\Entity\Room;
  8. use App\Entity\User;
  9. use App\Entity\LandLord;
  10. use App\Entity\Tennant;
  11. use App\Entity\RentalConditions;
  12. use App\Entity\ListingViews;
  13. use App\Services\ConfigService;
  14. class RoomController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("{_locale}/room/{url}", name="room", requirements={"_locale": "es|en"})
  18.      */
  19.     public function index(string $url ''Request $request): Response
  20.     {
  21.         $locale $request->getLocale();
  22.         //find flat by url
  23.         $room $this->getDoctrine()->getRepository(Room::class)->findOneBy(array('url' => $url));
  24.         //check if is found
  25.         if(!$room){
  26.             return $this->redirectToRoute('404');
  27.         }
  28.         //check if room is deativate
  29.         if($room->getActive() == '0'){
  30.             return $this->redirectToRoute('inactive_listing');
  31.         }
  32.        
  33.         //get publisher data
  34.         $publisher $this->getDoctrine()->getRepository(User::class)->findOneBy(array('id' => $room->getUserId()));
  35.         $publisherType '';
  36.         //check if publisher tennant or landlord
  37.         $publisherData $this->getDoctrine()->getRepository(Tennant::class)
  38.                             ->findOneBy(array('user' => $room->getUserId()));
  39.         
  40.         if(\is_null($publisherData)){
  41.             $publisherType 'landlord';
  42.             $publisherData $this->getDoctrine()->getRepository(LandLord::class)
  43.                             ->findOneBy(array('user' => $room->getUserId()));
  44.         }
  45.         //rental conditions array
  46.         $rt $this->getDoctrine()->getRepository(RentalConditions::class)->findOneBy(array('listingType'=>'room'));
  47.         //get maps api key
  48.         $config = new ConfigService($this->getDoctrine()->getManager());
  49.         $mapsApiKey $config->getMapsApiKey($this->getDoctrine()->getManager());
  50.         //add visitors count
  51.         $et $this->getDoctrine()->getManager(); 
  52.         $views = new ListingViews();
  53.         $views->setListingType('room');
  54.         $views->setListingId($room->getId());
  55.         $views->setVisitDate(\time());
  56.         $et->persist($views);
  57.         $et->flush();
  58.         return $this->render('public/_room.html.twig', [
  59.             'room' => $room,
  60.             'publisher'=>$publisher,
  61.             'publishertype'=>$publisherType,
  62.             'publisherdata'=>$publisherData,
  63.             'conditions'=>$rt,
  64.             'maps_key'=>$mapsApiKey
  65.         ]);
  66.     }
  67. }