src/Controller/ListingController.php line 75

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AccommodationType;
  4. use App\Entity\Addons;
  5. use App\Entity\BookableExperiences;
  6. use App\Entity\Bookings;
  7. use App\Entity\Favourites;
  8. use App\Entity\ListingQuestions;
  9. use App\Entity\Media;
  10. use App\Entity\MinimumNightOverride;
  11. use App\Entity\PricingNights;
  12. use App\Entity\PricingStay;
  13. use App\Entity\Property;
  14. use App\Entity\PropertyReviews;
  15. use App\Entity\PropertyTags;
  16. use App\Entity\PropertyTagsApplied;
  17. use App\Entity\Regions;
  18. use App\Entity\RoomBannersSpecific;
  19. use App\Entity\RoomURLAlias;
  20. use App\Entity\TrackedCalendars;
  21. use App\Entity\User;
  22. use App\Security\LoginFormAuthenticator;
  23. use App\Service\GlobalFunctions;
  24. use Cocur\Slugify\Slugify;
  25. use Liip\ImagineBundle\Message\WarmupCache;
  26. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  27. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  28. use Symfony\Component\Form\Extension\Core\Type\DateType;
  29. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  30. use Symfony\Component\Form\Extension\Core\Type\MoneyType;
  31. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  32. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  33. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  34. use Symfony\Component\Form\Extension\Core\Type\TextType;
  35. use Symfony\Component\HttpFoundation\Request;
  36. use Symfony\Component\HttpFoundation\Response;
  37. use Symfony\Component\Messenger\MessageBusInterface;
  38. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  39. use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
  40. use Vich\UploaderBundle\Form\Type\VichImageType;
  41. class ListingController extends AbstractController
  42. {
  43.     public function oldlisting($listing_slug$room_slug)
  44.     {
  45.         $em $this->getDoctrine()->getManager();
  46.         $AccommInfo $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
  47.                 'RoomSlug' => $room_slug,
  48.                 'Enabled' => true,
  49.             ]);
  50.         $NewSlug $AccommInfo->getRoomSlugNew();
  51.         if (null == $NewSlug) {
  52.             $slugify = new Slugify();
  53.             $NewHeadlineSlug $slugify->slugify($AccommInfo->getSearchHeadline());
  54.             $AccommInfo->setRoomSlugNew($NewHeadlineSlug);
  55.             $em->persist($AccommInfo);
  56.             $em->flush();
  57.             $NewSlug $NewHeadlineSlug;
  58.         }
  59.         if (isset($_GET['preview_listing'])) {
  60.             return $this->redirectToRoute('listing_new_url', ['room_slug_new' => $NewSlug'preview_listing' => 'true']);
  61.         } else {
  62.             return $this->redirectToRoute('listing_new_url', ['room_slug_new' => $NewSlug]);
  63.         }
  64.     }
  65.     public function index($room_slug_newGlobalFunctions $GlobalFn)
  66.     {
  67.         $em $this->getDoctrine()->getManager();
  68.         // Overrides for the URL and Aliases
  69.         $URL $this->getDoctrine()->getRepository(RoomURLAlias::class)->findOneBy(['Alias' => $room_slug_new]);
  70.         if ($URL) {
  71.             return $this->redirectToRoute('listing_new_url', ['room_slug_new' => $URL->getRoom()->getRoomSlugNew()]);
  72.         } else {
  73.             if (isset($_GET['preview_listing'])) {
  74.                 $AccommInfo $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
  75.                     'RoomSlugNew' => $room_slug_new,
  76.                 ]);
  77.             } else {
  78.                 $AccommInfo $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
  79.                     'RoomSlugNew' => $room_slug_new,
  80.                     'Enabled' => true,
  81.                 ]);
  82.             }
  83.         }
  84.         if (!$AccommInfo) {
  85.             return new Response('Sorry, the requested property is not currently available');
  86.         }
  87.         if (isset($_GET['check_in'])) {
  88.             $CheckIn $_GET['check_in'];
  89.             $CheckOut $_GET['check_out'];
  90.         } else {
  91.             $CheckIn null;
  92.             $CheckOut null;
  93.         }
  94.         $room_slug $AccommInfo->getRoomSlug();
  95.         $PropertyCode $AccommInfo->getPropertyCode();
  96.         $ListingInfo $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  97.                 'ListingCode' => $PropertyCode,
  98.             ]);
  99.         $listing_slug $ListingInfo->getListingSlug();
  100.         if (isset($_GET['preview_listing']) or 'Listed' == $ListingInfo->getListingStatus()) {
  101.             $LandownerInfo $this->getDoctrine()->getRepository(User::class)->find($ListingInfo->getLandownerId());
  102.             $ListingCode $ListingInfo->getListingCode();
  103.             $RoomTonightPrice $GlobalFn->nightPrice(0$AccommInfo->getRoomCode(), date('Y-m-d'));
  104.             $GetListingRooms $this->getDoctrine()->getRepository(AccommodationType::class)->findBy([
  105.                     'PropertyCode' => $ListingCode,
  106.                     'Enabled' => true,
  107.             ]);
  108.             $OtherListingRooms = [];
  109.             foreach ($GetListingRooms as $thisRoom) {
  110.                 if ('Listed' == $thisRoom->getProperty()->getListingStatus()) {
  111.                     if ($thisRoom->getRoomCode() !== $AccommInfo->getRoomCode()) {
  112.                         $OtherListingRooms[] = $thisRoom;
  113.                     }
  114.                 }
  115.             }
  116.             $CurrentRecentlyViewed $this->get('session')->get('recently_viewed');
  117.             $NewRecentlyViewed '['.$AccommInfo->getRoomCode().']'.str_replace('['.$AccommInfo->getRoomCode().']'''$CurrentRecentlyViewed);
  118.             $this->get('session')->set('recently_viewed'$NewRecentlyViewed);
  119.             // $GetImages = $GlobalFn->listing_photos($ListingCode, 0);
  120.             $MainImg $GlobalFn->room_photos($AccommInfo->getRoomCode(), 1);
  121.             $RoomImg $GlobalFn->room_photos($AccommInfo->getRoomCode(), 0);
  122.             $Images = [];
  123.             foreach ($RoomImg as $ThisImage) {
  124.                 $Images[] = ['id' => $ThisImage['id'], 'document_file_name' => 'media/'.$ThisImage['document_file_name'], 'description' => $ThisImage['description']];
  125.             }
  126.             $UserImg $this->getDoctrine()->getRepository(Media::class)->findOneBy(['UserId' => $LandownerInfo->getId()]);
  127.             if ($UserImg) {
  128.                 if ('' == $UserImg->getDocumentFileName()) {
  129.                     $UserImg = ['DocumentFileName' => 'media/OTBT_logo_green_RGB-01.png'];
  130.                 } else {
  131.                     $UserImg = ['DocumentFileName' => 'media/'.$UserImg->getDocumentFileName()];
  132.                 }
  133.             } else {
  134.                 $UserImg = ['DocumentFileName' => 'media/OTBT_logo_green_RGB-01.png'];
  135.             }
  136.             $Addons $this->getDoctrine()->getRepository(Addons::class)->findBy([
  137.                     'PropertyCode' => $ListingCode,
  138.                     'Enabled' => true,
  139.                 ]);
  140.             $AddonImg = [];
  141.             foreach ($Addons as $ThisAddon) {
  142.                 $AddonImg[$ThisAddon->getId()] = $GlobalFn->addon_photos($ThisAddon->getId(), 1);
  143.             }
  144.             /*$Amenities = $this->getDoctrine()->getRepository(PropertyTags::class)->findBy([
  145.                     'TagType' => 'amenity',
  146.                 ]);
  147.                 */
  148.             $GetRoomTags $ChosenAmenity $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy([
  149.                 'Room' => $AccommInfo,
  150.             ]);
  151.             $AllRoomTags = [];
  152.             foreach ($GetRoomTags as $thisTag) {
  153.                 $AllRoomTags[] = $thisTag->getTag()->getId();
  154.             }
  155.             $ActivitiesFilters $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  156.                 ->where('t.TagType = :tag_type')
  157.                 ->andWhere('t.Params IS NULL')
  158.                 ->setParameter('tag_type''activities')
  159.                 ->orderBy('t.TagName''ASC')
  160.                 ->getQuery()
  161.                 ->getResult();
  162.             $ChosenActivitiesFilters = [];
  163.             $ContraActivitiesFilters = [];
  164.             foreach ($ActivitiesFilters as $thisFilter) {
  165.                 if (in_array($thisFilter->getId(), $AllRoomTags)) {
  166.                     $ChosenActivitiesFilters[] = $thisFilter;
  167.                 } else {
  168.                     if (null !== $thisFilter->getContraTagName()) {
  169.                         $ContraActivitiesFilters[] = $thisFilter;
  170.                     }
  171.                 }
  172.             }
  173.             // ---
  174.             $AmenitiesFilters $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  175.                ->where('t.TagType = :tag_type')
  176.                ->setParameter('tag_type''amenity')
  177.                ->orderBy('t.TagName''ASC')
  178.                ->getQuery()
  179.                ->getResult();
  180.             $ChosenAmenitiesFilters = [];
  181.             $ContraAmenitiesFilters = [];
  182.             foreach ($AmenitiesFilters as $thisFilter) {
  183.                 if (in_array($thisFilter->getId(), $AllRoomTags)) {
  184.                     $ChosenAmenitiesFilters[] = $thisFilter;
  185.                 } else {
  186.                     if (null !== $thisFilter->getContraTagName()) {
  187.                         $ContraAmenitiesFilters[] = $thisFilter;
  188.                     }
  189.                 }
  190.             }
  191.             // ---
  192.             $ExperienceFilters $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  193.                ->where('t.TagType = :tag_type')
  194.                ->setParameter('tag_type''experience')
  195.                ->orderBy('t.TagName''ASC')
  196.                ->getQuery()
  197.                ->getResult();
  198.             $ChosenExperienceFilters = [];
  199.             foreach ($ExperienceFilters as $thisFilter) {
  200.                 if (in_array($thisFilter->getId(), $AllRoomTags)) {
  201.                     $ChosenExperienceFilters[] = $thisFilter;
  202.                 }
  203.             }
  204.             // ---
  205.             $EatingDrinkingFilters $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  206.                ->where('t.TagType = :tag_type')
  207.                ->setParameter('tag_type''eating_drinking')
  208.                ->orderBy('t.TagName''ASC')
  209.                ->getQuery()
  210.                ->getResult();
  211.             $ChosenEatingDrinkingFilters = [];
  212.             $ContraEatingDrinkingFilters = [];
  213.             foreach ($EatingDrinkingFilters as $thisFilter) {
  214.                 if (in_array($thisFilter->getId(), $AllRoomTags)) {
  215.                     $ChosenEatingDrinkingFilters[] = $thisFilter;
  216.                 } else {
  217.                     if (null !== $thisFilter->getContraTagName()) {
  218.                         $ContraEatingDrinkingFilters[] = $thisFilter;
  219.                     }
  220.                 }
  221.             }
  222.             // ---
  223.             $AccommTypeFilters $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  224.                ->where('t.TagType = :tag_type')
  225.                ->setParameter('tag_type''accomm_type')
  226.                ->orderBy('t.TagName''ASC')
  227.                ->getQuery()
  228.                ->getResult();
  229.             $ChosenAccommTypeFilters = [];
  230.             $ContraAccommTypeFilters = [];
  231.             foreach ($AccommTypeFilters as $thisFilter) {
  232.                 if (in_array($thisFilter->getId(), $AllRoomTags)) {
  233.                     $ChosenAccommTypeFilters[] = $thisFilter;
  234.                 } else {
  235.                     if (null !== $thisFilter->getContraTagName()) {
  236.                         $ContraAccommTypeFilters[] = $thisFilter;
  237.                     }
  238.                 }
  239.             }
  240.             // ---
  241.             $StayInfoFilters $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  242.                ->where('t.TagType = :tag_type')
  243.                ->setParameter('tag_type''stay_info')
  244.                ->orderBy('t.TagName''ASC')
  245.                ->getQuery()
  246.                ->getResult();
  247.             $ChosenStayInfoFilters = [];
  248.             $ContraStayInfoFilters = [];
  249.             foreach ($StayInfoFilters as $thisFilter) {
  250.                 if (in_array($thisFilter->getId(), $AllRoomTags)) {
  251.                     $ChosenStayInfoFilters[] = $thisFilter;
  252.                 } else {
  253.                     if (null !== $thisFilter->getContraTagName()) {
  254.                         $ContraStayInfoFilters[] = $thisFilter;
  255.                     }
  256.                 }
  257.             }
  258.             // ---
  259.             $UniqueThingsFilters $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  260.                ->where('t.TagType = :tag_type')
  261.                ->setParameter('tag_type''unique_things')
  262.                ->orderBy('t.TagName''ASC')
  263.                ->getQuery()
  264.                ->getResult();
  265.             $ChosenUniqueThingsFilters = [];
  266.             $ContraUniqueThingsFilters = [];
  267.             foreach ($UniqueThingsFilters as $thisFilter) {
  268.                 if (in_array($thisFilter->getId(), $AllRoomTags)) {
  269.                     $ChosenUniqueThingsFilters[] = $thisFilter;
  270.                 } else {
  271.                     if (null !== $thisFilter->getContraTagName()) {
  272.                         $ContraUniqueThingsFilters[] = $thisFilter;
  273.                     }
  274.                 }
  275.             }
  276.             $GetRegion $this->getDoctrine()->getRepository(Regions::class)->findOneBy([
  277.                 'Name' => $ListingInfo->getPhysAddr3(),
  278.             ]);
  279.             $NearbyListings $em->getRepository("App\Entity\AccommodationType")->createQueryBuilder('t')
  280.                ->where('t.Region = :Region')
  281.                ->andWhere('t.Enabled = 1')
  282.                ->andWhere('t.Property != :ThisListingCode')
  283.                ->setParameter('Region'$GetRegion)
  284.                ->setParameter('ThisListingCode'$ListingInfo)
  285.                ->setMaxResults(4)
  286.                ->getQuery()
  287.                ->getResult();
  288.             shuffle($NearbyListings);
  289.             $ReviewData = [];
  290.             $Reviews $this->getDoctrine()->getRepository(PropertyReviews::class)->findBy([
  291.                 'PropertyCode' => $ListingCode,
  292.                 'Approved' => true,
  293.             ], ['id' => 'DESC']);
  294.             foreach ($Reviews as $ThisReview) {
  295.                 if ($ThisReview->getBookingId() > 0) {
  296.                     $BookingInfo $this->getDoctrine()->getRepository(Bookings::class)->find($ThisReview->getBookingId());
  297.                     $HolidaymakerInfoReview $this->getDoctrine()->getRepository(User::class)->find($BookingInfo->getHolidaymakerId());
  298.                     $ReviewData[$ThisReview->getId()] = [
  299.                         'holidaymakerinfo' => $HolidaymakerInfoReview,
  300.                         'bookinginfo' => $BookingInfo,
  301.                     ];
  302.                 } else {
  303.                     $ReviewData[$ThisReview->getId()] = [
  304.                         'holidaymakerinfo' => [],
  305.                         'bookinginfo' => [],
  306.                     ];
  307.                 }
  308.             }
  309.             $RoomBanners $em->getRepository("App\Entity\RoomBanners")->createQueryBuilder('t')
  310.                ->where('t.Enabled = true')
  311.                ->andWhere(':time_now BETWEEN t.ApplyFrom AND t.ApplyTo')
  312.                ->setParameter('time_now', new \DateTime('now'))
  313.                ->getQuery()
  314.                ->getResult();
  315.             $RoomBannerOutput '';
  316.             foreach ($RoomBanners as $ThisRoomBanner) {
  317.                 $RoomSpecificBanner $this->getDoctrine()->getRepository(RoomBannersSpecific::class)->findOneBy([
  318.                     'RoomBanner' => $ThisRoomBanner,
  319.                     'Enabled' => true,
  320.                     'Room' => $AccommInfo,
  321.                 ]);
  322.                 if ($RoomSpecificBanner) {
  323.                     $RoomBannerOutput .= "<div class='alert' style='".$ThisRoomBanner->getBoxStyling()."'>";
  324.                     $RoomBannerOutput .= "<div class='row'>";
  325.                     $RoomBannerOutput .= "<div class='col-sm-2' style='text-align:center;'>";
  326.                     $RoomBannerOutput .= "<i class='fa ".$ThisRoomBanner->getBannerFAIcon()."' style='font-size:90px;'></i>";
  327.                     $RoomBannerOutput .= '</div>';
  328.                     $RoomBannerOutput .= "<div class='col-sm-10'>";
  329.                     $RoomBannerOutput .= $RoomSpecificBanner->getMessage();
  330.                     $RoomBannerOutput .= '</div>';
  331.                     $RoomBannerOutput .= '</div>';
  332.                     $RoomBannerOutput .= '</div>';
  333.                 } elseif (true == $ThisRoomBanner->getForceDefaultMessage()) {
  334.                     $RoomBannerOutput .= "<div class='alert' style='".$ThisRoomBanner->getBoxStyling()."'>";
  335.                     $RoomBannerOutput .= "<div class='row'>";
  336.                     $RoomBannerOutput .= "<div class='col-sm-2' style='text-align:center;'>";
  337.                     $RoomBannerOutput .= "<i class='fa ".$ThisRoomBanner->getBannerFAIcon()."' style='font-size:90px;'></i>";
  338.                     $RoomBannerOutput .= '</div>';
  339.                     $RoomBannerOutput .= "<div class='col-sm-10'>";
  340.                     $RoomBannerOutput .= $ThisRoomBanner->getDefaultMessage();
  341.                     $RoomBannerOutput .= '</div>';
  342.                     $RoomBannerOutput .= '</div>';
  343.                     $RoomBannerOutput .= '</div>';
  344.                 } else {
  345.                 }
  346.             }
  347.             if (count($RoomBanners) > 0) {
  348.                 // $RoomBannerOutput .="<hr>";
  349.             }
  350.             // Listing QnAs
  351.             $ListingQuestions $em->getRepository("App\Entity\ListingQuestions")->createQueryBuilder('t')
  352.                ->where('t.Room = :room')
  353.                ->andWhere('t.ModeratedBy > 0')
  354.                ->andWhere('t.ShowOnListing=1')
  355.                ->setParameter('room'$AccommInfo)
  356.                ->getQuery()
  357.                ->getResult();
  358.             // Bookable Experiences
  359.             $GetAllBookables $this->getDoctrine()->getRepository(BookableExperiences::class)->findBy(['Status' => 'Listed']);
  360.             $BookableExperiences = [];
  361.             $SearchDistance $GlobalFn->datedVar('bookableExperiencesSearchDistanceKm'date('Y-m-d'));
  362.             foreach ($GetAllBookables as $thisBookable) {
  363.                 $DistanceAway $GlobalFn->distanceCalculation($ListingInfo->getCoordLat(), $ListingInfo->getCoordLong(), $thisBookable->getCoordLat(), $thisBookable->getCoordLong());
  364.                 if ($DistanceAway $SearchDistance) {
  365.                     $BookableExperiences[] = [$thisBookable$DistanceAway];
  366.                 }
  367.             }
  368.             usort($BookableExperiences, function ($a$b) {
  369.                 return $a[1] <=> $b[1];
  370.             });
  371.             $UserExistingBooking $this->getDoctrine()->getRepository(Bookings::class)->findOneBy([
  372.                 'RelatedRoom' => $AccommInfo,
  373.                 'RelatedHolidaymaker' => $this->getUser(),
  374.                 'Status' => 'Draft',
  375.             ]);
  376.             return $this->render('listing/index.html.twig', [
  377.                 'controller_name' => 'ListingController',
  378.                 'listing_slug' => $listing_slug,
  379.                 'room_code' => $AccommInfo->getRoomCode(),
  380.                 'room_slug' => $room_slug,
  381.                 'listing_info' => $ListingInfo,
  382.                 'room_info' => $AccommInfo,
  383.                 'today_date' => date('Y-m-d'),
  384.                 'other_rooms' => $OtherListingRooms,
  385.                 'images_arr' => $Images,
  386.                 'tomorrow_date' => date('Y-m-d'strtotime('tomorrow')),
  387.                 'default_image' => '../../'.$MainImg,
  388.                 'other_room_count' => count($OtherListingRooms),
  389.                 'addons' => $Addons,
  390.                 'addons_img' => $AddonImg,
  391.                 'landowner_info' => $LandownerInfo,
  392.                 'map_lat' => $ListingInfo->getCoordLat(),
  393.                 'map_long' => $ListingInfo->getCoordLong(),
  394.                 'reviews' => $Reviews,
  395.                 'landowner_img' => $UserImg,
  396.                 'room_photos' => $RoomImg,
  397.                 'room_tonight_price' => $RoomTonightPrice,
  398.                 'room_banner_output' => $RoomBannerOutput,
  399.                 'nearby_listings' => $NearbyListings,
  400.                 'review_data' => $ReviewData,
  401.                 'listing_questions' => $ListingQuestions,
  402.                 'bookable_experiences' => $BookableExperiences,
  403.                 'checkin' => $CheckIn,
  404.                 'checkout' => $CheckOut,
  405.                 'user_existing_booking' => $UserExistingBooking,
  406.                 'filters_activities' => $ChosenActivitiesFilters,
  407.                 'filters_activities_contra' => $ContraActivitiesFilters,
  408.                 'filters_amenities' => $ChosenAmenitiesFilters,
  409.                 'filters_amenities_contra' => $ContraAmenitiesFilters,
  410.                 'filters_uniquethings' => $ChosenUniqueThingsFilters,
  411.                 'filters_uniquethings_contra' => $ContraUniqueThingsFilters,
  412.                 'filters_eatingdrinking' => $ChosenEatingDrinkingFilters,
  413.                 'filters_eatingdrinking_contra' => $ContraEatingDrinkingFilters,
  414.                 'filters_accommtype' => $ChosenAccommTypeFilters,
  415.                 'filters_accommtype_contra' => $ContraAccommTypeFilters,
  416.                 'filters_stayinfo' => $ChosenStayInfoFilters,
  417.                 'filters_stayinfo_contra' => $ContraStayInfoFilters,
  418.                 'filters_experience' => $ChosenExperienceFilters,
  419.             ]);
  420.         } else {
  421.             return new Response('Sorry, this listing can not be shown right now');
  422.         }
  423.     }
  424.     public function loginForFav($listing_slug$room_slug)
  425.     {
  426.         return $this->redirectToRoute('listing', ['listing_slug' => $listing_slug'room_slug' => $room_slug]);
  427.     }
  428.     public function toggleFavourite($room_id$ajax true)
  429.     {
  430.         $user_id $this->getUser()->getId();
  431.         $Room $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
  432.         $Favourite $this->getDoctrine()->getRepository(Favourites::class)->findOneBy([
  433.             'UserId' => $user_id,
  434.             'RoomId' => $room_id,
  435.         ]);
  436.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Room->getPropertyCode()]);
  437.         $entityManager $this->getDoctrine()->getManager();
  438.         if ($Favourite) {
  439.             $entityManager->remove($Favourite);
  440.             $entityManager->flush();
  441.             if (true == $ajax) {
  442.                 return new Response('ADD FAV');
  443.             } else {
  444.                 return $this->redirectToRoute('listing', ['listing_slug' => $Property->getListingSlug(), 'room_slug' => $Room->getRoomSlug()]);
  445.             }
  446.         } else {
  447.             $Favourite = new Favourites();
  448.             $Favourite->setRoomId($room_id);
  449.             $Favourite->setUserId($user_id);
  450.             $entityManager->persist($Favourite);
  451.             $entityManager->flush();
  452.             if (true == $ajax) {
  453.                 return new Response('REMOVE FAV');
  454.             } else {
  455.                 return $this->redirectToRoute('listing', ['listing_slug' => $Property->getListingSlug(), 'room_slug' => $Room->getRoomSlug()]);
  456.             }
  457.         }
  458.     }
  459.     public function loadFavourite($user_id$room_id)
  460.     {
  461.         $Room $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
  462.         $Favourite $this->getDoctrine()->getRepository(Favourites::class)->findOneBy([
  463.             'UserId' => $user_id,
  464.             'RoomId' => $room_id,
  465.         ]);
  466.         if ($Favourite) {
  467.             return new Response('REMOVE FAV');
  468.         } else {
  469.             return new Response('ADD FAV');
  470.         }
  471.     }
  472.     public function updateCaption($photo_idRequest $request)
  473.     {
  474.         $GetPhoto $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
  475.         $GetPhoto->setDescription($request->request->get('caption'));
  476.         $entityManager $this->getDoctrine()->getManager();
  477.         $entityManager->persist($GetPhoto);
  478.         $entityManager->flush();
  479.         return new Response('success');
  480.     }
  481.     public function photoManager($room_codeRequest $requestMessageBusInterface $messageBus)
  482.     {
  483.         if (isset($_GET['mode'])) {
  484.             $Mode $_GET['mode'];
  485.         } else {
  486.             $Mode 'normal';
  487.         }
  488.         $AccommType $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
  489.                 'RoomCode' => $room_code,
  490.         ]);
  491.         $user $this->get('security.token_storage')->getToken()->getUser();
  492.         if ($this->isGranted('ROLE_ADMIN')) {
  493.             $user $this->getDoctrine()->getRepository(User::class)->find($AccommType->getLandownerId());
  494.         }
  495.         $MatchListing $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  496.                 'ListingCode' => $AccommType->getPropertyCode(),
  497.                 'LandownerId' => $user,
  498.         ]);
  499.         if ($MatchListing) {
  500.             $GetPhotos $this->getDoctrine()->getRepository(Media::class)->findBy([
  501.                 'RoomCode' => $room_code,
  502.             ], ['DisplayOrder' => 'ASC']);
  503.             $NewPhoto = new Media();
  504.             $entityManager $this->getDoctrine()->getManager();
  505.             $form $this->createFormBuilder($NewPhoto)
  506.                 ->add('documentFile'VichImageType::class)
  507.                 ->add('Description'TextType::class, ['label' => 'Caption''required' => false])
  508.                 ->add('save'SubmitType::class, ['label' => 'Upload'])
  509.                 ->getForm();
  510.             $form->handleRequest($request);
  511.             if ($form->isSubmitted() && $form->isValid()) {
  512.                 // $form->getData() holds the submitted values
  513.                 // but, the original `$task` variable has also been updated
  514.                 $NewPhoto $form->getData();
  515.                 $NewPhoto->setRoomCode($room_code);
  516.                 $NewPhoto->setAccommType($AccommType);
  517.                 $entityManager->persist($NewPhoto);
  518.                 $entityManager->flush();
  519.                 $RandomFileName time().'_'.$NewPhoto->getDocumentFileName();
  520.                 rename('../public/media/'.$NewPhoto->getDocumentFileName(), '../public/media/'.$RandomFileName);
  521.                 $messageBus->dispatch(new WarmupCache('/media/'.$RandomFileName));
  522.                 $NewPhoto->setDocumentFileName($RandomFileName);
  523.                 $entityManager->persist($NewPhoto);
  524.                 $entityManager->flush();
  525.                 // var_dump($NewPhoto);
  526.                 // exit();
  527.                 return $this->redirectToRoute('edit_listing_photos', ['room_code' => $room_code'mode' => $Mode]);
  528.             }
  529.             $random_number rand(100000999999);
  530.             return $this->render('listing/photomanager.html.twig', [
  531.                 'listing_info' => $MatchListing,
  532.                 'photos' => $GetPhotos,
  533.                 'listing_code' => $MatchListing->getListingCode(),
  534.                 'room_code' => $room_code,
  535.                 'uploadForm' => $form->createView(),
  536.                 'mode' => $Mode,
  537.                 'random_number' => $random_number,
  538.             ]);
  539.         } else {
  540.             return new Response('No access');
  541.         }
  542.     }
  543.     public function resetPhotos($room_codeRequest $request)
  544.     {
  545.         $ListingPhotos $this->getDoctrine()->getRepository(Media::class)->findBy([
  546.             'RoomCode' => $room_code,
  547.         ], ['id' => 'ASC']);
  548.         $i 1;
  549.         foreach ($ListingPhotos as $thisPhoto) {
  550.             $thisPhoto->setDisplayOrder($i);
  551.             $entityManager $this->getDoctrine()->getManager();
  552.             $entityManager->persist($thisPhoto);
  553.             ++$i;
  554.         }
  555.         $entityManager->flush();
  556.         return $this->redirectToRoute('edit_listing_photos', ['room_code' => $room_code]);
  557.     }
  558.     public function newListing(GuardAuthenticatorHandler $guardHandlerRequest $requestLoginFormAuthenticator $authenticatorGlobalFunctions $GlobalFn)
  559.     {
  560.         $entityManager $this->getDoctrine()->getManager();
  561.         /*$NewListingCode = substr(str_shuffle("ABCDEFGHIJKLMNPQRSTUVWXYZ1234567890"),0,9);
  562.         $GetUserProperties = $this->getDoctrine()->getRepository(Property::class)->findBy([
  563.             'LandownerId' => $this->getUser()->getId()
  564.         ]);
  565.         foreach($GetUserProperties as $thisProperty) {
  566.             if($thisProperty->getListingStatus()=="New") {
  567.                 return $this->redirectToRoute('new_listing_form_edit',array('listing_code'=>$thisProperty->getListingCode()));
  568.                 exit;
  569.             }
  570.         }
  571.         $Property = new Property();
  572.         $user_id = $this->getUser()->getId();
  573.         $Property->setLandownerId($user_id);
  574.         $Property->setPropertyTitle("");
  575.         $Property->setListingSlug("listing-".$NewListingCode);
  576.         $Property->setListingCode($NewListingCode);
  577.         $Property->setListingStatus("New");
  578.         $Property->setCreatedDate(new \DateTime('today'));*/
  579.         $user $this->getUser();
  580.         $user->addRole('ROLE_LANDOWNER');
  581.         $entityManager->flush();
  582.         $GlobalFn->addUserToList($user->getId(), 3);
  583.         $doLogin $guardHandler->authenticateUserAndHandleSuccess(
  584.             $user,
  585.             $request,
  586.             $authenticator,
  587.             'main' // firewall name in security.yaml
  588.         );
  589.         return $this->redirectToRoute('onboarding_new');
  590.     }
  591.     public function updateListingField(Request $request)
  592.     {
  593.         $entityManager $this->getDoctrine()->getManager();
  594.         $listing_id $request->request->get('listing_id');
  595.         $field $request->request->get('field');
  596.         $user_id $this->getUser()->getId();
  597.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  598.                 'id' => $listing_id,
  599.                 'LandownerId' => $user_id,
  600.             ]);
  601.         $NewValue $request->request->get('NewValue');
  602.         if ('setPhysAddr3' == $field) {
  603.             if ('Manawatu-Wanganui' == $NewValue) {
  604.                 $NewValue 'Manawatu-Whanganui';
  605.             }
  606.         }
  607.         $Property->$field($NewValue);
  608.         $entityManager->persist($Property);
  609.         $entityManager->flush();
  610.         return new Response('success');
  611.     }
  612.     public function updateAccommField(Request $request)
  613.     {
  614.         $entityManager $this->getDoctrine()->getManager();
  615.         $accomm_id $request->request->get('accomm_id');
  616.         $field $request->request->get('field');
  617.         $user_id $this->getUser()->getId();
  618.         $Accomm $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
  619.                 'id' => $accomm_id,
  620.                 'LandownerId' => $user_id,
  621.             ]);
  622.         $NewValue $request->request->get('NewValue');
  623.         if ('setEnabled' === $field && '1' === $NewValue) {
  624.             return new Response('You do not have permission to change this. Please contact OTBT support for help.'403);
  625.         }
  626.         $Accomm->$field($NewValue);
  627.         $entityManager->persist($Accomm);
  628.         $entityManager->flush();
  629.         return new Response('success');
  630.     }
  631.     public function editNewListing($listing_code$modeRequest $request)
  632.     {
  633.         $user_id $this->getUser()->getId();
  634.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  635.                 'ListingCode' => $listing_code,
  636.                 'LandownerId' => $user_id,
  637.             ]);
  638.         return $this->render('listing/newlisting.html.twig', [
  639.             'mode' => $mode,
  640.             'listing' => $Property,
  641.         ]);
  642.     }
  643.     public function newListingPart2($property_code$modeRequest $request)
  644.     {
  645.         $user_id $this->getUser()->getId();
  646.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  647.                 'ListingCode' => $property_code,
  648.                 'LandownerId' => $user_id,
  649.         ]);
  650.         return $this->render('listing/listingpart2.html.twig', [
  651.             'listing' => $Property,
  652.         ]);
  653.     }
  654.     public function newAccommType($listing_codeRequest $request)
  655.     {
  656.         $entityManager $this->getDoctrine()->getManager();
  657.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  658.             'ListingCode' => $listing_code,
  659.         ]);
  660.         $ExistingAccomms $this->getDoctrine()->getRepository(AccommodationType::class)->findBy([
  661.             'PropertyCode' => $Property->getListingCode(),
  662.         ]);
  663.         foreach ($ExistingAccomms as $thisAccomm) {
  664.             if ('New Accommodation Type' == $thisAccomm->getRoomName()) {
  665.                 return $this->redirectToRoute('newroom_edit', ['room_code' => $thisAccomm->getRoomCode()]);
  666.             }
  667.         }
  668.         $AccommType = new AccommodationType();
  669.         $AccommType->setEnabled(0);
  670.         $NewRoomCode substr(str_shuffle('ABCDEFGHIJKLMNPQRSTUVWXYZ1234567890'), 09);
  671.         $AccommType->setPropertyCode($listing_code);
  672.         $AccommType->setProperty($Property);
  673.         $AccommType->setRoomCode($NewRoomCode);
  674.         $AccommType->setRoomName('New Accommodation Type');
  675.         $AccommType->setRoomSlug('room-'.$NewRoomCode);
  676.         $AccommType->setSearchHeadline('Display Name of Listing');
  677.         $AccommType->setRoomSlugNew('room-'.$NewRoomCode);
  678.         $AccommType->setMinimumNights(1);
  679.         $AccommType->setNightlyQnt(1);
  680.         $AccommType->setPriceMode('pn');
  681.         $user_id $this->getUser()->getId();
  682.         $AccommType->setLandownerId($user_id);
  683.         $entityManager->persist($AccommType);
  684.         $entityManager->flush();
  685.         return $this->redirectToRoute('newroom_edit', ['room_code' => $NewRoomCode]);
  686.     }
  687.     public function editNewAccommType($room_code$modeRequest $request)
  688.     {
  689.         $user_id $this->getUser()->getId();
  690.         $AccommType $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
  691.             'RoomCode' => $room_code,
  692.             'LandownerId' => $user_id,
  693.         ]);
  694.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  695.             'ListingCode' => $AccommType->getPropertyCode(),
  696.         ]);
  697.         $listing_code $Property->getListingCode();
  698.         $entityManager $this->getDoctrine()->getManager();
  699.         $RoomAmenities $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  700.            ->where('t.TagType = :tag_type')
  701.            ->setParameter('tag_type''amenity')
  702.            ->orderBy('t.TagName''ASC')
  703.            ->getQuery()
  704.            ->getResult();
  705.         $EatingDrinking $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  706.            ->where('t.TagType = :tag_type')
  707.            ->setParameter('tag_type''eating_drinking')
  708.            ->orderBy('t.TagName''ASC')
  709.            ->getQuery()
  710.            ->getResult();
  711.         $AccommTypeTags $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  712.            ->where('t.TagType = :tag_type')
  713.            ->setParameter('tag_type''accomm_type')
  714.            ->orderBy('t.TagName''ASC')
  715.            ->getQuery()
  716.            ->getResult();
  717.         $EssentialStayInfo $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  718.            ->where('t.TagType = :tag_type')
  719.            ->setParameter('tag_type''stay_info')
  720.            ->orderBy('t.TagName''ASC')
  721.            ->getQuery()
  722.            ->getResult();
  723.         $UniqueThings $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  724.            ->where('t.TagType = :tag_type')
  725.            ->setParameter('tag_type''unique_things')
  726.            ->orderBy('t.TagName''ASC')
  727.            ->getQuery()
  728.            ->getResult();
  729.         $Activities $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
  730.            ->where('t.TagType = :tag_type')
  731.            ->setParameter('tag_type''activities')
  732.            ->orderBy('t.TagName''ASC')
  733.            ->getQuery()
  734.            ->getResult();
  735.         $RegionList $this->getDoctrine()->getRepository(Regions::class)->findAll();
  736.         $GetSelectedTags $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy([
  737.                 'Room' => $AccommType,
  738.         ]);
  739.         $SelectedTags = [];
  740.         foreach ($GetSelectedTags as $ThisTag) {
  741.             $SelectedTags[$ThisTag->getTag()->getId()] = $ThisTag->getTag()->getId();
  742.         }
  743.         $SyncList $this->getDoctrine()->getRepository(TrackedCalendars::class)->findBy([
  744.             'RoomCode' => $AccommType->getRoomCode(),
  745.         ]);
  746.         return $this->render('listing/newaccomm.html.twig', [
  747.             'listing' => $Property,
  748.             'room' => $AccommType,
  749.             'room_amenities' => $RoomAmenities,
  750.             'selected_tags' => $SelectedTags,
  751.             'eating_drinking' => $EatingDrinking,
  752.             'accomm_type' => $AccommTypeTags,
  753.             'essential_stay' => $EssentialStayInfo,
  754.             'unique_things' => $UniqueThings,
  755.             'activities' => $Activities,
  756.             'regions' => $RegionList,
  757.             'synclist' => $SyncList,
  758.         ]);
  759.     }
  760.     public function setRegion($room_id$region_id)
  761.     {
  762.         $Room $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
  763.         $Region $this->getDoctrine()->getRepository(Regions::class)->find($region_id);
  764.         $Room->setRegion($Region);
  765.         $entityManager $this->getDoctrine()->getManager();
  766.         $entityManager->persist($Room);
  767.         $entityManager->flush();
  768.         return new Response('success');
  769.     }
  770.     public function newAddon($listing_codeRequest $request)
  771.     {
  772.         $Addon = new Addons();
  773.         $Addon->setPropertyCode($listing_code);
  774.         $Addon->setPriceMode('A');
  775.         $Addon->setEnabled(true);
  776.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  777.             'ListingCode' => $listing_code,
  778.         ]);
  779.         $form $this->createFormBuilder($Addon)
  780.             ->add('Title'TextType::class)
  781.             ->add('Description'TextareaType::class)
  782.             ->add('PriceMode'ChoiceType::class, [
  783.                 'choices' => [
  784.                     'One Off / Per Person' => 'A',
  785.                     'Daily / Per Person' => 'B',
  786.                     'Daily / Per Trip (flat rate)' => 'C',
  787.                     'One Off / Per Trip (flat rate)' => 'D',
  788.                 ],
  789.             ])
  790.             ->add('PricePer'MoneyType::class)
  791.             ->add('PerName'TextType::class)
  792.             ->add('MaxPeople'NumberType::class)
  793.             ->add('save'SubmitType::class, ['label' => 'Save'])
  794.             ->getForm();
  795.         $form->handleRequest($request);
  796.         if ($form->isSubmitted() && $form->isValid()) {
  797.             // $form->getData() holds the submitted values
  798.             // but, the original `$task` variable has also been updated
  799.             $Addon $form->getData();
  800.             // ... perform some action, such as saving the Property to the database
  801.             // for example, if Property is a Doctrine entity, save it!
  802.             $entityManager $this->getDoctrine()->getManager();
  803.             $entityManager->persist($Addon);
  804.             $entityManager->flush();
  805.             $email = new \SendGrid\Mail\Mail();
  806.             $email->setFrom('support@otbt.co.nz''OTBT System');
  807.             $email->addTo('info@otbt.co.nz');
  808.             $email->setSubject('New Addon Created - Property: '.$Property->getPropertyTitle());
  809.             $email->addContent(
  810.                 'text/html',
  811.                 'Hi Admin, <br><br>A new addon has been added to '.$Property->getPropertyTitle().'. The new data is as follows:<br><br><pre>'.print_r($Addontrue).'</pre><br>  <br><br>Thanks, <br>OTBT System'
  812.             );
  813.             $sendgrid = new \App\Classes\SendGrid();
  814.             try {
  815.                 $response $sendgrid->send($email);
  816.             } catch (Exception $e) {
  817.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  818.             }
  819.             return $this->redirectToRoute('new_listing_overview', ['property_id' => $Property->getId()]);
  820.         }
  821.         return $this->render('listing/addon.html.twig', [
  822.             'newaddon' => $form->createView(),
  823.         ]);
  824.     }
  825.     public function editAddon($addon_idRequest $request)
  826.     {
  827.         $Addon $this->getDoctrine()->getRepository(Addons::class)->find($addon_id);
  828.         $AddonCurrently print_r($Addontrue);
  829.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  830.             'ListingCode' => $Addon->getPropertyCode(),
  831.         ]);
  832.         $form $this->createFormBuilder($Addon)
  833.             ->add('Title'TextType::class)
  834.             ->add('Description'TextareaType::class)
  835.             ->add('PriceMode'ChoiceType::class, [
  836.                 'choices' => [
  837.                     'One Off / Per Person' => 'A',
  838.                     'Daily / Per Person' => 'B',
  839.                     'Daily / Per Trip (flat rate)' => 'C',
  840.                     'One Off / Per Trip (flat rate)' => 'D',
  841.                 ],
  842.             ])
  843.             ->add('PricePer'TextType::class)
  844.             ->add('PerName'TextType::class)
  845.             ->add('MaxPeople'TextType::class)
  846.             ->add('save'SubmitType::class, ['label' => 'Save'])
  847.             ->getForm();
  848.         $form->handleRequest($request);
  849.         if ($form->isSubmitted() && $form->isValid()) {
  850.             // $form->getData() holds the submitted values
  851.             // but, the original `$task` variable has also been updated
  852.             $Addon $form->getData();
  853.             // ... perform some action, such as saving the Property to the database
  854.             // for example, if Property is a Doctrine entity, save it!
  855.             $entityManager $this->getDoctrine()->getManager();
  856.             $entityManager->persist($Addon);
  857.             $entityManager->flush();
  858.             $email = new \SendGrid\Mail\Mail();
  859.             $email->setFrom('support@otbt.co.nz''OTBT System');
  860.             $email->addTo('info@otbt.co.nz');
  861.             $email->setSubject('Addon has been Edited: '.$Addon->getTitle());
  862.             $email->addContent(
  863.                 'text/html',
  864.                 'Hi Admin, <br><br>An addon: '.$Addon->getTitle().' at '.$Property->getPropertyTitle()." has been edited. The new data is as follows:<br><br><table border='1'><tr><td>The data was:<br><br><pre>".$AddonCurrently.'</pre></td><td>The new data is as follows:<br><br><pre>'.print_r($Addontrue).'</pre></td></tr></table><pre>'.print_r($Addontrue).'</pre><br>  <br><br>Thanks, <br>OTBT System'
  865.             );
  866.             $sendgrid = new \App\Classes\SendGrid();
  867.             try {
  868.                 $response $sendgrid->send($email);
  869.             } catch (Exception $e) {
  870.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  871.             }
  872.             if ('Draft' == $Property->getListingStatus()) {
  873.                 return $this->redirectToRoute('new_listing_overview', ['property_id' => $Property->getId()]);
  874.             } else {
  875.                 return $this->redirectToRoute('edit_listing', ['listing_code' => $Property->getListingCode()]);
  876.             }
  877.         }
  878.         return $this->render('listing/addon.html.twig', [
  879.             'newaddon' => $form->createView(),
  880.         ]);
  881.     }
  882.     public function listingQuestion(Request $request)
  883.     {
  884.         $person_name $request->request->get('person_name');
  885.         $person_email $request->request->get('person_email');
  886.         $question $request->request->get('question');
  887.         $room_name $request->request->get('room_name');
  888.         $email = new \SendGrid\Mail\Mail();
  889.         $email->setFrom('support@otbt.co.nz''OTBT System');
  890.         $email->addTo('info@otbt.co.nz');
  891.         $email->addTo('support@otbt.co.nz');
  892.         $email->setTemplateId('d-fb55f6c29f294cae97c063f9f97dd95e'); // UPDATED SG TEMPLATE 20224
  893.         $email->addDynamicTemplateDatas([
  894.             'person_name' => $person_name,
  895.             'person_email' => $person_email,
  896.             'question' => $question,
  897.             'room_name' => $room_name,
  898.         ]);
  899.         $sendgrid = new \App\Classes\SendGrid();
  900.         try {
  901.             $response $sendgrid->send($email);
  902.         } catch (Exception $e) {
  903.             echo 'Caught exception: ',  $e->getMessage(), "\n";
  904.         }
  905.         return new Response('success');
  906.     }
  907.     public function landownerQAreply(ListingQuestions $qaRequest $requestUrlGeneratorInterface $router)
  908.     {
  909.         $entityManager $this->getDoctrine()->getManager();
  910.         $Room $qa->getRoom();
  911.         $Landowner $this->getDoctrine()->getRepository(User::class)->find($Room->getLandownerId());
  912.         if ($Landowner->getId() !== $this->getUser()->getId()) {
  913.             return new Response('unauthorized');
  914.         } else {
  915.             $form $this->createFormBuilder($qa)
  916.             ->add('Answer'TextareaType::class)
  917.             ->add('save'SubmitType::class, ['label' => 'Submit Answer'])
  918.             ->getForm();
  919.             $form->handleRequest($request);
  920.             if ($form->isSubmitted() && $form->isValid()) {
  921.                 // $form->getData() holds the submitted values
  922.                 // but, the original `$task` variable has also been updated
  923.                 $qa $form->getData();
  924.                 $qa->setAnsweredDate(new \DateTime());
  925.                 $qa->setAnsweredBy($this->getUser());
  926.                 $ModerateURL 'https://'.$_SERVER['SERVER_NAME'].$router->generate('admin_listingquestions_moderate', ['id' => $qa->getId()]);
  927.                 $entityManager->persist($qa);
  928.                 $entityManager->flush();
  929.                 $email = new \SendGrid\Mail\Mail();
  930.                 $email->setFrom('support@otbt.co.nz''OTBT System');
  931.                 $email->addTo('info@otbt.co.nz');
  932.                 // $email->addTo("partner.otbt@luminate.one");
  933.                 $email->setSubject('New QA to be moderated');
  934.                 $email->addContent(
  935.                     'text/html',
  936.                     "Hi team, <br>a new question has been answered by a landowner. <a href='".$ModerateURL."'>Please moderate now</a> so the answer can be released to the asker."
  937.                 );
  938.                 $sendgrid = new \App\Classes\SendGrid();
  939.                 try {
  940.                     $response $sendgrid->send($email);
  941.                 } catch (Exception $e) {
  942.                     echo 'Caught exception: ',  $e->getMessage(), "\n";
  943.                 }
  944.                 return $this->render('listing/landownerQAreplyDONE.html.twig', [
  945.                     'qa' => $qa,
  946.                 ]);
  947.             } else {
  948.                 return $this->render('listing/landownerQAreply.html.twig', [
  949.                     'form' => $form->createView(),
  950.                     'qa' => $qa,
  951.                 ]);
  952.             }
  953.         }
  954.     }
  955.     public function reviewNewListing($listing_code)
  956.     {
  957.         $user_id $this->getUser()->getId();
  958.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  959.             'ListingCode' => $listing_code,
  960.             'LandownerId' => $user_id,
  961.         ]);
  962.         $AccommType $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
  963.             'PropertyCode' => $listing_code,
  964.             'LandownerId' => $user_id,
  965.         ]);
  966.         $AllTags $this->getDoctrine()->getRepository(PropertyTags::class)->findAll();
  967.         $GetAllTags = [];
  968.         foreach ($AllTags as $ThisTag) {
  969.             $GetAllTags[$ThisTag->getId()] = $ThisTag;
  970.         }
  971.         $GetSelectedTags $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy([
  972.                 'Room' => $AccommType,
  973.         ]);
  974.         $SelectedTags = [];
  975.         foreach ($GetSelectedTags as $ThisTag) {
  976.             $SelectedTags[] = $GetAllTags[$ThisTag->getTag()->getId()];
  977.         }
  978.         return $this->render('listing/reviewlisting.html.twig', [
  979.             'property' => $Property,
  980.             'accomm' => $AccommType,
  981.             'listing_code' => $listing_code,
  982.             'room_code' => $AccommType->getRoomCode(),
  983.             'selected_tags' => $SelectedTags,
  984.             'mode' => 'review',
  985.         ]);
  986.     }
  987.     public function editListingNew($listing_code)
  988.     {
  989.         $user_id $this->getUser()->getId();
  990.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  991.             'ListingCode' => $listing_code,
  992.             'LandownerId' => $user_id,
  993.         ]);
  994.         if ('New' == $Property->getListingStatus()) {
  995.             return $this->redirectToRoute('new_listing_overview', ['property_id' => $Property->getId()]);
  996.         }
  997.         $AccommTypes $this->getDoctrine()->getRepository(AccommodationType::class)->findBy([
  998.             'PropertyCode' => $listing_code,
  999.             'LandownerId' => $user_id,
  1000.         ]);
  1001.         $Addons $this->getDoctrine()->getRepository(Addons::class)->findBy([
  1002.             'PropertyCode' => $listing_code,
  1003.                 'Enabled' => true,
  1004.         ]);
  1005.         return $this->render('listing/reviewlisting.html.twig', [
  1006.             'property' => $Property,
  1007.             'listing_code' => $listing_code,
  1008.             'mode' => 'edit',
  1009.             'accomm_types' => $AccommTypes,
  1010.             'addons' => $Addons,
  1011.         ]);
  1012.     }
  1013.     public function submitNewListing($listing_code)
  1014.     {
  1015.         $user_id $this->getUser()->getId();
  1016.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy([
  1017.             'ListingCode' => $listing_code,
  1018.             'LandownerId' => $user_id,
  1019.         ]);
  1020.         $UserInfo $this->getDoctrine()->getRepository(User::class)->find($user_id);
  1021.         $Property->setListingStatus('Awaiting Review');
  1022.         $entityManager $this->getDoctrine()->getManager();
  1023.         $entityManager->persist($Property);
  1024.         $entityManager->flush();
  1025.         $email = new \SendGrid\Mail\Mail();
  1026.         $email->setFrom('support@otbt.co.nz''OTBT System');
  1027.         $email->addTo($UserInfo->getEmail());
  1028.         $email->setTemplateId('d-a89cf56c0e214ca0bd825836128c26cd'); // UPDATE SG TEMPLATE 2024
  1029.         $sendgrid = new \App\Classes\SendGrid();
  1030.         try {
  1031.             $response $sendgrid->send($email);
  1032.         } catch (Exception $e) {
  1033.             echo 'Caught exception: ',  $e->getMessage(), "\n";
  1034.         }
  1035.         $email = new \SendGrid\Mail\Mail();
  1036.         $email->setFrom('support@otbt.co.nz''OTBT System');
  1037.         $email->addTo('info@otbt.co.nz');
  1038.         $email->setSubject('New Property Submitted for Review');
  1039.         $email->addContent(
  1040.             'text/html',
  1041.             'Hi Admin, <br>A new property has been submitted for review - '.$Property->getPropertyTitle().'. It is available to look at in the Properties section of the admin panel.<br><br>Thanks, <br>OTBT System'
  1042.         );
  1043.         $sendgrid = new \App\Classes\SendGrid();
  1044.         try {
  1045.             $response $sendgrid->send($email);
  1046.         } catch (Exception $e) {
  1047.             echo 'Caught exception: ',  $e->getMessage(), "\n";
  1048.         }
  1049.         $GetAccommTypes $this->getDoctrine()->getRepository(AccommodationType::class)->findBy(['PropertyCode' => $Property->getListingCode()]);
  1050.         foreach ($GetAccommTypes as $thisAccomm) {
  1051.             if ('New Accommodation Type' == $thisAccomm->getRoomName() && == $thisAccomm->getEnabled() && null == $thisAccomm->getRoomDescription() && null == $thisAccomm->getNormalPrice() && null == $thisAccomm->getBeddingConfiguration() && null == $thisAccomm->getEatingDrinking()) {
  1052.                 $entityManager->remove($thisAccomm);
  1053.             }
  1054.         }
  1055.         $entityManager->flush();
  1056.         return $this->render('listing/submitreview.html.twig', [
  1057.             'listing_code' => $listing_code,
  1058.         ]);
  1059.     }
  1060.     public function deletePhoto($photo_id)
  1061.     {
  1062.         $Media $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
  1063.         $entityManager $this->getDoctrine()->getManager();
  1064.         $entityManager->remove($Media);
  1065.         $entityManager->flush();
  1066.         return new Response('success');
  1067.     }
  1068.     public function applyTag($room_id$tag_id)
  1069.     {
  1070.         $GetTag $this->getDoctrine()->getRepository(PropertyTags::class)->find($tag_id);
  1071.         $Room $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
  1072.         $entityManager $this->getDoctrine()->getManager();
  1073.         $TagApplied = new PropertyTagsApplied();
  1074.         $TagApplied->setRoom($Room);
  1075.         $TagApplied->setTag($GetTag);
  1076.         $entityManager->persist($TagApplied);
  1077.         $entityManager->flush();
  1078.         return new Response('success');
  1079.     }
  1080.     public function removeTag($room_id$tag_id)
  1081.     {
  1082.         $Room $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
  1083.         $Tag $this->getDoctrine()->getRepository(PropertyTags::class)->find($tag_id);
  1084.         $entityManager $this->getDoctrine()->getManager();
  1085.         $TagApplied $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findOneBy(['Room' => $Room'Tag' => $Tag]);
  1086.         $entityManager $this->getDoctrine()->getManager();
  1087.         $entityManager->remove($TagApplied);
  1088.         $entityManager->flush();
  1089.         return new Response('success');
  1090.     }
  1091.     public function updateProfilePicture(Request $requestGlobalFunctions $GlobalFnMessageBusInterface $messageBus)
  1092.     {
  1093.         @$Mode $_GET['mode'];
  1094.         if (!isset($Mode)) {
  1095.             $Mode 'edit';
  1096.         }
  1097.         @$PropertyId $_GET['property_id'];
  1098.         if (!isset($PropertyId)) {
  1099.             $PropertyId null;
  1100.         }
  1101.         $user_id $this->getUser()->getId();
  1102.         $Media $this->getDoctrine()->getRepository(Media::class)->findOneBy(['UserId' => $user_id]);
  1103.         $ProfilePicture $GlobalFn->user_photo($user_id);
  1104.         if (!$Media) {
  1105.             $Media = new Media();
  1106.             $Media->setUserId($user_id);
  1107.         }
  1108.         $entityManager $this->getDoctrine()->getManager();
  1109.         $form $this->createFormBuilder($Media)
  1110.             ->add('documentFile'VichImageType::class, ['allow_delete' => true'download_link' => false])
  1111.             ->add('save'SubmitType::class, ['label' => 'Upload'])
  1112.             ->getForm();
  1113.         $form->handleRequest($request);
  1114.         if ($form->isSubmitted() && $form->isValid()) {
  1115.             // $form->getData() holds the submitted values
  1116.             // but, the original `$task` variable has also been updated
  1117.             $Media $form->getData();
  1118.             $entityManager->persist($Media);
  1119.             $entityManager->flush();
  1120.             $ProfilePicture $GlobalFn->user_photo($user_id);
  1121.             $messageBus->dispatch(new WarmupCache($ProfilePicture));
  1122.             return $this->redirectToRoute('profile_picture');
  1123.         }
  1124.         return $this->render('listing/updateprofilepic.html.twig', [
  1125.             'form' => $form->createView(),
  1126.             'user' => $this->getUser(),
  1127.             'profile_picture' => $ProfilePicture,
  1128.             'updatemessage' => 0,
  1129.             'mode' => $Mode,
  1130.             'property_id' => $PropertyId,
  1131.         ]);
  1132.     }
  1133.     public function landownerPriceAdjustment($accomm_idRequest $request)
  1134.     {
  1135.         $entityManager $this->getDoctrine()->getManager();
  1136.         $Accomm $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
  1137.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Accomm->getPropertyCode()]);
  1138.         if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
  1139.             return new Exception('You do not have permission to access this');
  1140.         } else {
  1141.             $AccommPricing $this->getDoctrine()->getRepository(PricingNights::class)->findBy(['RoomCode' => $Accomm->getRoomCode()]);
  1142.             $StayPricing $this->getDoctrine()->getRepository(PricingStay::class)->findBy(['RoomCode' => $Accomm->getRoomCode()]);
  1143.             $accommForm $this->createFormBuilder($Accomm)
  1144.                 ->add('NightlyQnt'ChoiceType::class, [
  1145.                 'required' => true,
  1146.                 'choices' => [
  1147.                     => 1234567891011121314151617181920,
  1148.                 ],
  1149.                 ])
  1150.                 ->add('NormalPrice'MoneyType::class, ['required' => true'currency' => 'NZD'])
  1151.                 ->add('MaxGuests'ChoiceType::class, [
  1152.                     'required' => true,
  1153.                     'choices' => [
  1154.                         => 1234567891011121314151617181920,
  1155.                     ],
  1156.                 ])
  1157.                 ->add('MaxAdditionalGuests'ChoiceType::class, [
  1158.                     'required' => true,
  1159.                     'choices' => [
  1160.                         'No additional guests' => 0=> 123456789101112131415,
  1161.                     ],
  1162.                 ])
  1163.                 ->add('AdditionalGuestPrice'MoneyType::class, ['required' => false'currency' => 'NZD'])
  1164.                 ->add('PriceMode'ChoiceType::class, [
  1165.                     'required' => true,
  1166.                     'choices' => [
  1167.                         'Per Night' => 'pn',
  1168.                         'Per Person Per Night' => 'pppn',
  1169.                     ],
  1170.                     'expanded' => false,
  1171.                     'multiple' => false,
  1172.                 ])
  1173.                 ->add('MinimumNights'ChoiceType::class, [
  1174.                     'required' => true,
  1175.                     'choices' => [
  1176.                         'Minimum 1 night' => 1=> 234567891011121314151617181920,
  1177.                     ],
  1178.                 ])
  1179.                 ->add('save'SubmitType::class, ['label' => 'Update'])
  1180.                 ->getForm();
  1181.             $accommForm->handleRequest($request);
  1182.             if ($accommForm->isSubmitted() && $accommForm->isValid()) {
  1183.                 // $accommForm->getData() holds the submitted values
  1184.                 // but, the original `$task` variable has also been updated
  1185.                 $Accomm $accommForm->getData();
  1186.                 $Accomm->setRoomCode($Accomm->getRoomCode());
  1187.                 $entityManager->persist($Accomm);
  1188.                 $entityManager->flush();
  1189.                 return $this->redirectToRoute('landowner_price_adjustments', ['accomm_id' => $accomm_id]);
  1190.             }
  1191.             $MinimumNightAdjustments $this->getDoctrine()->getRepository(MinimumNightOverride::class)->findBy(['Room' => $Accomm]);
  1192.             return $this->render('listing/landownerpriceadjustments.html.twig', [
  1193.                 'accomm_form' => $accommForm->createView(),
  1194.                 'pricing' => $AccommPricing,
  1195.                 'accomm' => $Accomm,
  1196.                 'property' => $Property,
  1197.                 'staypricing' => $StayPricing,
  1198.                 'minimum_night_adjustments' => $MinimumNightAdjustments,
  1199.             ]);
  1200.         }
  1201.     }
  1202.     public function newMinimumNightAdjustment(AccommodationType $roomRequest $request)
  1203.     {
  1204.         $newadj_fromdate $request->request->get('date_from');
  1205.         $newadj_todate $request->request->get('date_to');
  1206.         $newadj_selectedweek $request->request->get('selecteddow');
  1207.         $newadj_minnights = (int) $request->request->get('setminimumnight');
  1208.         if ('' == $newadj_fromdate) {
  1209.             $newadj_fromdate null;
  1210.         } else {
  1211.             $newadj_fromdate = new \DateTime($newadj_fromdate);
  1212.             $newadj_todate = new \DateTime($newadj_todate);
  1213.         }
  1214.         if ('-' == $newadj_selectedweek) {
  1215.             $newadj_selectedweek null;
  1216.         }
  1217.         $MinNightOverride = new MinimumNightOverride();
  1218.         $MinNightOverride->setRoom($room);
  1219.         if (!empty($newadj_fromdate)) {
  1220.             $MinNightOverride->setAppliesFromDate($newadj_fromdate);
  1221.             $MinNightOverride->setAppliesToDate($newadj_todate);
  1222.         }
  1223.         $MinNightOverride->setDayOfWeek($newadj_selectedweek);
  1224.         $MinNightOverride->setSetMinimumNights($newadj_minnights);
  1225.         $entityManager $this->getDoctrine()->getManager();
  1226.         $entityManager->persist($MinNightOverride);
  1227.         $entityManager->flush();
  1228.         return new Response('success');
  1229.     }
  1230.     public function deleteMinNightAdjustment(Request $request)
  1231.     {
  1232.         $adj $this->getDoctrine()->getRepository(MinimumNightOverride::class)->find($request->request->get('adj_id'));
  1233.         $entityManager $this->getDoctrine()->getManager();
  1234.         $entityManager->remove($adj);
  1235.         $entityManager->flush();
  1236.         return new Response('success');
  1237.     }
  1238.     public function landownerPriceAdjustmentAdd($accomm_idRequest $request)
  1239.     {
  1240.         $entityManager $this->getDoctrine()->getManager();
  1241.         $Accomm $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
  1242.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Accomm->getPropertyCode()]);
  1243.         if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
  1244.             return new Exception('You do not have permission to access this');
  1245.         } else {
  1246.             $AccommPricing $this->getDoctrine()->getRepository(PricingNights::class)->findBy(['RoomCode' => $Accomm->getRoomCode()]);
  1247.             $NewPricing = new PricingNights();
  1248.             $NewPricing->setDaysOfWeek('[Mon][Tue][Wed][Thu][Fri][Sat][Sun]');
  1249.             $form $this->createFormBuilder($NewPricing)
  1250.                 ->add('DateFrom'DateType::class, ['required' => true])
  1251.                 ->add('DateTo'DateType::class, ['required' => true])
  1252.                 ->add('DaysOfWeek'HiddenType::class, ['required' => true])
  1253.                 ->add('Adjustment'TextType::class, ['required' => true])
  1254.                 ->add('Description'TextType::class, ['required' => true])
  1255.                 ->add('save'SubmitType::class, ['label' => 'Add New'])
  1256.                 ->getForm();
  1257.             $form->handleRequest($request);
  1258.             if ($form->isSubmitted() && $form->isValid()) {
  1259.                 // $form->getData() holds the submitted values
  1260.                 // but, the original `$task` variable has also been updated
  1261.                 $NewPricing $form->getData();
  1262.                 $NewPricing->setRoomCode($Accomm->getRoomCode());
  1263.                 $entityManager->persist($NewPricing);
  1264.                 $entityManager->flush();
  1265.                 return $this->redirectToRoute('landowner_price_adjustments', ['accomm_id' => $accomm_id]);
  1266.             }
  1267.             return $this->render('listing/landownerpriceadjustmentsadd.html.twig', [
  1268.                 'form' => $form->createView(),
  1269.                 'pricing' => $AccommPricing,
  1270.                 'accomm' => $Accomm,
  1271.                 'property' => $Property,
  1272.             ]);
  1273.         }
  1274.     }
  1275.     public function stayPricingAdd($accomm_idRequest $request)
  1276.     {
  1277.         $entityManager $this->getDoctrine()->getManager();
  1278.         $Accomm $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
  1279.         $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Accomm->getPropertyCode()]);
  1280.         if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
  1281.             return new Exception('You do not have permission to access this');
  1282.         } else {
  1283.             $NewPricing = new PricingStay();
  1284.             $form $this->createFormBuilder($NewPricing)
  1285.                 ->add('DateFrom'DateType::class, ['required' => true])
  1286.                 ->add('DateTo'DateType::class, ['required' => true])
  1287.                 ->add('MinNights'TextType::class, ['required' => true])
  1288.                 ->add('Adjustment'TextType::class, ['required' => false])
  1289.                 ->add('PercentageAdjustment'TextType::class, ['required' => false])
  1290.                 ->add('LineDescription'TextType::class, ['required' => true])
  1291.                 ->add('save'SubmitType::class, ['label' => 'Add New'])
  1292.                 ->getForm();
  1293.             $form->handleRequest($request);
  1294.             if ($form->isSubmitted() && $form->isValid()) {
  1295.                 // $form->getData() holds the submitted values
  1296.                 // but, the original `$task` variable has also been updated
  1297.                 $NewPricing $form->getData();
  1298.                 $NewPricing->setRoomCode($Accomm->getRoomCode());
  1299.                 $entityManager->persist($NewPricing);
  1300.                 $entityManager->flush();
  1301.                 return $this->redirectToRoute('landowner_price_adjustments', ['accomm_id' => $accomm_id]);
  1302.             }
  1303.             return $this->render('listing/staypricingadd.html.twig', [
  1304.                 'form' => $form->createView(),
  1305.                 'accomm' => $Accomm,
  1306.                 'property' => $Property,
  1307.             ]);
  1308.         }
  1309.     }
  1310.     public function landownerPriceAdjustmentDelete($accomm_id$adj_id)
  1311.     {
  1312.         $entityManager $this->getDoctrine()->getManager();
  1313.         $Accomm $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
  1314.         if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
  1315.             return new Exception('You do not have permission to access this');
  1316.         } else {
  1317.             $AccommPricing $this->getDoctrine()->getRepository(PricingNights::class)->find($adj_id);
  1318.             $entityManager->remove($AccommPricing);
  1319.             $entityManager->flush();
  1320.             return new Response('success');
  1321.         }
  1322.     }
  1323.     public function priceStayDelete($accomm_id$price_id)
  1324.     {
  1325.         $entityManager $this->getDoctrine()->getManager();
  1326.         $Accomm $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
  1327.         if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
  1328.             return new Exception('You do not have permission to access this');
  1329.         } else {
  1330.             $AccommPricing $this->getDoctrine()->getRepository(PricingStay::class)->find($price_id);
  1331.             $entityManager->remove($AccommPricing);
  1332.             $entityManager->flush();
  1333.             return new Response('success');
  1334.         }
  1335.     }
  1336.     public function newlistingoverview($property_idGlobalFunctions $GlobalFn)
  1337.     {
  1338.         $entityManager $this->getDoctrine()->getManager();
  1339.         $Property $this->getDoctrine()->getRepository(Property::class)->find($property_id);
  1340.         $Landowner $this->getDoctrine()->getRepository(User::class)->find($Property->getLandownerId());
  1341.         $ProfilePicture $GlobalFn->user_photo($this->getUser()->getId());
  1342.         if ($Property) {
  1343.             if ($Property->getLandownerId() == $this->getUser()->getId()) {
  1344.                 $AccommTypes $this->getDoctrine()->getRepository(AccommodationType::class)->findBy(['PropertyCode' => $Property->getListingCode()]);
  1345.                 $Addons $this->getDoctrine()->getRepository(Addons::class)->findBy(['PropertyCode' => $Property->getListingCode(), 'Enabled' => 1]);
  1346.                 $TrackedCalendars = [];
  1347.                 foreach ($AccommTypes as $thisAccomm) {
  1348.                     $Calendars $this->getDoctrine()->getRepository(TrackedCalendars::class)->findBy(['RoomCode' => $thisAccomm->getRoomCode()]);
  1349.                     $TrackedCalendars[$thisAccomm->getRoomCode()] = count($Calendars);
  1350.                 }
  1351.                 $TagsApplied = [];
  1352.                 foreach ($AccommTypes as $thisAccomm) {
  1353.                     $PropertyTags $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy(['Room' => $thisAccomm]);
  1354.                     $TagsApplied[$thisAccomm->getId()] = count($PropertyTags);
  1355.                 }
  1356.                 return $this->render('listing/newlistingoverview.html.twig', [
  1357.                     'property' => $Property,
  1358.                     'landowner' => $Landowner,
  1359.                     'accomm_types' => $AccommTypes,
  1360.                     'addons' => $Addons,
  1361.                     'profile_picture' => $ProfilePicture,
  1362.                     'tracked_calendars' => $TrackedCalendars,
  1363.                     'tags_applied' => $TagsApplied,
  1364.                 ]);
  1365.             } else {
  1366.                 return new Response('Sorry, you are not authorised to see this item');
  1367.             }
  1368.         } else {
  1369.             return new Response('Sorry, you are not authorised to see this item');
  1370.         }
  1371.     }
  1372.     public function imgjseditor($photo_id)
  1373.     {
  1374.         $entityManager $this->getDoctrine()->getManager();
  1375.         $Photo $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
  1376.         $random_number rand(100000999999);
  1377.         return $this->render('listing/imgjseditor.html.twig', [
  1378.             'photo' => $Photo,
  1379.             'random_number' => $random_number,
  1380.         ]);
  1381.     }
  1382.     public function rotate_img($photo_id$degreesMessageBusInterface $messageBus)
  1383.     {
  1384.         @ini_set('memory_limit''256M');
  1385.         $entityManager $this->getDoctrine()->getManager();
  1386.         $Photo $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
  1387.         $filepath '../public/media/'.$Photo->getDocumentFileName();
  1388.         if (IMAGETYPE_JPEG == exif_imagetype($filepath)) {
  1389.             /** @var resource $source */
  1390.             $source imagecreatefromjpeg($filepath);
  1391.             /** @var resource $rotate */
  1392.             $rotate imagerotate($source$degrees0);
  1393.             imagejpeg($rotate$filepath);
  1394.         } elseif (IMAGETYPE_PNG == exif_imagetype($filepath)) {
  1395.             /** @var resource $source */
  1396.             $source imagecreatefrompng($filepath);
  1397.             /** @var resource $rotate */
  1398.             $rotate imagerotate($source$degrees0);
  1399.             imagepng($rotate$filepath);
  1400.         } else {
  1401.             return new Response('error - image type not accepted');
  1402.         }
  1403.         imagedestroy($source);
  1404.         imagedestroy($rotate);
  1405.         if ('1' == substr($Photo->getDocumentFileName(), 01) && '_' == substr($Photo->getDocumentFileName(), 101)) {
  1406.             $ActualFilename time().'_'.substr($Photo->getDocumentFileName(), 11);
  1407.             $NewFileName $ActualFilename;
  1408.             rename('../public/media/'.$Photo->getDocumentFileName(), '../public/media/'.$NewFileName);
  1409.             $messageBus->dispatch(new WarmupCache('media/'.$NewFileName));
  1410.         } else {
  1411.             $ActualFilename time().'_'.$Photo->getDocumentFileName();
  1412.             $NewFileName $ActualFilename;
  1413.             rename('../public/media/'.$Photo->getDocumentFileName(), '../public/media/'.$NewFileName);
  1414.             $messageBus->dispatch(new WarmupCache('media/'.$NewFileName));
  1415.         }
  1416.         $Photo->setDocumentFileName($ActualFilename);
  1417.         $entityManager->persist($Photo);
  1418.         $entityManager->flush();
  1419.         return new Response('success');
  1420.     }
  1421.     public function reorder_photo($photo_id$direction)
  1422.     {
  1423.         $entityManager $this->getDoctrine()->getManager();
  1424.         $Photo $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
  1425.         $AllPhotos $this->getDoctrine()->getRepository(Media::class)->findBy(['RoomCode' => $Photo->getRoomCode()], ['DisplayOrder' => 'ASC']);
  1426.         $Order 1;
  1427.         foreach ($AllPhotos as $ThisPhoto) {
  1428.             if (null === $ThisPhoto->getDisplayOrder()) {
  1429.                 $ThisPhoto->setDisplayOrder($Order);
  1430.                 $entityManager->persist($ThisPhoto);
  1431.             }
  1432.             ++$Order;
  1433.         }
  1434.         $entityManager->flush();
  1435.         if ('up' == $direction) {
  1436.             $DirectionBelow $Photo->getDisplayOrder() - 1;
  1437.             $PhotoBelow $this->getDoctrine()->getRepository(Media::class)->findOneBy(['RoomCode' => $Photo->getRoomCode(), 'DisplayOrder' => $DirectionBelow]);
  1438.             $PhotoBelow->setDisplayOrder($Photo->getDisplayOrder());
  1439.             $Photo->setDisplayOrder($DirectionBelow);
  1440.             $entityManager->persist($Photo);
  1441.             $entityManager->persist($PhotoBelow);
  1442.             $entityManager->flush();
  1443.         }
  1444.         if ('down' == $direction) {
  1445.             $DirectionAbove $Photo->getDisplayOrder() + 1;
  1446.             $PhotoAbove $this->getDoctrine()->getRepository(Media::class)->findOneBy(['RoomCode' => $Photo->getRoomCode(), 'DisplayOrder' => $DirectionAbove]);
  1447.             $PhotoAbove->setDisplayOrder($Photo->getDisplayOrder());
  1448.             $Photo->setDisplayOrder($DirectionAbove);
  1449.             $entityManager->persist($Photo);
  1450.             $entityManager->persist($PhotoAbove);
  1451.             $entityManager->flush();
  1452.         }
  1453.         return new Response('success');
  1454.     }
  1455.     public function makeDefault($photo_id)
  1456.     {
  1457.         $entityManager $this->getDoctrine()->getManager();
  1458.         $Photo $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
  1459.         $AllPhotos $this->getDoctrine()->getRepository(Media::class)->findBy(['RoomCode' => $Photo->getRoomCode()], ['DisplayOrder' => 'ASC']);
  1460.         foreach ($AllPhotos as $ThisPhoto) {
  1461.             $ThisPhoto->setSearchDefault(null);
  1462.             $ThisPhoto->setDefaultImage(null);
  1463.         }
  1464.         $Photo->setSearchDefault(1);
  1465.         $Photo->setDefaultImage(1);
  1466.         // Get room ID as frontend uses this to display the correct images on search
  1467.         $room $this->getDoctrine()->getRepository(AccommodationType::class)->findBy(['RoomCode' => $Photo->getRoomCode()])[0];
  1468.         if (null !== $room && $Photo) {
  1469.             $Photo->setAccommType($room);
  1470.         }
  1471.         $entityManager->persist($Photo);
  1472.         $entityManager->flush();
  1473.         return new Response('success');
  1474.     }
  1475.     public function updateUserBio(Request $request)
  1476.     {
  1477.         $new_bio $request->request->get('new_bio');
  1478.         $entityManager $this->getDoctrine()->getManager();
  1479.         $User $this->getUser();
  1480.         $User->setBio($new_bio);
  1481.         $entityManager->persist($User);
  1482.         $entityManager->flush();
  1483.         return new Response('success');
  1484.     }
  1485.     public function updateUserAcc(Request $request)
  1486.     {
  1487.         $new_acc $request->request->get('new_acc');
  1488.         $entityManager $this->getDoctrine()->getManager();
  1489.         $User $this->getUser();
  1490.         $User->setBankAccountNumber($new_acc);
  1491.         $entityManager->persist($User);
  1492.         $entityManager->flush();
  1493.         return new Response('success');
  1494.     }
  1495. }