src/Entity/Address.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\ORM\Mapping\JoinColumn;
  5. use Doctrine\ORM\Mapping\ManyToOne;
  6. use JMS\Serializer\Annotation\Groups;
  7. /**
  8.  * @ORM\Table("Address")
  9.  *
  10.  * @ORM\HasLifecycleCallbacks()
  11.  *
  12.  * @ORM\Entity(repositoryClass="App\Repository\AddressRepository")
  13.  */
  14. class Address
  15. {
  16.     /**
  17.      * @Groups({"addressdetail", "adminindex"})
  18.      *
  19.      * @ORM\Id()
  20.      *
  21.      * @ORM\GeneratedValue()
  22.      *
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @Groups({"addressindex", "adminindex"})
  28.      *
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $street;
  32.     /**
  33.      * @Groups({"addressindex", "adminindex"})
  34.      *
  35.      * @ORM\Column(type="string", length=6)
  36.      */
  37.     private $houseNumber;
  38.     /**
  39.      * @Groups({"addressdetail", "adminindex"})
  40.      *
  41.      * @ORM\Column(type="string", length=255)
  42.      */
  43.     private $city;
  44.     /**
  45.      * @Groups({"addressdetail", "adminindex"})
  46.      *
  47.      * @ORM\Column(type="string", length=8)
  48.      */
  49.     private $zipCode;
  50.     /**
  51.      * @Groups({"addressdetail", "adminindex"})
  52.      *
  53.      * @ORM\Column(type="string", length=2)
  54.      */
  55.     private $country 'DE';
  56.     /**
  57.      * @ManyToOne(targetEntity="App\Entity\Account", cascade={"persist"})
  58.      *
  59.      * @JoinColumn(name="account_id", referencedColumnName="id", onDelete="SET NULL")
  60.      */
  61.     private $account;
  62.     /**
  63.      * @Groups({"adminindex"})
  64.      *
  65.      * @ORM\Column(type="datetime")
  66.      */
  67.     private $created_at;
  68.     /**
  69.      * @ORM\PrePersist()
  70.      */
  71.     public function prePersist()
  72.     {
  73.         if (!$this->getCreatedAt()) {
  74.             $this->setCreatedAt(new \DateTime());
  75.         }
  76.     }
  77.     public function getId()
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getStreet(): ?string
  82.     {
  83.         return $this->street;
  84.     }
  85.     public function setStreet(string $street): self
  86.     {
  87.         $this->street $street;
  88.         return $this;
  89.     }
  90.     public function getHouseNumber(): ?string
  91.     {
  92.         return $this->houseNumber;
  93.     }
  94.     public function setHouseNumber(string $houseNumber): self
  95.     {
  96.         $this->houseNumber $houseNumber;
  97.         return $this;
  98.     }
  99.     public function getCity(): ?string
  100.     {
  101.         return $this->city;
  102.     }
  103.     public function setCity(string $city): self
  104.     {
  105.         $this->city $city;
  106.         return $this;
  107.     }
  108.     public function getZipCode(): ?string
  109.     {
  110.         return $this->zipCode;
  111.     }
  112.     public function setZipCode(string $zipCode): self
  113.     {
  114.         $this->zipCode $zipCode;
  115.         return $this;
  116.     }
  117.     public function getCountry(): ?string
  118.     {
  119.         return $this->country;
  120.     }
  121.     public function setCountry(string $country): self
  122.     {
  123.         $this->country $country;
  124.         return $this;
  125.     }
  126.     public function getAccount(): ?Account
  127.     {
  128.         return $this->account;
  129.     }
  130.     public function setAccount(?Account $account): self
  131.     {
  132.         $this->account $account;
  133.         return $this;
  134.     }
  135.     public function getCreatedAt(): ?\DateTimeInterface
  136.     {
  137.         return $this->created_at;
  138.     }
  139.     public function setCreatedAt(\DateTimeInterface $created_at): self
  140.     {
  141.         $this->created_at $created_at;
  142.         return $this;
  143.     }
  144.     public function hasChangedMainFields(?Address $address): bool
  145.     {
  146.         if (null === $address) {
  147.             return 'DE' !== $this->getCountry()
  148.                 || null !== $this->getStreet()
  149.                 || null !== $this->getHouseNumber()
  150.                 || null !== $this->getZipCode()
  151.                 || null !== $this->getCity();
  152.         }
  153.         return
  154.             $this->getStreet() !== $address->getStreet()
  155.             || $this->getHouseNumber() !== $address->getHouseNumber()
  156.             || $this->getZipCode() !== $address->getZipCode()
  157.             || $this->getCity() !== $address->getCity()
  158.             || $this->getCountry() !== $address->getCountry();
  159.     }
  160. }