<?php
namespace App\Controller;
use App\Entity\AccommodationType;
use App\Entity\Addons;
use App\Entity\BookableExperiences;
use App\Entity\Bookings;
use App\Entity\Favourites;
use App\Entity\ListingQuestions;
use App\Entity\Media;
use App\Entity\MinimumNightOverride;
use App\Entity\PricingNights;
use App\Entity\PricingStay;
use App\Entity\Property;
use App\Entity\PropertyReviews;
use App\Entity\PropertyTags;
use App\Entity\PropertyTagsApplied;
use App\Entity\Regions;
use App\Entity\RoomBannersSpecific;
use App\Entity\RoomURLAlias;
use App\Entity\TrackedCalendars;
use App\Entity\User;
use App\Security\LoginFormAuthenticator;
use App\Service\GlobalFunctions;
use Cocur\Slugify\Slugify;
use Liip\ImagineBundle\Message\WarmupCache;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Vich\UploaderBundle\Form\Type\VichImageType;
class ListingController extends AbstractController
{
public function oldlisting($listing_slug, $room_slug)
{
$em = $this->getDoctrine()->getManager();
$AccommInfo = $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
'RoomSlug' => $room_slug,
'Enabled' => true,
]);
$NewSlug = $AccommInfo->getRoomSlugNew();
if (null == $NewSlug) {
$slugify = new Slugify();
$NewHeadlineSlug = $slugify->slugify($AccommInfo->getSearchHeadline());
$AccommInfo->setRoomSlugNew($NewHeadlineSlug);
$em->persist($AccommInfo);
$em->flush();
$NewSlug = $NewHeadlineSlug;
}
if (isset($_GET['preview_listing'])) {
return $this->redirectToRoute('listing_new_url', ['room_slug_new' => $NewSlug, 'preview_listing' => 'true']);
} else {
return $this->redirectToRoute('listing_new_url', ['room_slug_new' => $NewSlug]);
}
}
public function index($room_slug_new, GlobalFunctions $GlobalFn)
{
$em = $this->getDoctrine()->getManager();
// Overrides for the URL and Aliases
$URL = $this->getDoctrine()->getRepository(RoomURLAlias::class)->findOneBy(['Alias' => $room_slug_new]);
if ($URL) {
return $this->redirectToRoute('listing_new_url', ['room_slug_new' => $URL->getRoom()->getRoomSlugNew()]);
} else {
if (isset($_GET['preview_listing'])) {
$AccommInfo = $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
'RoomSlugNew' => $room_slug_new,
]);
} else {
$AccommInfo = $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
'RoomSlugNew' => $room_slug_new,
'Enabled' => true,
]);
}
}
if (!$AccommInfo) {
return new Response('Sorry, the requested property is not currently available');
}
if (isset($_GET['check_in'])) {
$CheckIn = $_GET['check_in'];
$CheckOut = $_GET['check_out'];
} else {
$CheckIn = null;
$CheckOut = null;
}
$room_slug = $AccommInfo->getRoomSlug();
$PropertyCode = $AccommInfo->getPropertyCode();
$ListingInfo = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $PropertyCode,
]);
$listing_slug = $ListingInfo->getListingSlug();
if (isset($_GET['preview_listing']) or 'Listed' == $ListingInfo->getListingStatus()) {
$LandownerInfo = $this->getDoctrine()->getRepository(User::class)->find($ListingInfo->getLandownerId());
$ListingCode = $ListingInfo->getListingCode();
$RoomTonightPrice = $GlobalFn->nightPrice(0, $AccommInfo->getRoomCode(), date('Y-m-d'));
$GetListingRooms = $this->getDoctrine()->getRepository(AccommodationType::class)->findBy([
'PropertyCode' => $ListingCode,
'Enabled' => true,
]);
$OtherListingRooms = [];
foreach ($GetListingRooms as $thisRoom) {
if ('Listed' == $thisRoom->getProperty()->getListingStatus()) {
if ($thisRoom->getRoomCode() !== $AccommInfo->getRoomCode()) {
$OtherListingRooms[] = $thisRoom;
}
}
}
$CurrentRecentlyViewed = $this->get('session')->get('recently_viewed');
$NewRecentlyViewed = '['.$AccommInfo->getRoomCode().']'.str_replace('['.$AccommInfo->getRoomCode().']', '', $CurrentRecentlyViewed);
$this->get('session')->set('recently_viewed', $NewRecentlyViewed);
// $GetImages = $GlobalFn->listing_photos($ListingCode, 0);
$MainImg = $GlobalFn->room_photos($AccommInfo->getRoomCode(), 1);
$RoomImg = $GlobalFn->room_photos($AccommInfo->getRoomCode(), 0);
$Images = [];
foreach ($RoomImg as $ThisImage) {
$Images[] = ['id' => $ThisImage['id'], 'document_file_name' => 'media/'.$ThisImage['document_file_name'], 'description' => $ThisImage['description']];
}
$UserImg = $this->getDoctrine()->getRepository(Media::class)->findOneBy(['UserId' => $LandownerInfo->getId()]);
if ($UserImg) {
if ('' == $UserImg->getDocumentFileName()) {
$UserImg = ['DocumentFileName' => 'media/OTBT_logo_green_RGB-01.png'];
} else {
$UserImg = ['DocumentFileName' => 'media/'.$UserImg->getDocumentFileName()];
}
} else {
$UserImg = ['DocumentFileName' => 'media/OTBT_logo_green_RGB-01.png'];
}
$Addons = $this->getDoctrine()->getRepository(Addons::class)->findBy([
'PropertyCode' => $ListingCode,
'Enabled' => true,
]);
$AddonImg = [];
foreach ($Addons as $ThisAddon) {
$AddonImg[$ThisAddon->getId()] = $GlobalFn->addon_photos($ThisAddon->getId(), 1);
}
/*$Amenities = $this->getDoctrine()->getRepository(PropertyTags::class)->findBy([
'TagType' => 'amenity',
]);
*/
$GetRoomTags = $ChosenAmenity = $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy([
'Room' => $AccommInfo,
]);
$AllRoomTags = [];
foreach ($GetRoomTags as $thisTag) {
$AllRoomTags[] = $thisTag->getTag()->getId();
}
$ActivitiesFilters = $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->andWhere('t.Params IS NULL')
->setParameter('tag_type', 'activities')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$ChosenActivitiesFilters = [];
$ContraActivitiesFilters = [];
foreach ($ActivitiesFilters as $thisFilter) {
if (in_array($thisFilter->getId(), $AllRoomTags)) {
$ChosenActivitiesFilters[] = $thisFilter;
} else {
if (null !== $thisFilter->getContraTagName()) {
$ContraActivitiesFilters[] = $thisFilter;
}
}
}
// ---
$AmenitiesFilters = $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'amenity')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$ChosenAmenitiesFilters = [];
$ContraAmenitiesFilters = [];
foreach ($AmenitiesFilters as $thisFilter) {
if (in_array($thisFilter->getId(), $AllRoomTags)) {
$ChosenAmenitiesFilters[] = $thisFilter;
} else {
if (null !== $thisFilter->getContraTagName()) {
$ContraAmenitiesFilters[] = $thisFilter;
}
}
}
// ---
$ExperienceFilters = $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'experience')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$ChosenExperienceFilters = [];
foreach ($ExperienceFilters as $thisFilter) {
if (in_array($thisFilter->getId(), $AllRoomTags)) {
$ChosenExperienceFilters[] = $thisFilter;
}
}
// ---
$EatingDrinkingFilters = $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'eating_drinking')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$ChosenEatingDrinkingFilters = [];
$ContraEatingDrinkingFilters = [];
foreach ($EatingDrinkingFilters as $thisFilter) {
if (in_array($thisFilter->getId(), $AllRoomTags)) {
$ChosenEatingDrinkingFilters[] = $thisFilter;
} else {
if (null !== $thisFilter->getContraTagName()) {
$ContraEatingDrinkingFilters[] = $thisFilter;
}
}
}
// ---
$AccommTypeFilters = $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'accomm_type')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$ChosenAccommTypeFilters = [];
$ContraAccommTypeFilters = [];
foreach ($AccommTypeFilters as $thisFilter) {
if (in_array($thisFilter->getId(), $AllRoomTags)) {
$ChosenAccommTypeFilters[] = $thisFilter;
} else {
if (null !== $thisFilter->getContraTagName()) {
$ContraAccommTypeFilters[] = $thisFilter;
}
}
}
// ---
$StayInfoFilters = $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'stay_info')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$ChosenStayInfoFilters = [];
$ContraStayInfoFilters = [];
foreach ($StayInfoFilters as $thisFilter) {
if (in_array($thisFilter->getId(), $AllRoomTags)) {
$ChosenStayInfoFilters[] = $thisFilter;
} else {
if (null !== $thisFilter->getContraTagName()) {
$ContraStayInfoFilters[] = $thisFilter;
}
}
}
// ---
$UniqueThingsFilters = $em->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'unique_things')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$ChosenUniqueThingsFilters = [];
$ContraUniqueThingsFilters = [];
foreach ($UniqueThingsFilters as $thisFilter) {
if (in_array($thisFilter->getId(), $AllRoomTags)) {
$ChosenUniqueThingsFilters[] = $thisFilter;
} else {
if (null !== $thisFilter->getContraTagName()) {
$ContraUniqueThingsFilters[] = $thisFilter;
}
}
}
$GetRegion = $this->getDoctrine()->getRepository(Regions::class)->findOneBy([
'Name' => $ListingInfo->getPhysAddr3(),
]);
$NearbyListings = $em->getRepository("App\Entity\AccommodationType")->createQueryBuilder('t')
->where('t.Region = :Region')
->andWhere('t.Enabled = 1')
->andWhere('t.Property != :ThisListingCode')
->setParameter('Region', $GetRegion)
->setParameter('ThisListingCode', $ListingInfo)
->setMaxResults(4)
->getQuery()
->getResult();
shuffle($NearbyListings);
$ReviewData = [];
$Reviews = $this->getDoctrine()->getRepository(PropertyReviews::class)->findBy([
'PropertyCode' => $ListingCode,
'Approved' => true,
], ['id' => 'DESC']);
foreach ($Reviews as $ThisReview) {
if ($ThisReview->getBookingId() > 0) {
$BookingInfo = $this->getDoctrine()->getRepository(Bookings::class)->find($ThisReview->getBookingId());
$HolidaymakerInfoReview = $this->getDoctrine()->getRepository(User::class)->find($BookingInfo->getHolidaymakerId());
$ReviewData[$ThisReview->getId()] = [
'holidaymakerinfo' => $HolidaymakerInfoReview,
'bookinginfo' => $BookingInfo,
];
} else {
$ReviewData[$ThisReview->getId()] = [
'holidaymakerinfo' => [],
'bookinginfo' => [],
];
}
}
$RoomBanners = $em->getRepository("App\Entity\RoomBanners")->createQueryBuilder('t')
->where('t.Enabled = true')
->andWhere(':time_now BETWEEN t.ApplyFrom AND t.ApplyTo')
->setParameter('time_now', new \DateTime('now'))
->getQuery()
->getResult();
$RoomBannerOutput = '';
foreach ($RoomBanners as $ThisRoomBanner) {
$RoomSpecificBanner = $this->getDoctrine()->getRepository(RoomBannersSpecific::class)->findOneBy([
'RoomBanner' => $ThisRoomBanner,
'Enabled' => true,
'Room' => $AccommInfo,
]);
if ($RoomSpecificBanner) {
$RoomBannerOutput .= "<div class='alert' style='".$ThisRoomBanner->getBoxStyling()."'>";
$RoomBannerOutput .= "<div class='row'>";
$RoomBannerOutput .= "<div class='col-sm-2' style='text-align:center;'>";
$RoomBannerOutput .= "<i class='fa ".$ThisRoomBanner->getBannerFAIcon()."' style='font-size:90px;'></i>";
$RoomBannerOutput .= '</div>';
$RoomBannerOutput .= "<div class='col-sm-10'>";
$RoomBannerOutput .= $RoomSpecificBanner->getMessage();
$RoomBannerOutput .= '</div>';
$RoomBannerOutput .= '</div>';
$RoomBannerOutput .= '</div>';
} elseif (true == $ThisRoomBanner->getForceDefaultMessage()) {
$RoomBannerOutput .= "<div class='alert' style='".$ThisRoomBanner->getBoxStyling()."'>";
$RoomBannerOutput .= "<div class='row'>";
$RoomBannerOutput .= "<div class='col-sm-2' style='text-align:center;'>";
$RoomBannerOutput .= "<i class='fa ".$ThisRoomBanner->getBannerFAIcon()."' style='font-size:90px;'></i>";
$RoomBannerOutput .= '</div>';
$RoomBannerOutput .= "<div class='col-sm-10'>";
$RoomBannerOutput .= $ThisRoomBanner->getDefaultMessage();
$RoomBannerOutput .= '</div>';
$RoomBannerOutput .= '</div>';
$RoomBannerOutput .= '</div>';
} else {
}
}
if (count($RoomBanners) > 0) {
// $RoomBannerOutput .="<hr>";
}
// Listing QnAs
$ListingQuestions = $em->getRepository("App\Entity\ListingQuestions")->createQueryBuilder('t')
->where('t.Room = :room')
->andWhere('t.ModeratedBy > 0')
->andWhere('t.ShowOnListing=1')
->setParameter('room', $AccommInfo)
->getQuery()
->getResult();
// Bookable Experiences
$GetAllBookables = $this->getDoctrine()->getRepository(BookableExperiences::class)->findBy(['Status' => 'Listed']);
$BookableExperiences = [];
$SearchDistance = $GlobalFn->datedVar('bookableExperiencesSearchDistanceKm', date('Y-m-d'));
foreach ($GetAllBookables as $thisBookable) {
$DistanceAway = $GlobalFn->distanceCalculation($ListingInfo->getCoordLat(), $ListingInfo->getCoordLong(), $thisBookable->getCoordLat(), $thisBookable->getCoordLong());
if ($DistanceAway < $SearchDistance) {
$BookableExperiences[] = [$thisBookable, $DistanceAway];
}
}
usort($BookableExperiences, function ($a, $b) {
return $a[1] <=> $b[1];
});
$UserExistingBooking = $this->getDoctrine()->getRepository(Bookings::class)->findOneBy([
'RelatedRoom' => $AccommInfo,
'RelatedHolidaymaker' => $this->getUser(),
'Status' => 'Draft',
]);
return $this->render('listing/index.html.twig', [
'controller_name' => 'ListingController',
'listing_slug' => $listing_slug,
'room_code' => $AccommInfo->getRoomCode(),
'room_slug' => $room_slug,
'listing_info' => $ListingInfo,
'room_info' => $AccommInfo,
'today_date' => date('Y-m-d'),
'other_rooms' => $OtherListingRooms,
'images_arr' => $Images,
'tomorrow_date' => date('Y-m-d', strtotime('tomorrow')),
'default_image' => '../../'.$MainImg,
'other_room_count' => count($OtherListingRooms),
'addons' => $Addons,
'addons_img' => $AddonImg,
'landowner_info' => $LandownerInfo,
'map_lat' => $ListingInfo->getCoordLat(),
'map_long' => $ListingInfo->getCoordLong(),
'reviews' => $Reviews,
'landowner_img' => $UserImg,
'room_photos' => $RoomImg,
'room_tonight_price' => $RoomTonightPrice,
'room_banner_output' => $RoomBannerOutput,
'nearby_listings' => $NearbyListings,
'review_data' => $ReviewData,
'listing_questions' => $ListingQuestions,
'bookable_experiences' => $BookableExperiences,
'checkin' => $CheckIn,
'checkout' => $CheckOut,
'user_existing_booking' => $UserExistingBooking,
'filters_activities' => $ChosenActivitiesFilters,
'filters_activities_contra' => $ContraActivitiesFilters,
'filters_amenities' => $ChosenAmenitiesFilters,
'filters_amenities_contra' => $ContraAmenitiesFilters,
'filters_uniquethings' => $ChosenUniqueThingsFilters,
'filters_uniquethings_contra' => $ContraUniqueThingsFilters,
'filters_eatingdrinking' => $ChosenEatingDrinkingFilters,
'filters_eatingdrinking_contra' => $ContraEatingDrinkingFilters,
'filters_accommtype' => $ChosenAccommTypeFilters,
'filters_accommtype_contra' => $ContraAccommTypeFilters,
'filters_stayinfo' => $ChosenStayInfoFilters,
'filters_stayinfo_contra' => $ContraStayInfoFilters,
'filters_experience' => $ChosenExperienceFilters,
]);
} else {
return new Response('Sorry, this listing can not be shown right now');
}
}
public function loginForFav($listing_slug, $room_slug)
{
return $this->redirectToRoute('listing', ['listing_slug' => $listing_slug, 'room_slug' => $room_slug]);
}
public function toggleFavourite($room_id, $ajax = true)
{
$user_id = $this->getUser()->getId();
$Room = $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
$Favourite = $this->getDoctrine()->getRepository(Favourites::class)->findOneBy([
'UserId' => $user_id,
'RoomId' => $room_id,
]);
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Room->getPropertyCode()]);
$entityManager = $this->getDoctrine()->getManager();
if ($Favourite) {
$entityManager->remove($Favourite);
$entityManager->flush();
if (true == $ajax) {
return new Response('ADD FAV');
} else {
return $this->redirectToRoute('listing', ['listing_slug' => $Property->getListingSlug(), 'room_slug' => $Room->getRoomSlug()]);
}
} else {
$Favourite = new Favourites();
$Favourite->setRoomId($room_id);
$Favourite->setUserId($user_id);
$entityManager->persist($Favourite);
$entityManager->flush();
if (true == $ajax) {
return new Response('REMOVE FAV');
} else {
return $this->redirectToRoute('listing', ['listing_slug' => $Property->getListingSlug(), 'room_slug' => $Room->getRoomSlug()]);
}
}
}
public function loadFavourite($user_id, $room_id)
{
$Room = $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
$Favourite = $this->getDoctrine()->getRepository(Favourites::class)->findOneBy([
'UserId' => $user_id,
'RoomId' => $room_id,
]);
if ($Favourite) {
return new Response('REMOVE FAV');
} else {
return new Response('ADD FAV');
}
}
public function updateCaption($photo_id, Request $request)
{
$GetPhoto = $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
$GetPhoto->setDescription($request->request->get('caption'));
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($GetPhoto);
$entityManager->flush();
return new Response('success');
}
public function photoManager($room_code, Request $request, MessageBusInterface $messageBus)
{
if (isset($_GET['mode'])) {
$Mode = $_GET['mode'];
} else {
$Mode = 'normal';
}
$AccommType = $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
'RoomCode' => $room_code,
]);
$user = $this->get('security.token_storage')->getToken()->getUser();
if ($this->isGranted('ROLE_ADMIN')) {
$user = $this->getDoctrine()->getRepository(User::class)->find($AccommType->getLandownerId());
}
$MatchListing = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $AccommType->getPropertyCode(),
'LandownerId' => $user,
]);
if ($MatchListing) {
$GetPhotos = $this->getDoctrine()->getRepository(Media::class)->findBy([
'RoomCode' => $room_code,
], ['DisplayOrder' => 'ASC']);
$NewPhoto = new Media();
$entityManager = $this->getDoctrine()->getManager();
$form = $this->createFormBuilder($NewPhoto)
->add('documentFile', VichImageType::class)
->add('Description', TextType::class, ['label' => 'Caption', 'required' => false])
->add('save', SubmitType::class, ['label' => 'Upload'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$NewPhoto = $form->getData();
$NewPhoto->setRoomCode($room_code);
$NewPhoto->setAccommType($AccommType);
$entityManager->persist($NewPhoto);
$entityManager->flush();
$RandomFileName = time().'_'.$NewPhoto->getDocumentFileName();
rename('../public/media/'.$NewPhoto->getDocumentFileName(), '../public/media/'.$RandomFileName);
$messageBus->dispatch(new WarmupCache('/media/'.$RandomFileName));
$NewPhoto->setDocumentFileName($RandomFileName);
$entityManager->persist($NewPhoto);
$entityManager->flush();
// var_dump($NewPhoto);
// exit();
return $this->redirectToRoute('edit_listing_photos', ['room_code' => $room_code, 'mode' => $Mode]);
}
$random_number = rand(100000, 999999);
return $this->render('listing/photomanager.html.twig', [
'listing_info' => $MatchListing,
'photos' => $GetPhotos,
'listing_code' => $MatchListing->getListingCode(),
'room_code' => $room_code,
'uploadForm' => $form->createView(),
'mode' => $Mode,
'random_number' => $random_number,
]);
} else {
return new Response('No access');
}
}
public function resetPhotos($room_code, Request $request)
{
$ListingPhotos = $this->getDoctrine()->getRepository(Media::class)->findBy([
'RoomCode' => $room_code,
], ['id' => 'ASC']);
$i = 1;
foreach ($ListingPhotos as $thisPhoto) {
$thisPhoto->setDisplayOrder($i);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($thisPhoto);
++$i;
}
$entityManager->flush();
return $this->redirectToRoute('edit_listing_photos', ['room_code' => $room_code]);
}
public function newListing(GuardAuthenticatorHandler $guardHandler, Request $request, LoginFormAuthenticator $authenticator, GlobalFunctions $GlobalFn)
{
$entityManager = $this->getDoctrine()->getManager();
/*$NewListingCode = substr(str_shuffle("ABCDEFGHIJKLMNPQRSTUVWXYZ1234567890"),0,9);
$GetUserProperties = $this->getDoctrine()->getRepository(Property::class)->findBy([
'LandownerId' => $this->getUser()->getId()
]);
foreach($GetUserProperties as $thisProperty) {
if($thisProperty->getListingStatus()=="New") {
return $this->redirectToRoute('new_listing_form_edit',array('listing_code'=>$thisProperty->getListingCode()));
exit;
}
}
$Property = new Property();
$user_id = $this->getUser()->getId();
$Property->setLandownerId($user_id);
$Property->setPropertyTitle("");
$Property->setListingSlug("listing-".$NewListingCode);
$Property->setListingCode($NewListingCode);
$Property->setListingStatus("New");
$Property->setCreatedDate(new \DateTime('today'));*/
$user = $this->getUser();
$user->addRole('ROLE_LANDOWNER');
$entityManager->flush();
$GlobalFn->addUserToList($user->getId(), 3);
$doLogin = $guardHandler->authenticateUserAndHandleSuccess(
$user,
$request,
$authenticator,
'main' // firewall name in security.yaml
);
return $this->redirectToRoute('onboarding_new');
}
public function updateListingField(Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$listing_id = $request->request->get('listing_id');
$field = $request->request->get('field');
$user_id = $this->getUser()->getId();
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'id' => $listing_id,
'LandownerId' => $user_id,
]);
$NewValue = $request->request->get('NewValue');
if ('setPhysAddr3' == $field) {
if ('Manawatu-Wanganui' == $NewValue) {
$NewValue = 'Manawatu-Whanganui';
}
}
$Property->$field($NewValue);
$entityManager->persist($Property);
$entityManager->flush();
return new Response('success');
}
public function updateAccommField(Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$accomm_id = $request->request->get('accomm_id');
$field = $request->request->get('field');
$user_id = $this->getUser()->getId();
$Accomm = $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
'id' => $accomm_id,
'LandownerId' => $user_id,
]);
$NewValue = $request->request->get('NewValue');
if ('setEnabled' === $field && '1' === $NewValue) {
return new Response('You do not have permission to change this. Please contact OTBT support for help.', 403);
}
$Accomm->$field($NewValue);
$entityManager->persist($Accomm);
$entityManager->flush();
return new Response('success');
}
public function editNewListing($listing_code, $mode, Request $request)
{
$user_id = $this->getUser()->getId();
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $listing_code,
'LandownerId' => $user_id,
]);
return $this->render('listing/newlisting.html.twig', [
'mode' => $mode,
'listing' => $Property,
]);
}
public function newListingPart2($property_code, $mode, Request $request)
{
$user_id = $this->getUser()->getId();
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $property_code,
'LandownerId' => $user_id,
]);
return $this->render('listing/listingpart2.html.twig', [
'listing' => $Property,
]);
}
public function newAccommType($listing_code, Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $listing_code,
]);
$ExistingAccomms = $this->getDoctrine()->getRepository(AccommodationType::class)->findBy([
'PropertyCode' => $Property->getListingCode(),
]);
foreach ($ExistingAccomms as $thisAccomm) {
if ('New Accommodation Type' == $thisAccomm->getRoomName()) {
return $this->redirectToRoute('newroom_edit', ['room_code' => $thisAccomm->getRoomCode()]);
}
}
$AccommType = new AccommodationType();
$AccommType->setEnabled(0);
$NewRoomCode = substr(str_shuffle('ABCDEFGHIJKLMNPQRSTUVWXYZ1234567890'), 0, 9);
$AccommType->setPropertyCode($listing_code);
$AccommType->setProperty($Property);
$AccommType->setRoomCode($NewRoomCode);
$AccommType->setRoomName('New Accommodation Type');
$AccommType->setRoomSlug('room-'.$NewRoomCode);
$AccommType->setSearchHeadline('Display Name of Listing');
$AccommType->setRoomSlugNew('room-'.$NewRoomCode);
$AccommType->setMinimumNights(1);
$AccommType->setNightlyQnt(1);
$AccommType->setPriceMode('pn');
$user_id = $this->getUser()->getId();
$AccommType->setLandownerId($user_id);
$entityManager->persist($AccommType);
$entityManager->flush();
return $this->redirectToRoute('newroom_edit', ['room_code' => $NewRoomCode]);
}
public function editNewAccommType($room_code, $mode, Request $request)
{
$user_id = $this->getUser()->getId();
$AccommType = $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
'RoomCode' => $room_code,
'LandownerId' => $user_id,
]);
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $AccommType->getPropertyCode(),
]);
$listing_code = $Property->getListingCode();
$entityManager = $this->getDoctrine()->getManager();
$RoomAmenities = $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'amenity')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$EatingDrinking = $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'eating_drinking')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$AccommTypeTags = $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'accomm_type')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$EssentialStayInfo = $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'stay_info')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$UniqueThings = $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'unique_things')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$Activities = $entityManager->getRepository("App\Entity\PropertyTags")->createQueryBuilder('t')
->where('t.TagType = :tag_type')
->setParameter('tag_type', 'activities')
->orderBy('t.TagName', 'ASC')
->getQuery()
->getResult();
$RegionList = $this->getDoctrine()->getRepository(Regions::class)->findAll();
$GetSelectedTags = $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy([
'Room' => $AccommType,
]);
$SelectedTags = [];
foreach ($GetSelectedTags as $ThisTag) {
$SelectedTags[$ThisTag->getTag()->getId()] = $ThisTag->getTag()->getId();
}
$SyncList = $this->getDoctrine()->getRepository(TrackedCalendars::class)->findBy([
'RoomCode' => $AccommType->getRoomCode(),
]);
return $this->render('listing/newaccomm.html.twig', [
'listing' => $Property,
'room' => $AccommType,
'room_amenities' => $RoomAmenities,
'selected_tags' => $SelectedTags,
'eating_drinking' => $EatingDrinking,
'accomm_type' => $AccommTypeTags,
'essential_stay' => $EssentialStayInfo,
'unique_things' => $UniqueThings,
'activities' => $Activities,
'regions' => $RegionList,
'synclist' => $SyncList,
]);
}
public function setRegion($room_id, $region_id)
{
$Room = $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
$Region = $this->getDoctrine()->getRepository(Regions::class)->find($region_id);
$Room->setRegion($Region);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Room);
$entityManager->flush();
return new Response('success');
}
public function newAddon($listing_code, Request $request)
{
$Addon = new Addons();
$Addon->setPropertyCode($listing_code);
$Addon->setPriceMode('A');
$Addon->setEnabled(true);
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $listing_code,
]);
$form = $this->createFormBuilder($Addon)
->add('Title', TextType::class)
->add('Description', TextareaType::class)
->add('PriceMode', ChoiceType::class, [
'choices' => [
'One Off / Per Person' => 'A',
'Daily / Per Person' => 'B',
'Daily / Per Trip (flat rate)' => 'C',
'One Off / Per Trip (flat rate)' => 'D',
],
])
->add('PricePer', MoneyType::class)
->add('PerName', TextType::class)
->add('MaxPeople', NumberType::class)
->add('save', SubmitType::class, ['label' => 'Save'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$Addon = $form->getData();
// ... perform some action, such as saving the Property to the database
// for example, if Property is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Addon);
$entityManager->flush();
$email = new \SendGrid\Mail\Mail();
$email->setFrom('support@otbt.co.nz', 'OTBT System');
$email->addTo('info@otbt.co.nz');
$email->setSubject('New Addon Created - Property: '.$Property->getPropertyTitle());
$email->addContent(
'text/html',
'Hi Admin, <br><br>A new addon has been added to '.$Property->getPropertyTitle().'. The new data is as follows:<br><br><pre>'.print_r($Addon, true).'</pre><br> <br><br>Thanks, <br>OTBT System'
);
$sendgrid = new \App\Classes\SendGrid();
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
return $this->redirectToRoute('new_listing_overview', ['property_id' => $Property->getId()]);
}
return $this->render('listing/addon.html.twig', [
'newaddon' => $form->createView(),
]);
}
public function editAddon($addon_id, Request $request)
{
$Addon = $this->getDoctrine()->getRepository(Addons::class)->find($addon_id);
$AddonCurrently = print_r($Addon, true);
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $Addon->getPropertyCode(),
]);
$form = $this->createFormBuilder($Addon)
->add('Title', TextType::class)
->add('Description', TextareaType::class)
->add('PriceMode', ChoiceType::class, [
'choices' => [
'One Off / Per Person' => 'A',
'Daily / Per Person' => 'B',
'Daily / Per Trip (flat rate)' => 'C',
'One Off / Per Trip (flat rate)' => 'D',
],
])
->add('PricePer', TextType::class)
->add('PerName', TextType::class)
->add('MaxPeople', TextType::class)
->add('save', SubmitType::class, ['label' => 'Save'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$Addon = $form->getData();
// ... perform some action, such as saving the Property to the database
// for example, if Property is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Addon);
$entityManager->flush();
$email = new \SendGrid\Mail\Mail();
$email->setFrom('support@otbt.co.nz', 'OTBT System');
$email->addTo('info@otbt.co.nz');
$email->setSubject('Addon has been Edited: '.$Addon->getTitle());
$email->addContent(
'text/html',
'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($Addon, true).'</pre></td></tr></table><pre>'.print_r($Addon, true).'</pre><br> <br><br>Thanks, <br>OTBT System'
);
$sendgrid = new \App\Classes\SendGrid();
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
if ('Draft' == $Property->getListingStatus()) {
return $this->redirectToRoute('new_listing_overview', ['property_id' => $Property->getId()]);
} else {
return $this->redirectToRoute('edit_listing', ['listing_code' => $Property->getListingCode()]);
}
}
return $this->render('listing/addon.html.twig', [
'newaddon' => $form->createView(),
]);
}
public function listingQuestion(Request $request)
{
$person_name = $request->request->get('person_name');
$person_email = $request->request->get('person_email');
$question = $request->request->get('question');
$room_name = $request->request->get('room_name');
$email = new \SendGrid\Mail\Mail();
$email->setFrom('support@otbt.co.nz', 'OTBT System');
$email->addTo('info@otbt.co.nz');
$email->addTo('support@otbt.co.nz');
$email->setTemplateId('d-fb55f6c29f294cae97c063f9f97dd95e'); // UPDATED SG TEMPLATE 20224
$email->addDynamicTemplateDatas([
'person_name' => $person_name,
'person_email' => $person_email,
'question' => $question,
'room_name' => $room_name,
]);
$sendgrid = new \App\Classes\SendGrid();
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
return new Response('success');
}
public function landownerQAreply(ListingQuestions $qa, Request $request, UrlGeneratorInterface $router)
{
$entityManager = $this->getDoctrine()->getManager();
$Room = $qa->getRoom();
$Landowner = $this->getDoctrine()->getRepository(User::class)->find($Room->getLandownerId());
if ($Landowner->getId() !== $this->getUser()->getId()) {
return new Response('unauthorized');
} else {
$form = $this->createFormBuilder($qa)
->add('Answer', TextareaType::class)
->add('save', SubmitType::class, ['label' => 'Submit Answer'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$qa = $form->getData();
$qa->setAnsweredDate(new \DateTime());
$qa->setAnsweredBy($this->getUser());
$ModerateURL = 'https://'.$_SERVER['SERVER_NAME'].$router->generate('admin_listingquestions_moderate', ['id' => $qa->getId()]);
$entityManager->persist($qa);
$entityManager->flush();
$email = new \SendGrid\Mail\Mail();
$email->setFrom('support@otbt.co.nz', 'OTBT System');
$email->addTo('info@otbt.co.nz');
// $email->addTo("partner.otbt@luminate.one");
$email->setSubject('New QA to be moderated');
$email->addContent(
'text/html',
"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."
);
$sendgrid = new \App\Classes\SendGrid();
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
return $this->render('listing/landownerQAreplyDONE.html.twig', [
'qa' => $qa,
]);
} else {
return $this->render('listing/landownerQAreply.html.twig', [
'form' => $form->createView(),
'qa' => $qa,
]);
}
}
}
public function reviewNewListing($listing_code)
{
$user_id = $this->getUser()->getId();
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $listing_code,
'LandownerId' => $user_id,
]);
$AccommType = $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy([
'PropertyCode' => $listing_code,
'LandownerId' => $user_id,
]);
$AllTags = $this->getDoctrine()->getRepository(PropertyTags::class)->findAll();
$GetAllTags = [];
foreach ($AllTags as $ThisTag) {
$GetAllTags[$ThisTag->getId()] = $ThisTag;
}
$GetSelectedTags = $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy([
'Room' => $AccommType,
]);
$SelectedTags = [];
foreach ($GetSelectedTags as $ThisTag) {
$SelectedTags[] = $GetAllTags[$ThisTag->getTag()->getId()];
}
return $this->render('listing/reviewlisting.html.twig', [
'property' => $Property,
'accomm' => $AccommType,
'listing_code' => $listing_code,
'room_code' => $AccommType->getRoomCode(),
'selected_tags' => $SelectedTags,
'mode' => 'review',
]);
}
public function editListingNew($listing_code)
{
$user_id = $this->getUser()->getId();
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $listing_code,
'LandownerId' => $user_id,
]);
if ('New' == $Property->getListingStatus()) {
return $this->redirectToRoute('new_listing_overview', ['property_id' => $Property->getId()]);
}
$AccommTypes = $this->getDoctrine()->getRepository(AccommodationType::class)->findBy([
'PropertyCode' => $listing_code,
'LandownerId' => $user_id,
]);
$Addons = $this->getDoctrine()->getRepository(Addons::class)->findBy([
'PropertyCode' => $listing_code,
'Enabled' => true,
]);
return $this->render('listing/reviewlisting.html.twig', [
'property' => $Property,
'listing_code' => $listing_code,
'mode' => 'edit',
'accomm_types' => $AccommTypes,
'addons' => $Addons,
]);
}
public function submitNewListing($listing_code)
{
$user_id = $this->getUser()->getId();
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy([
'ListingCode' => $listing_code,
'LandownerId' => $user_id,
]);
$UserInfo = $this->getDoctrine()->getRepository(User::class)->find($user_id);
$Property->setListingStatus('Awaiting Review');
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($Property);
$entityManager->flush();
$email = new \SendGrid\Mail\Mail();
$email->setFrom('support@otbt.co.nz', 'OTBT System');
$email->addTo($UserInfo->getEmail());
$email->setTemplateId('d-a89cf56c0e214ca0bd825836128c26cd'); // UPDATE SG TEMPLATE 2024
$sendgrid = new \App\Classes\SendGrid();
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
$email = new \SendGrid\Mail\Mail();
$email->setFrom('support@otbt.co.nz', 'OTBT System');
$email->addTo('info@otbt.co.nz');
$email->setSubject('New Property Submitted for Review');
$email->addContent(
'text/html',
'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'
);
$sendgrid = new \App\Classes\SendGrid();
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
$GetAccommTypes = $this->getDoctrine()->getRepository(AccommodationType::class)->findBy(['PropertyCode' => $Property->getListingCode()]);
foreach ($GetAccommTypes as $thisAccomm) {
if ('New Accommodation Type' == $thisAccomm->getRoomName() && 0 == $thisAccomm->getEnabled() && null == $thisAccomm->getRoomDescription() && null == $thisAccomm->getNormalPrice() && null == $thisAccomm->getBeddingConfiguration() && null == $thisAccomm->getEatingDrinking()) {
$entityManager->remove($thisAccomm);
}
}
$entityManager->flush();
return $this->render('listing/submitreview.html.twig', [
'listing_code' => $listing_code,
]);
}
public function deletePhoto($photo_id)
{
$Media = $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($Media);
$entityManager->flush();
return new Response('success');
}
public function applyTag($room_id, $tag_id)
{
$GetTag = $this->getDoctrine()->getRepository(PropertyTags::class)->find($tag_id);
$Room = $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
$entityManager = $this->getDoctrine()->getManager();
$TagApplied = new PropertyTagsApplied();
$TagApplied->setRoom($Room);
$TagApplied->setTag($GetTag);
$entityManager->persist($TagApplied);
$entityManager->flush();
return new Response('success');
}
public function removeTag($room_id, $tag_id)
{
$Room = $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
$Tag = $this->getDoctrine()->getRepository(PropertyTags::class)->find($tag_id);
$entityManager = $this->getDoctrine()->getManager();
$TagApplied = $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findOneBy(['Room' => $Room, 'Tag' => $Tag]);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($TagApplied);
$entityManager->flush();
return new Response('success');
}
public function updateProfilePicture(Request $request, GlobalFunctions $GlobalFn, MessageBusInterface $messageBus)
{
@$Mode = $_GET['mode'];
if (!isset($Mode)) {
$Mode = 'edit';
}
@$PropertyId = $_GET['property_id'];
if (!isset($PropertyId)) {
$PropertyId = null;
}
$user_id = $this->getUser()->getId();
$Media = $this->getDoctrine()->getRepository(Media::class)->findOneBy(['UserId' => $user_id]);
$ProfilePicture = $GlobalFn->user_photo($user_id);
if (!$Media) {
$Media = new Media();
$Media->setUserId($user_id);
}
$entityManager = $this->getDoctrine()->getManager();
$form = $this->createFormBuilder($Media)
->add('documentFile', VichImageType::class, ['allow_delete' => true, 'download_link' => false])
->add('save', SubmitType::class, ['label' => 'Upload'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$Media = $form->getData();
$entityManager->persist($Media);
$entityManager->flush();
$ProfilePicture = $GlobalFn->user_photo($user_id);
$messageBus->dispatch(new WarmupCache($ProfilePicture));
return $this->redirectToRoute('profile_picture');
}
return $this->render('listing/updateprofilepic.html.twig', [
'form' => $form->createView(),
'user' => $this->getUser(),
'profile_picture' => $ProfilePicture,
'updatemessage' => 0,
'mode' => $Mode,
'property_id' => $PropertyId,
]);
}
public function landownerPriceAdjustment($accomm_id, Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$Accomm = $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Accomm->getPropertyCode()]);
if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
return new Exception('You do not have permission to access this');
} else {
$AccommPricing = $this->getDoctrine()->getRepository(PricingNights::class)->findBy(['RoomCode' => $Accomm->getRoomCode()]);
$StayPricing = $this->getDoctrine()->getRepository(PricingStay::class)->findBy(['RoomCode' => $Accomm->getRoomCode()]);
$accommForm = $this->createFormBuilder($Accomm)
->add('NightlyQnt', ChoiceType::class, [
'required' => true,
'choices' => [
1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
],
])
->add('NormalPrice', MoneyType::class, ['required' => true, 'currency' => 'NZD'])
->add('MaxGuests', ChoiceType::class, [
'required' => true,
'choices' => [
1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
],
])
->add('MaxAdditionalGuests', ChoiceType::class, [
'required' => true,
'choices' => [
'No additional guests' => 0, 1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
],
])
->add('AdditionalGuestPrice', MoneyType::class, ['required' => false, 'currency' => 'NZD'])
->add('PriceMode', ChoiceType::class, [
'required' => true,
'choices' => [
'Per Night' => 'pn',
'Per Person Per Night' => 'pppn',
],
'expanded' => false,
'multiple' => false,
])
->add('MinimumNights', ChoiceType::class, [
'required' => true,
'choices' => [
'Minimum 1 night' => 1, 2 => 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
],
])
->add('save', SubmitType::class, ['label' => 'Update'])
->getForm();
$accommForm->handleRequest($request);
if ($accommForm->isSubmitted() && $accommForm->isValid()) {
// $accommForm->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$Accomm = $accommForm->getData();
$Accomm->setRoomCode($Accomm->getRoomCode());
$entityManager->persist($Accomm);
$entityManager->flush();
return $this->redirectToRoute('landowner_price_adjustments', ['accomm_id' => $accomm_id]);
}
$MinimumNightAdjustments = $this->getDoctrine()->getRepository(MinimumNightOverride::class)->findBy(['Room' => $Accomm]);
return $this->render('listing/landownerpriceadjustments.html.twig', [
'accomm_form' => $accommForm->createView(),
'pricing' => $AccommPricing,
'accomm' => $Accomm,
'property' => $Property,
'staypricing' => $StayPricing,
'minimum_night_adjustments' => $MinimumNightAdjustments,
]);
}
}
public function newMinimumNightAdjustment(AccommodationType $room, Request $request)
{
$newadj_fromdate = $request->request->get('date_from');
$newadj_todate = $request->request->get('date_to');
$newadj_selectedweek = $request->request->get('selecteddow');
$newadj_minnights = (int) $request->request->get('setminimumnight');
if ('' == $newadj_fromdate) {
$newadj_fromdate = null;
} else {
$newadj_fromdate = new \DateTime($newadj_fromdate);
$newadj_todate = new \DateTime($newadj_todate);
}
if ('-' == $newadj_selectedweek) {
$newadj_selectedweek = null;
}
$MinNightOverride = new MinimumNightOverride();
$MinNightOverride->setRoom($room);
if (!empty($newadj_fromdate)) {
$MinNightOverride->setAppliesFromDate($newadj_fromdate);
$MinNightOverride->setAppliesToDate($newadj_todate);
}
$MinNightOverride->setDayOfWeek($newadj_selectedweek);
$MinNightOverride->setSetMinimumNights($newadj_minnights);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($MinNightOverride);
$entityManager->flush();
return new Response('success');
}
public function deleteMinNightAdjustment(Request $request)
{
$adj = $this->getDoctrine()->getRepository(MinimumNightOverride::class)->find($request->request->get('adj_id'));
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($adj);
$entityManager->flush();
return new Response('success');
}
public function landownerPriceAdjustmentAdd($accomm_id, Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$Accomm = $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Accomm->getPropertyCode()]);
if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
return new Exception('You do not have permission to access this');
} else {
$AccommPricing = $this->getDoctrine()->getRepository(PricingNights::class)->findBy(['RoomCode' => $Accomm->getRoomCode()]);
$NewPricing = new PricingNights();
$NewPricing->setDaysOfWeek('[Mon][Tue][Wed][Thu][Fri][Sat][Sun]');
$form = $this->createFormBuilder($NewPricing)
->add('DateFrom', DateType::class, ['required' => true])
->add('DateTo', DateType::class, ['required' => true])
->add('DaysOfWeek', HiddenType::class, ['required' => true])
->add('Adjustment', TextType::class, ['required' => true])
->add('Description', TextType::class, ['required' => true])
->add('save', SubmitType::class, ['label' => 'Add New'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$NewPricing = $form->getData();
$NewPricing->setRoomCode($Accomm->getRoomCode());
$entityManager->persist($NewPricing);
$entityManager->flush();
return $this->redirectToRoute('landowner_price_adjustments', ['accomm_id' => $accomm_id]);
}
return $this->render('listing/landownerpriceadjustmentsadd.html.twig', [
'form' => $form->createView(),
'pricing' => $AccommPricing,
'accomm' => $Accomm,
'property' => $Property,
]);
}
}
public function stayPricingAdd($accomm_id, Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$Accomm = $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
$Property = $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Accomm->getPropertyCode()]);
if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
return new Exception('You do not have permission to access this');
} else {
$NewPricing = new PricingStay();
$form = $this->createFormBuilder($NewPricing)
->add('DateFrom', DateType::class, ['required' => true])
->add('DateTo', DateType::class, ['required' => true])
->add('MinNights', TextType::class, ['required' => true])
->add('Adjustment', TextType::class, ['required' => false])
->add('PercentageAdjustment', TextType::class, ['required' => false])
->add('LineDescription', TextType::class, ['required' => true])
->add('save', SubmitType::class, ['label' => 'Add New'])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$NewPricing = $form->getData();
$NewPricing->setRoomCode($Accomm->getRoomCode());
$entityManager->persist($NewPricing);
$entityManager->flush();
return $this->redirectToRoute('landowner_price_adjustments', ['accomm_id' => $accomm_id]);
}
return $this->render('listing/staypricingadd.html.twig', [
'form' => $form->createView(),
'accomm' => $Accomm,
'property' => $Property,
]);
}
}
public function landownerPriceAdjustmentDelete($accomm_id, $adj_id)
{
$entityManager = $this->getDoctrine()->getManager();
$Accomm = $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
return new Exception('You do not have permission to access this');
} else {
$AccommPricing = $this->getDoctrine()->getRepository(PricingNights::class)->find($adj_id);
$entityManager->remove($AccommPricing);
$entityManager->flush();
return new Response('success');
}
}
public function priceStayDelete($accomm_id, $price_id)
{
$entityManager = $this->getDoctrine()->getManager();
$Accomm = $this->getDoctrine()->getRepository(AccommodationType::class)->find($accomm_id);
if ($Accomm->getLandownerId() !== $this->getUser()->getId()) {
return new Exception('You do not have permission to access this');
} else {
$AccommPricing = $this->getDoctrine()->getRepository(PricingStay::class)->find($price_id);
$entityManager->remove($AccommPricing);
$entityManager->flush();
return new Response('success');
}
}
public function newlistingoverview($property_id, GlobalFunctions $GlobalFn)
{
$entityManager = $this->getDoctrine()->getManager();
$Property = $this->getDoctrine()->getRepository(Property::class)->find($property_id);
$Landowner = $this->getDoctrine()->getRepository(User::class)->find($Property->getLandownerId());
$ProfilePicture = $GlobalFn->user_photo($this->getUser()->getId());
if ($Property) {
if ($Property->getLandownerId() == $this->getUser()->getId()) {
$AccommTypes = $this->getDoctrine()->getRepository(AccommodationType::class)->findBy(['PropertyCode' => $Property->getListingCode()]);
$Addons = $this->getDoctrine()->getRepository(Addons::class)->findBy(['PropertyCode' => $Property->getListingCode(), 'Enabled' => 1]);
$TrackedCalendars = [];
foreach ($AccommTypes as $thisAccomm) {
$Calendars = $this->getDoctrine()->getRepository(TrackedCalendars::class)->findBy(['RoomCode' => $thisAccomm->getRoomCode()]);
$TrackedCalendars[$thisAccomm->getRoomCode()] = count($Calendars);
}
$TagsApplied = [];
foreach ($AccommTypes as $thisAccomm) {
$PropertyTags = $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy(['Room' => $thisAccomm]);
$TagsApplied[$thisAccomm->getId()] = count($PropertyTags);
}
return $this->render('listing/newlistingoverview.html.twig', [
'property' => $Property,
'landowner' => $Landowner,
'accomm_types' => $AccommTypes,
'addons' => $Addons,
'profile_picture' => $ProfilePicture,
'tracked_calendars' => $TrackedCalendars,
'tags_applied' => $TagsApplied,
]);
} else {
return new Response('Sorry, you are not authorised to see this item');
}
} else {
return new Response('Sorry, you are not authorised to see this item');
}
}
public function imgjseditor($photo_id)
{
$entityManager = $this->getDoctrine()->getManager();
$Photo = $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
$random_number = rand(100000, 999999);
return $this->render('listing/imgjseditor.html.twig', [
'photo' => $Photo,
'random_number' => $random_number,
]);
}
public function rotate_img($photo_id, $degrees, MessageBusInterface $messageBus)
{
@ini_set('memory_limit', '256M');
$entityManager = $this->getDoctrine()->getManager();
$Photo = $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
$filepath = '../public/media/'.$Photo->getDocumentFileName();
if (IMAGETYPE_JPEG == exif_imagetype($filepath)) {
/** @var resource $source */
$source = imagecreatefromjpeg($filepath);
/** @var resource $rotate */
$rotate = imagerotate($source, $degrees, 0);
imagejpeg($rotate, $filepath);
} elseif (IMAGETYPE_PNG == exif_imagetype($filepath)) {
/** @var resource $source */
$source = imagecreatefrompng($filepath);
/** @var resource $rotate */
$rotate = imagerotate($source, $degrees, 0);
imagepng($rotate, $filepath);
} else {
return new Response('error - image type not accepted');
}
imagedestroy($source);
imagedestroy($rotate);
if ('1' == substr($Photo->getDocumentFileName(), 0, 1) && '_' == substr($Photo->getDocumentFileName(), 10, 1)) {
$ActualFilename = time().'_'.substr($Photo->getDocumentFileName(), 11);
$NewFileName = $ActualFilename;
rename('../public/media/'.$Photo->getDocumentFileName(), '../public/media/'.$NewFileName);
$messageBus->dispatch(new WarmupCache('media/'.$NewFileName));
} else {
$ActualFilename = time().'_'.$Photo->getDocumentFileName();
$NewFileName = $ActualFilename;
rename('../public/media/'.$Photo->getDocumentFileName(), '../public/media/'.$NewFileName);
$messageBus->dispatch(new WarmupCache('media/'.$NewFileName));
}
$Photo->setDocumentFileName($ActualFilename);
$entityManager->persist($Photo);
$entityManager->flush();
return new Response('success');
}
public function reorder_photo($photo_id, $direction)
{
$entityManager = $this->getDoctrine()->getManager();
$Photo = $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
$AllPhotos = $this->getDoctrine()->getRepository(Media::class)->findBy(['RoomCode' => $Photo->getRoomCode()], ['DisplayOrder' => 'ASC']);
$Order = 1;
foreach ($AllPhotos as $ThisPhoto) {
if (null === $ThisPhoto->getDisplayOrder()) {
$ThisPhoto->setDisplayOrder($Order);
$entityManager->persist($ThisPhoto);
}
++$Order;
}
$entityManager->flush();
if ('up' == $direction) {
$DirectionBelow = $Photo->getDisplayOrder() - 1;
$PhotoBelow = $this->getDoctrine()->getRepository(Media::class)->findOneBy(['RoomCode' => $Photo->getRoomCode(), 'DisplayOrder' => $DirectionBelow]);
$PhotoBelow->setDisplayOrder($Photo->getDisplayOrder());
$Photo->setDisplayOrder($DirectionBelow);
$entityManager->persist($Photo);
$entityManager->persist($PhotoBelow);
$entityManager->flush();
}
if ('down' == $direction) {
$DirectionAbove = $Photo->getDisplayOrder() + 1;
$PhotoAbove = $this->getDoctrine()->getRepository(Media::class)->findOneBy(['RoomCode' => $Photo->getRoomCode(), 'DisplayOrder' => $DirectionAbove]);
$PhotoAbove->setDisplayOrder($Photo->getDisplayOrder());
$Photo->setDisplayOrder($DirectionAbove);
$entityManager->persist($Photo);
$entityManager->persist($PhotoAbove);
$entityManager->flush();
}
return new Response('success');
}
public function makeDefault($photo_id)
{
$entityManager = $this->getDoctrine()->getManager();
$Photo = $this->getDoctrine()->getRepository(Media::class)->find($photo_id);
$AllPhotos = $this->getDoctrine()->getRepository(Media::class)->findBy(['RoomCode' => $Photo->getRoomCode()], ['DisplayOrder' => 'ASC']);
foreach ($AllPhotos as $ThisPhoto) {
$ThisPhoto->setSearchDefault(null);
$ThisPhoto->setDefaultImage(null);
}
$Photo->setSearchDefault(1);
$Photo->setDefaultImage(1);
// Get room ID as frontend uses this to display the correct images on search
$room = $this->getDoctrine()->getRepository(AccommodationType::class)->findBy(['RoomCode' => $Photo->getRoomCode()])[0];
if (null !== $room && $Photo) {
$Photo->setAccommType($room);
}
$entityManager->persist($Photo);
$entityManager->flush();
return new Response('success');
}
public function updateUserBio(Request $request)
{
$new_bio = $request->request->get('new_bio');
$entityManager = $this->getDoctrine()->getManager();
$User = $this->getUser();
$User->setBio($new_bio);
$entityManager->persist($User);
$entityManager->flush();
return new Response('success');
}
public function updateUserAcc(Request $request)
{
$new_acc = $request->request->get('new_acc');
$entityManager = $this->getDoctrine()->getManager();
$User = $this->getUser();
$User->setBankAccountNumber($new_acc);
$entityManager->persist($User);
$entityManager->flush();
return new Response('success');
}
}