<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Table("Address")
*
* @ORM\HasLifecycleCallbacks()
*
* @ORM\Entity(repositoryClass="App\Repository\AddressRepository")
*/
class Address
{
/**
* @Groups({"addressdetail", "adminindex"})
*
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Groups({"addressindex", "adminindex"})
*
* @ORM\Column(type="string", length=255)
*/
private $street;
/**
* @Groups({"addressindex", "adminindex"})
*
* @ORM\Column(type="string", length=6)
*/
private $houseNumber;
/**
* @Groups({"addressdetail", "adminindex"})
*
* @ORM\Column(type="string", length=255)
*/
private $city;
/**
* @Groups({"addressdetail", "adminindex"})
*
* @ORM\Column(type="string", length=8)
*/
private $zipCode;
/**
* @Groups({"addressdetail", "adminindex"})
*
* @ORM\Column(type="string", length=2)
*/
private $country = 'DE';
/**
* @ManyToOne(targetEntity="App\Entity\Account", cascade={"persist"})
*
* @JoinColumn(name="account_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $account;
/**
* @Groups({"adminindex"})
*
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\PrePersist()
*/
public function prePersist()
{
if (!$this->getCreatedAt()) {
$this->setCreatedAt(new \DateTime());
}
}
public function getId()
{
return $this->id;
}
public function getStreet(): ?string
{
return $this->street;
}
public function setStreet(string $street): self
{
$this->street = $street;
return $this;
}
public function getHouseNumber(): ?string
{
return $this->houseNumber;
}
public function setHouseNumber(string $houseNumber): self
{
$this->houseNumber = $houseNumber;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getZipCode(): ?string
{
return $this->zipCode;
}
public function setZipCode(string $zipCode): self
{
$this->zipCode = $zipCode;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getAccount(): ?Account
{
return $this->account;
}
public function setAccount(?Account $account): self
{
$this->account = $account;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function hasChangedMainFields(?Address $address): bool
{
if (null === $address) {
return 'DE' !== $this->getCountry()
|| null !== $this->getStreet()
|| null !== $this->getHouseNumber()
|| null !== $this->getZipCode()
|| null !== $this->getCity();
}
return
$this->getStreet() !== $address->getStreet()
|| $this->getHouseNumber() !== $address->getHouseNumber()
|| $this->getZipCode() !== $address->getZipCode()
|| $this->getCity() !== $address->getCity()
|| $this->getCountry() !== $address->getCountry();
}
}