Files
immorechner/src/Entity/Immobilie.php
2025-11-08 18:56:59 +01:00

326 lines
7.1 KiB
PHP

<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Enum\ImmobilienTyp;
use App\Repository\ImmobilieRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: ImmobilieRepository::class)]
#[ORM\Table(name: 'immobilien')]
#[ORM\HasLifecycleCallbacks]
#[ApiResource]
class Immobilie
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'immobilien')]
#[ORM\JoinColumn(nullable: false)]
#[Assert\NotNull]
private User $verwalter;
#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
#[Assert\Length(min: 5, max: 255)]
private string $adresse;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2)]
#[Assert\NotBlank]
#[Assert\Positive]
private float $preis;
#[ORM\Column(type: 'decimal', precision: 8, scale: 2)]
#[Assert\NotBlank]
#[Assert\Positive]
private float $flaeche;
#[ORM\Column(type: 'boolean')]
private bool $garage = false;
#[ORM\Column(type: 'integer')]
#[Assert\NotBlank]
#[Assert\Positive]
private int $zimmer;
#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\Range(min: 1800, max: 2100)]
private ?int $baujahr = null;
#[ORM\Column(type: 'string', enumType: ImmobilienTyp::class)]
private ImmobilienTyp $typ;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $beschreibung = null;
#[ORM\Column(type: 'boolean')]
private bool $verfuegbar = true;
#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\PositiveOrZero]
private ?int $balkonFlaeche = null;
#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\PositiveOrZero]
private ?int $kellerFlaeche = null;
#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\Min(0)]
#[Assert\Max(10)]
private ?int $etage = null;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private ?string $heizungstyp = null;
#[ORM\Column(type: 'decimal', precision: 6, scale: 2, nullable: true)]
#[Assert\PositiveOrZero]
private ?float $nebenkosten = null;
#[ORM\Column(type: 'datetime')]
private \DateTimeInterface $createdAt;
#[ORM\Column(type: 'datetime')]
private \DateTimeInterface $updatedAt;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->typ = ImmobilienTyp::WOHNUNG;
}
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getAdresse(): string
{
return $this->adresse;
}
public function setAdresse(string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getPreis(): float
{
return $this->preis;
}
public function setPreis(float $preis): self
{
$this->preis = $preis;
return $this;
}
public function getFlaeche(): float
{
return $this->flaeche;
}
public function setFlaeche(float $flaeche): self
{
$this->flaeche = $flaeche;
return $this;
}
public function getGarage(): bool
{
return $this->garage;
}
public function isGarage(): bool
{
return $this->garage;
}
public function setGarage(bool $garage): self
{
$this->garage = $garage;
return $this;
}
public function getZimmer(): int
{
return $this->zimmer;
}
public function setZimmer(int $zimmer): self
{
$this->zimmer = $zimmer;
return $this;
}
public function getBaujahr(): ?int
{
return $this->baujahr;
}
public function setBaujahr(?int $baujahr): self
{
$this->baujahr = $baujahr;
return $this;
}
public function getTyp(): ImmobilienTyp
{
return $this->typ;
}
public function setTyp(ImmobilienTyp $typ): self
{
$this->typ = $typ;
return $this;
}
public function getBeschreibung(): ?string
{
return $this->beschreibung;
}
public function setBeschreibung(?string $beschreibung): self
{
$this->beschreibung = $beschreibung;
return $this;
}
public function isVerfuegbar(): bool
{
return $this->verfuegbar;
}
public function setVerfuegbar(bool $verfuegbar): self
{
$this->verfuegbar = $verfuegbar;
return $this;
}
public function getBalkonFlaeche(): ?int
{
return $this->balkonFlaeche;
}
public function setBalkonFlaeche(?int $balkonFlaeche): self
{
$this->balkonFlaeche = $balkonFlaeche;
return $this;
}
public function getKellerFlaeche(): ?int
{
return $this->kellerFlaeche;
}
public function setKellerFlaeche(?int $kellerFlaeche): self
{
$this->kellerFlaeche = $kellerFlaeche;
return $this;
}
public function getEtage(): ?int
{
return $this->etage;
}
public function setEtage(?int $etage): self
{
$this->etage = $etage;
return $this;
}
public function getHeizungstyp(): ?string
{
return $this->heizungstyp;
}
public function setHeizungstyp(?string $heizungstyp): self
{
$this->heizungstyp = $heizungstyp;
return $this;
}
public function getNebenkosten(): ?float
{
return $this->nebenkosten;
}
public function setNebenkosten(?float $nebenkosten): self
{
$this->nebenkosten = $nebenkosten;
return $this;
}
public function getCreatedAt(): \DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): \DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getVerwalter(): User
{
return $this->verwalter;
}
public function setVerwalter(User $verwalter): self
{
$this->verwalter = $verwalter;
return $this;
}
/**
* Berechnet den Preis pro Quadratmeter
*/
public function getPreisProQm(): float
{
if ($this->flaeche > 0) {
return round($this->preis / $this->flaeche, 2);
}
return 0;
}
/**
* Berechnet die Gesamtfläche inkl. Balkon und Keller
*/
public function getGesamtflaeche(): float
{
$gesamt = $this->flaeche;
if ($this->balkonFlaeche) {
$gesamt += $this->balkonFlaeche;
}
if ($this->kellerFlaeche) {
$gesamt += $this->kellerFlaeche;
}
return $gesamt;
}
}