<?php
namespace App\Entity\Properties;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints AS Assert;
use Doctrine\ORM\Mapping AS ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Lazy\LazyUuidFromString;
use App\Entity\BaseEntity;
use App\Entity\Landlords\Landlord;
use App\Entity\Properties\Type;
use App\Entity\Properties\Area;
use App\Entity\Properties\Image;
use App\Entity\Properties\PropertyFeature;
use App\Entity\Maintenance\Maintenance;
use App\Entity\Statements\Item;
/**
* @ORM\Entity(repositoryClass="App\Repository\Properties\PropertyRepository")
* @ORM\Table(name="properties_property")
* @ORM\EntityListeners({"App\Listener\Entity\Properties\PropertyListener"})
*/
class Property extends BaseEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="uuid")
* @Assert\Uuid
*/
protected $uuid;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=false)
* @Assert\Type("\DateTime")
*/
private $created;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=false)
* @Assert\Type("\DateTime")
*/
private $modified;
/**
* @ORM\Column(type="string", length=20, nullable=false)
* @Assert\NotBlank()
*/
private $listingType;
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $reference;
/**
* @var \DateTime
*
* @ORM\Column(type="date", nullable=true)
* @Assert\Type("\DateTime")
*/
private $dateAvailable;
/**
* @ORM\Column(type="string", length=128, nullable=false)
* @Assert\NotBlank()
*/
private $nameNumber;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $address2;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $address3;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $address4;
/**
* @ORM\Column(type="string", length=128, nullable=false)
* @Assert\NotBlank()
*/
private $town;
/**
* @ORM\Column(type="string", length=10, nullable=false)
* @Assert\NotBlank()
*/
private $postcode;
/**
* @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
*/
private $latitude;
/**
* @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
*/
private $longitude;
/**
* @ORM\Column(type="integer", length=10, nullable=true)
*/
private $rentalPrice;
/**
* @ORM\Column(type="integer", length=10, nullable=true)
*/
private $monthlyRentalPrice;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $rentFrequency;
/**
* @ORM\Column(type="integer", length=10, nullable=true)
*/
private $salePrice;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $cornerBanner;
/**
* @ORM\Column(type="text", nullable=false)
* @Assert\NotBlank()
*/
private $summary;
/**
* @ORM\Column(type="text", nullable=false)
* @Assert\NotBlank()
*/
private $description;
/**
* @ORM\Column(type="integer", length=4, nullable=false)
* @Assert\NotBlank()
*/
private $bedrooms;
/**
* @ORM\Column(type="integer", length=4, nullable=false)
* @Assert\NotBlank()
*/
private $bathrooms;
/**
* @ORM\Column(type="integer", length=4, nullable=false)
* @Assert\NotBlank()
*/
private $receptionRooms;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $epcUrl;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $showOnWebsite;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $showOnRightMove;
/**
* @ORM\Column(type="integer", nullable=true, length=1)
*/
private $rightMoveStatus;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $rightMoveLastUpdated;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $rightMoveListingURL;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $showOnZoopla;
/**
* @ORM\Column(type="integer", nullable=true, length=1)
*/
private $zooplaStatus;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $zooplaLastUpdated;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $zooplaListingURL;
/**
* @ORM\Column(type="integer", length=10, nullable=false)
*/
private $billableMonthlyRent;
/**
* @ORM\ManyToOne(targetEntity=Landlord::class, inversedBy="properties")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
**/
private $landlord;
/**
* @ORM\ManyToOne(targetEntity=Type::class, inversedBy="properties")
* @ORM\JoinColumn(nullable=false)
**/
private $type;
/**
* @ORM\ManyToOne(targetEntity=Area::class, inversedBy="properties")
* @ORM\JoinColumn(nullable=false)
**/
private $area;
/**
* @ORM\OneToMany(targetEntity=Image::class, mappedBy="property", cascade={"persist", "remove"})
**/
private $images;
/**
* @ORM\ManyToOne(targetEntity=Image::class)
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
**/
private $featuredImage;
/**
* @ORM\OneToMany(targetEntity=Maintenance::class, mappedBy="property", cascade={"persist", "remove"})
**/
private $maintenance;
/**
* @ORM\OneToMany(targetEntity=Item::class, mappedBy="property", cascade={"persist", "remove"})
**/
private $statementItems;
/**
* @ORM\OneToMany(targetEntity=PropertyFeature::class, mappedBy="property", cascade={"persist", "remove"})
**/
private $propertyFeatures;
public function __construct(array $defaults = array())
{
// Defaults
$this->setUuid(Uuid::uuid4());
$this->setCreated(new \DateTime());
$this->setModified(new \DateTime());
$this->images = new ArrayCollection();
$this->propertyFeatures = new ArrayCollection();
$this->bedrooms = 0;
$this->bathrooms = 0;
$this->receptionRooms = 0;
$this->showOnWebsite = true;
$this->showOnRightMove = true;
$this->rightMoveStatus = null;
$this->rightMoveLastUpdated = null;
$this->showOnZoopla = true;
$this->zooplaStatus = null;
$this->zooplaLastUpdated = null;
$this->billableMonthlyRent = 0;
parent::__construct($defaults);
}
public function getMicroAddress(): array
{
return array_filter([
$this->getNameNumber(),
$this->getAddress2()
]);
}
public function getShortAddress(): array
{
return array_filter([
$this->getNameNumber(),
$this->getAddress2(),
$this->getPostcode()
]);
}
public function getFullAddress(): array
{
return array_filter([
$this->getNameNumber(),
$this->getAddress2(),
$this->getAddress3(),
$this->getAddress4(),
$this->getTown(),
$this->getPostcode()
]);
}
public function __toString()
{
return $this->getId();
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): LazyUuidFromString
{
return $this->uuid;
}
public function setUuid(LazyUuidFromString $uuid): void
{
$this->uuid = $uuid;
}
public function setCreated(\DateTime $created): void
{
$this->created = $created;
}
public function getCreated(): \DateTime
{
return $this->created;
}
public function getModified() : \DateTime
{
return $this->modified;
}
public function setModified(\DateTime $modified): void
{
$this->modified = $modified;
}
public function getDateAvailable(): ?\DateTime
{
return $this->dateAvailable;
}
public function setDateAvailable(\DateTime $dateAvailable = null): void
{
$this->dateAvailable = $dateAvailable;
}
public function getNameNumber(): string
{
return $this->nameNumber;
}
public function setNameNumber(string $nameNumber): void
{
$this->nameNumber = $nameNumber;
}
public function getAddress2(): ?string
{
return $this->address2;
}
public function setAddress2(string $address2 = null): void
{
$this->address2 = $address2;
}
public function getAddress3(): ?string
{
return $this->address3;
}
public function setAddress3(string $address3 = null): void
{
$this->address3 = $address3;
}
public function getAddress4(): ?string
{
return $this->address4;
}
public function setAddress4(string $address4 = null): void
{
$this->address4 = $address4;
}
public function getTown(): string
{
return $this->town;
}
public function setTown(string $town): void
{
$this->town = $town;
}
public function getPostcode(): string
{
return $this->postcode;
}
public function setPostcode(string $postcode): void
{
// Sanitize it
$postcode = strtoupper(preg_replace("/[^A-Za-z0-9 ]/", '', $postcode));
$this->postcode = $postcode;
}
public function getType(): ?Type
{
return $this->type;
}
public function setType(Type $type): void
{
$this->type = $type;
}
public function getArea(): ?Area
{
return $this->area;
}
public function setArea(Area $area): void
{
$this->area = $area;
}
public function getRentalPrice(): int
{
return $this->rentalPrice;
}
public function setRentalPrice(int $rentalPrice = null): void
{
$this->rentalPrice = $rentalPrice;
}
public function getSummary(): string
{
return $this->summary;
}
public function setSummary(string $summary): void
{
$this->summary = $summary;
}
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description): void
{
$this->description = $description;
}
public function getBedrooms(): int
{
return $this->bedrooms;
}
public function setBedrooms(int $bedrooms): void
{
$this->bedrooms = $bedrooms;
}
public function getBathrooms(): int
{
return $this->bathrooms;
}
public function setBathrooms(int $bathrooms): void
{
$this->bathrooms = $bathrooms;
}
public function getReceptionRooms(): int
{
return $this->receptionRooms;
}
public function setReceptionRooms(int $receptionRooms): void
{
$this->receptionRooms = $receptionRooms;
}
public function getRentFrequency()
{
return $this->rentFrequency;
}
public function setRentFrequency(string $rentFrequency = null): void
{
$this->rentFrequency = $rentFrequency;
}
public function getPropertyFeatures()
{
return $this->propertyFeatures;
}
public function getReference()
{
return $this->reference;
}
public function setReference(int $reference)
{
$this->reference = $reference;
}
public function getLatitude()
{
return $this->latitude;
}
public function setLatitude(float $latitude = null)
{
$this->latitude = $latitude;
}
public function getLongitude()
{
return $this->longitude;
}
public function setLongitude(float $longitude = null)
{
$this->longitude = $longitude;
}
public function getListingType()
{
return $this->listingType;
}
public function setListingType(string $listingType)
{
if(!in_array($listingType, ["letting", "sale"]))
throw new \Exception("Invalid listing type: " . $listingType);
$this->listingType = $listingType;
}
public function getSalePrice()
{
return $this->salePrice;
}
public function setSalePrice(int $salePrice = null)
{
$this->salePrice = $salePrice;
}
public function getMonthlyRentalPrice()
{
return $this->monthlyRentalPrice;
}
public function setMonthlyRentalPrice(float $monthlyRentalPrice = null)
{
$this->monthlyRentalPrice = $monthlyRentalPrice;
}
public function getFeaturedImage()
{
return $this->featuredImage;
}
public function setFeaturedImage(Image $featuredImage = null)
{
$this->featuredImage = $featuredImage;
}
public function getEpcUrl()
{
return $this->epcUrl;
}
public function setEpcUrl(string $epcUrl = null)
{
$this->epcUrl = $epcUrl;
}
public function getShowOnWebsite()
{
return $this->showOnWebsite;
}
public function setShowOnWebsite(bool $showOnWebsite)
{
$this->showOnWebsite = $showOnWebsite;
}
public function getShowOnRightMove()
{
return $this->showOnRightMove;
}
public function setShowOnRightMove(bool $showOnRightMove)
{
$this->showOnRightMove = $showOnRightMove;
}
public function getShowOnZoopla()
{
return $this->showOnZoopla;
}
public function setShowOnZoopla(bool $showOnZoopla)
{
$this->showOnZoopla = $showOnZoopla;
}
public function getRightMoveStatus()
{
return $this->rightMoveStatus;
}
public function setRightMoveStatus(int $rightMoveStatus = null)
{
$this->rightMoveStatus = $rightMoveStatus;
}
public function getRightMoveLastUpdated()
{
return $this->rightMoveLastUpdated;
}
public function setRightMoveLastUpdated(\DateTime $rightMoveLastUpdated = null)
{
$this->rightMoveLastUpdated = $rightMoveLastUpdated;
}
public function getZooplaStatus()
{
return $this->zooplaStatus;
}
public function setZooplaStatus(int $zooplaStatus = null)
{
$this->zooplaStatus = $zooplaStatus;
}
public function getZooplaLastUpdated()
{
return $this->zooplaLastUpdated;
}
public function setZooplaLastUpdated(\DateTime $zooplaLastUpdated = null)
{
$this->zooplaLastUpdated = $zooplaLastUpdated;
}
public function getImages()
{
return $this->images;
}
public function getCornerBanner()
{
return $this->cornerBanner;
}
public function setCornerBanner(string $cornerBanner = null)
{
$this->cornerBanner = $cornerBanner;
}
public function getRightMoveListingURL()
{
return $this->rightMoveListingURL;
}
public function setRightMoveListingURL(string $rightMoveListingURL = null)
{
$this->rightMoveListingURL = $rightMoveListingURL;
}
public function getZooplaListingURL()
{
return $this->zooplaListingURL;
}
public function setZooplaListingURL(string $zooplaListingURL = null)
{
$this->zooplaListingURL = $zooplaListingURL;
}
public function getLandlord()
{
return $this->landlord;
}
public function setLandlord(Landlord $landlord = null)
{
$this->landlord = $landlord;
}
public function getBillableMonthlyRent()
{
return $this->billableMonthlyRent;
}
public function setBillableMonthlyRent(int $billableMonthlyRent)
{
$this->billableMonthlyRent = $billableMonthlyRent;
}
}