src/Entity/Properties/Property.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Properties;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Symfony\Component\Validator\Constraints AS Assert;
  5. use Doctrine\ORM\Mapping AS ORM;
  6. use Ramsey\Uuid\Uuid;
  7. use Ramsey\Uuid\Lazy\LazyUuidFromString;
  8. use App\Entity\BaseEntity;
  9. use App\Entity\Landlords\Landlord;
  10. use App\Entity\Properties\Type;
  11. use App\Entity\Properties\Area;
  12. use App\Entity\Properties\Image;
  13. use App\Entity\Properties\PropertyFeature;
  14. use App\Entity\Maintenance\Maintenance;
  15. use App\Entity\Statements\Item;
  16. /**
  17.  * @ORM\Entity(repositoryClass="App\Repository\Properties\PropertyRepository")
  18.  * @ORM\Table(name="properties_property")
  19.  * @ORM\EntityListeners({"App\Listener\Entity\Properties\PropertyListener"})
  20.  */
  21. class Property extends BaseEntity
  22. {
  23.     /**
  24.     * @ORM\Id
  25.     * @ORM\GeneratedValue(strategy="AUTO")
  26.     * @ORM\Column(type="integer")
  27.     */
  28.     private $id;
  29.     /**
  30.      * @ORM\Column(type="uuid")
  31.      * @Assert\Uuid
  32.      */
  33.     protected $uuid;
  34.     /**
  35.      * @var \DateTime
  36.      *
  37.      * @ORM\Column(type="datetime", nullable=false)
  38.      * @Assert\Type("\DateTime")
  39.      */
  40.     private $created;
  41.     /**
  42.      * @var \DateTime
  43.      *
  44.      * @ORM\Column(type="datetime", nullable=false)
  45.      * @Assert\Type("\DateTime")
  46.      */
  47.     private $modified;
  48.     /**
  49.      * @ORM\Column(type="string", length=20, nullable=false)
  50.      * @Assert\NotBlank()
  51.      */
  52.     private $listingType;
  53.     /**
  54.     * @ORM\Column(type="integer", nullable=false)
  55.     */
  56.     private $reference;
  57.     /**
  58.      * @var \DateTime
  59.      *
  60.      * @ORM\Column(type="date", nullable=true)
  61.      * @Assert\Type("\DateTime")
  62.      */
  63.     private $dateAvailable;
  64.     /**
  65.      * @ORM\Column(type="string", length=128, nullable=false)
  66.      * @Assert\NotBlank()
  67.      */
  68.     private $nameNumber;
  69.     /**
  70.      * @ORM\Column(type="string", length=128, nullable=true)
  71.      */
  72.     private $address2;
  73.     /**
  74.      * @ORM\Column(type="string", length=128, nullable=true)
  75.      */
  76.     private $address3;
  77.     /**
  78.      * @ORM\Column(type="string", length=128, nullable=true)
  79.      */
  80.     private $address4;
  81.     /**
  82.      * @ORM\Column(type="string", length=128, nullable=false)
  83.      * @Assert\NotBlank()
  84.      */
  85.     private $town;
  86.     /**
  87.      * @ORM\Column(type="string", length=10, nullable=false)
  88.      * @Assert\NotBlank()
  89.      */
  90.     private $postcode;
  91.     /**
  92.      * @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
  93.      */
  94.     private $latitude;
  95.     /**
  96.      * @ORM\Column(type="decimal", precision=20, scale=16, nullable=true)
  97.      */
  98.     private $longitude;
  99.     /**
  100.      * @ORM\Column(type="integer", length=10, nullable=true)
  101.      */
  102.     private $rentalPrice;
  103.     /**
  104.      * @ORM\Column(type="integer", length=10, nullable=true)
  105.      */
  106.     private $monthlyRentalPrice;
  107.     /**
  108.      * @ORM\Column(type="string", length=10, nullable=true)
  109.      */
  110.     private $rentFrequency;
  111.     /**
  112.      * @ORM\Column(type="integer", length=10, nullable=true)
  113.      */
  114.     private $salePrice;
  115.     /**
  116.      * @ORM\Column(type="string", length=100, nullable=true)
  117.      */
  118.     private $cornerBanner;
  119.     /**
  120.      * @ORM\Column(type="text", nullable=false)
  121.      * @Assert\NotBlank()
  122.      */
  123.     private $summary;
  124.     /**
  125.      * @ORM\Column(type="text", nullable=false)
  126.      * @Assert\NotBlank()
  127.      */
  128.     private $description;
  129.     /**
  130.      * @ORM\Column(type="integer", length=4, nullable=false)
  131.      * @Assert\NotBlank()
  132.      */
  133.     private $bedrooms;
  134.     /**
  135.      * @ORM\Column(type="integer", length=4, nullable=false)
  136.      * @Assert\NotBlank()
  137.      */
  138.     private $bathrooms;
  139.     /**
  140.      * @ORM\Column(type="integer", length=4, nullable=false)
  141.      * @Assert\NotBlank()
  142.      */
  143.     private $receptionRooms;
  144.     /**
  145.      * @ORM\Column(type="string", length=255, nullable=true)
  146.      */
  147.     private $epcUrl;
  148.     /**
  149.      * @ORM\Column(type="boolean", nullable=false)
  150.      */
  151.     private $showOnWebsite;
  152.     /**
  153.      * @ORM\Column(type="boolean", nullable=false)
  154.      */
  155.     private $showOnRightMove;
  156.     /**
  157.      * @ORM\Column(type="integer", nullable=true, length=1)
  158.      */
  159.     private $rightMoveStatus;
  160.     /**
  161.      * @ORM\Column(type="datetime", nullable=true)
  162.      */
  163.     private $rightMoveLastUpdated;
  164.     /**
  165.      * @ORM\Column(type="string", length=255, nullable=true)
  166.      */
  167.     private $rightMoveListingURL;
  168.     /**
  169.      * @ORM\Column(type="boolean", nullable=false)
  170.      */
  171.     private $showOnZoopla;
  172.     /**
  173.      * @ORM\Column(type="integer", nullable=true, length=1)
  174.      */
  175.     private $zooplaStatus;
  176.     /**
  177.      * @ORM\Column(type="datetime", nullable=true)
  178.      */
  179.     private $zooplaLastUpdated;
  180.     /**
  181.      * @ORM\Column(type="string", length=255, nullable=true)
  182.      */
  183.     private $zooplaListingURL;
  184.     /**
  185.      * @ORM\Column(type="integer", length=10, nullable=false)
  186.      */
  187.     private $billableMonthlyRent;
  188.     /**
  189.      * @ORM\ManyToOne(targetEntity=Landlord::class, inversedBy="properties")
  190.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  191.      **/
  192.     private $landlord;
  193.     /**
  194.      * @ORM\ManyToOne(targetEntity=Type::class, inversedBy="properties")
  195.      * @ORM\JoinColumn(nullable=false)
  196.      **/
  197.     private $type;
  198.     /**
  199.      * @ORM\ManyToOne(targetEntity=Area::class, inversedBy="properties")
  200.      * @ORM\JoinColumn(nullable=false)
  201.      **/
  202.     private $area;
  203.     /**
  204.      * @ORM\OneToMany(targetEntity=Image::class, mappedBy="property", cascade={"persist", "remove"})
  205.      **/
  206.     private $images;
  207.     /**
  208.      * @ORM\ManyToOne(targetEntity=Image::class)
  209.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  210.      **/
  211.     private $featuredImage;
  212.     /**
  213.      * @ORM\OneToMany(targetEntity=Maintenance::class, mappedBy="property", cascade={"persist", "remove"})
  214.      **/
  215.     private $maintenance;
  216.     /**
  217.      * @ORM\OneToMany(targetEntity=Item::class, mappedBy="property", cascade={"persist", "remove"})
  218.      **/
  219.     private $statementItems;
  220.     /**
  221.      * @ORM\OneToMany(targetEntity=PropertyFeature::class, mappedBy="property", cascade={"persist", "remove"})
  222.      **/
  223.     private $propertyFeatures;
  224.     public function __construct(array $defaults = array())
  225.     {
  226.         // Defaults
  227.         $this->setUuid(Uuid::uuid4());
  228.         $this->setCreated(new \DateTime());
  229.         $this->setModified(new \DateTime());
  230.         $this->images = new ArrayCollection();
  231.         $this->propertyFeatures = new ArrayCollection();
  232.         $this->bedrooms 0;
  233.         $this->bathrooms 0;
  234.         $this->receptionRooms 0;
  235.         $this->showOnWebsite true;
  236.         $this->showOnRightMove true;
  237.         $this->rightMoveStatus null;
  238.         $this->rightMoveLastUpdated null;
  239.         $this->showOnZoopla true;
  240.         $this->zooplaStatus null;
  241.         $this->zooplaLastUpdated null;
  242.         $this->billableMonthlyRent 0;
  243.         parent::__construct($defaults);
  244.     }
  245.     public function getMicroAddress(): array
  246.     {
  247.         return array_filter([
  248.             $this->getNameNumber(),
  249.             $this->getAddress2()
  250.         ]);
  251.     }
  252.     public function getShortAddress(): array
  253.     {
  254.         return array_filter([
  255.             $this->getNameNumber(),
  256.             $this->getAddress2(),
  257.             $this->getPostcode()
  258.         ]);
  259.     }
  260.     public function getFullAddress(): array
  261.     {
  262.         return array_filter([
  263.             $this->getNameNumber(),
  264.             $this->getAddress2(),
  265.             $this->getAddress3(),
  266.             $this->getAddress4(),
  267.             $this->getTown(),
  268.             $this->getPostcode()
  269.         ]);
  270.     }
  271.     public function __toString()
  272.     {
  273.         return $this->getId();
  274.     }
  275.     public function getId(): ?int
  276.     {
  277.         return $this->id;
  278.     }
  279.     public function getUuid(): LazyUuidFromString
  280.     {
  281.         return $this->uuid;
  282.     }
  283.     public function setUuid(LazyUuidFromString $uuid): void
  284.     {
  285.         $this->uuid $uuid;
  286.     }
  287.     public function setCreated(\DateTime $created): void
  288.     {
  289.         $this->created $created;
  290.     }
  291.     public function getCreated(): \DateTime
  292.     {
  293.         return $this->created;
  294.     }
  295.     public function getModified() : \DateTime
  296.     {
  297.         return $this->modified;
  298.     }
  299.     public function setModified(\DateTime $modified): void
  300.     {
  301.         $this->modified $modified;
  302.     }
  303.     public function getDateAvailable(): ?\DateTime
  304.     {
  305.         return $this->dateAvailable;
  306.     }
  307.     public function setDateAvailable(\DateTime $dateAvailable null): void
  308.     {
  309.         $this->dateAvailable $dateAvailable;
  310.     }
  311.     public function getNameNumber(): string
  312.     {
  313.         return $this->nameNumber;
  314.     }
  315.     public function setNameNumber(string $nameNumber): void
  316.     {
  317.         $this->nameNumber $nameNumber;
  318.     }
  319.     public function getAddress2(): ?string
  320.     {
  321.         return $this->address2;
  322.     }
  323.     public function setAddress2(string $address2 null): void
  324.     {
  325.         $this->address2 $address2;
  326.     }
  327.     public function getAddress3(): ?string
  328.     {
  329.         return $this->address3;
  330.     }
  331.     public function setAddress3(string $address3 null): void
  332.     {
  333.         $this->address3 $address3;
  334.     }
  335.     public function getAddress4(): ?string
  336.     {
  337.         return $this->address4;
  338.     }
  339.     public function setAddress4(string $address4 null): void
  340.     {
  341.         $this->address4 $address4;
  342.     }
  343.     public function getTown(): string
  344.     {
  345.         return $this->town;
  346.     }
  347.     public function setTown(string $town): void
  348.     {
  349.         $this->town $town;
  350.     }
  351.     public function getPostcode(): string
  352.     {
  353.         return $this->postcode;
  354.     }
  355.     public function setPostcode(string $postcode): void
  356.     {
  357.         // Sanitize it
  358.         $postcode strtoupper(preg_replace("/[^A-Za-z0-9 ]/"''$postcode));
  359.         $this->postcode $postcode;
  360.     }
  361.     public function getType(): ?Type
  362.     {
  363.         return $this->type;
  364.     }
  365.     public function setType(Type $type): void
  366.     {
  367.         $this->type $type;
  368.     }
  369.     public function getArea(): ?Area
  370.     {
  371.         return $this->area;
  372.     }
  373.     public function setArea(Area $area): void
  374.     {
  375.         $this->area $area;
  376.     }
  377.     public function getRentalPrice(): int
  378.     {
  379.         return $this->rentalPrice;
  380.     }
  381.     public function setRentalPrice(int $rentalPrice null): void
  382.     {
  383.         $this->rentalPrice $rentalPrice;
  384.     }
  385.     public function getSummary(): string
  386.     {
  387.         return $this->summary;
  388.     }
  389.     public function setSummary(string $summary): void
  390.     {
  391.         $this->summary $summary;
  392.     }
  393.     public function getDescription(): string
  394.     {
  395.         return $this->description;
  396.     }
  397.     public function setDescription(string $description): void
  398.     {
  399.         $this->description $description;
  400.     }
  401.     public function getBedrooms(): int
  402.     {
  403.         return $this->bedrooms;
  404.     }
  405.     public function setBedrooms(int $bedrooms): void
  406.     {
  407.         $this->bedrooms $bedrooms;
  408.     }
  409.     public function getBathrooms(): int
  410.     {
  411.         return $this->bathrooms;
  412.     }
  413.     public function setBathrooms(int $bathrooms): void
  414.     {
  415.         $this->bathrooms $bathrooms;
  416.     }
  417.     public function getReceptionRooms(): int
  418.     {
  419.         return $this->receptionRooms;
  420.     }
  421.     public function setReceptionRooms(int $receptionRooms): void
  422.     {
  423.         $this->receptionRooms $receptionRooms;
  424.     }
  425.     public function getRentFrequency()
  426.     {
  427.         return $this->rentFrequency;
  428.     }
  429.     public function setRentFrequency(string $rentFrequency null): void
  430.     {
  431.         $this->rentFrequency $rentFrequency;
  432.     }
  433.     public function getPropertyFeatures()
  434.     {
  435.         return $this->propertyFeatures;
  436.     }
  437.     public function getReference()
  438.     {
  439.         return $this->reference;
  440.     }
  441.     public function setReference(int $reference)
  442.     {
  443.         $this->reference $reference;
  444.     }
  445.     public function getLatitude()
  446.     {
  447.         return $this->latitude;
  448.     }
  449.     public function setLatitude(float $latitude null)
  450.     {
  451.         $this->latitude $latitude;
  452.     }
  453.     public function getLongitude()
  454.     {
  455.         return $this->longitude;
  456.     }
  457.     public function setLongitude(float $longitude null)
  458.     {
  459.         $this->longitude $longitude;
  460.     }
  461.     public function getListingType()
  462.     {
  463.         return $this->listingType;
  464.     }
  465.     public function setListingType(string $listingType)
  466.     {
  467.         if(!in_array($listingType, ["letting""sale"]))
  468.             throw new \Exception("Invalid listing type: " $listingType);
  469.         $this->listingType $listingType;
  470.     }
  471.     public function getSalePrice()
  472.     {
  473.         return $this->salePrice;
  474.     }
  475.     public function setSalePrice(int $salePrice null)
  476.     {
  477.         $this->salePrice $salePrice;
  478.     }
  479.     public function getMonthlyRentalPrice()
  480.     {
  481.         return $this->monthlyRentalPrice;
  482.     }
  483.     public function setMonthlyRentalPrice(float $monthlyRentalPrice null)
  484.     {
  485.         $this->monthlyRentalPrice $monthlyRentalPrice;
  486.     }
  487.     public function getFeaturedImage()
  488.     {
  489.         return $this->featuredImage;
  490.     }
  491.     public function setFeaturedImage(Image $featuredImage null)
  492.     {
  493.         $this->featuredImage $featuredImage;
  494.     }
  495.     public function getEpcUrl()
  496.     {
  497.         return $this->epcUrl;
  498.     }
  499.     public function setEpcUrl(string $epcUrl null)
  500.     {
  501.         $this->epcUrl $epcUrl;
  502.     }
  503.     public function getShowOnWebsite()
  504.     {
  505.         return $this->showOnWebsite;
  506.     }
  507.     public function setShowOnWebsite(bool $showOnWebsite)
  508.     {
  509.         $this->showOnWebsite $showOnWebsite;
  510.     }
  511.     public function getShowOnRightMove()
  512.     {
  513.         return $this->showOnRightMove;
  514.     }
  515.     public function setShowOnRightMove(bool $showOnRightMove)
  516.     {
  517.         $this->showOnRightMove $showOnRightMove;
  518.     }
  519.     public function getShowOnZoopla()
  520.     {
  521.         return $this->showOnZoopla;
  522.     }
  523.     public function setShowOnZoopla(bool $showOnZoopla)
  524.     {
  525.         $this->showOnZoopla $showOnZoopla;
  526.     }
  527.     public function getRightMoveStatus()
  528.     {
  529.         return $this->rightMoveStatus;
  530.     }
  531.     public function setRightMoveStatus(int $rightMoveStatus null)
  532.     {
  533.         $this->rightMoveStatus $rightMoveStatus;
  534.     }
  535.     public function getRightMoveLastUpdated()
  536.     {
  537.         return $this->rightMoveLastUpdated;
  538.     }
  539.     public function setRightMoveLastUpdated(\DateTime $rightMoveLastUpdated null)
  540.     {
  541.         $this->rightMoveLastUpdated $rightMoveLastUpdated;
  542.     }
  543.     public function getZooplaStatus()
  544.     {
  545.         return $this->zooplaStatus;
  546.     }
  547.     public function setZooplaStatus(int $zooplaStatus null)
  548.     {
  549.         $this->zooplaStatus $zooplaStatus;
  550.     }
  551.     public function getZooplaLastUpdated()
  552.     {
  553.         return $this->zooplaLastUpdated;
  554.     }
  555.     public function setZooplaLastUpdated(\DateTime $zooplaLastUpdated null)
  556.     {
  557.         $this->zooplaLastUpdated $zooplaLastUpdated;
  558.     }
  559.     public function getImages()
  560.     {
  561.         return $this->images;
  562.     }
  563.     public function getCornerBanner()
  564.     {
  565.         return $this->cornerBanner;
  566.     }
  567.     public function setCornerBanner(string $cornerBanner null)
  568.     {
  569.         $this->cornerBanner $cornerBanner;
  570.     }
  571.     public function getRightMoveListingURL()
  572.     {
  573.         return $this->rightMoveListingURL;
  574.     }
  575.     public function setRightMoveListingURL(string $rightMoveListingURL null)
  576.     {
  577.         $this->rightMoveListingURL $rightMoveListingURL;
  578.     }
  579.     public function getZooplaListingURL()
  580.     {
  581.         return $this->zooplaListingURL;
  582.     }
  583.     public function setZooplaListingURL(string $zooplaListingURL null)
  584.     {
  585.         $this->zooplaListingURL $zooplaListingURL;
  586.     }
  587.     public function getLandlord()
  588.     {
  589.         return $this->landlord;
  590.     }
  591.     public function setLandlord(Landlord $landlord null)
  592.     {
  593.         $this->landlord $landlord;
  594.     }
  595.     public function getBillableMonthlyRent()
  596.     {
  597.         return $this->billableMonthlyRent;
  598.     }
  599.     public function setBillableMonthlyRent(int $billableMonthlyRent)
  600.     {
  601.         $this->billableMonthlyRent $billableMonthlyRent;
  602.     }
  603. }