src/Entity/Address.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Annotation\SiteAware;
  4. use App\Entity\Interfaces\SiteInterface;
  5. use App\Entity\Traits\SiteTrait;
  6. use App\Repository\AddressRepository;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. /**
  10.  * @ORM\Table(name="vulco_address", indexes={@ORM\Index(name="address_site_idx", columns={"site"})})
  11.  *
  12.  * @ORM\Entity(repositoryClass=AddressRepository::class)
  13.  *
  14.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  15.  *
  16.  * @SiteAware(siteFieldName="site")
  17.  */
  18. class Address extends AbstractBase implements SiteInterface
  19. {
  20.     use SiteTrait;
  21.     /**
  22.      * @ORM\Column(type="string", length=255, nullable=false)
  23.      */
  24.     private string $street1;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, nullable=true)
  27.      */
  28.     private ?string $street2 null;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private ?string $number null;
  33.     /**
  34.      * @ORM\Column(type="string", length=255, nullable=false)
  35.      */
  36.     private string $locality;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      */
  40.     private ?string $zone null;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=false)
  43.      */
  44.     private string $zipCode;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      */
  48.     private ?string $lat null;
  49.     /**
  50.      * @ORM\Column(type="string", length=255, nullable=true)
  51.      */
  52.     private ?string $lon null;
  53.     /**
  54.      * @ORM\Column(type="boolean", nullable=true, options={"default": 0})
  55.      */
  56.     private ?bool $showInSite false;
  57.     /**
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private ?string $phone null;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      */
  64.     private ?string $mobile null;
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private ?string $fax null;
  69.     /**
  70.      * @ORM\Column(type="string", length=255, nullable=true)
  71.      */
  72.     private ?string $email null;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      */
  76.     private ?string $timetableMorning null;
  77.     /**
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private ?string $timetableAfternoon null;
  81.     /**
  82.      * @ORM\Column(type="string", length=255, nullable=true)
  83.      */
  84.     private ?string $timetableSaturday null;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity="App\Entity\Province", fetch="EAGER")
  87.      */
  88.     private ?Province $province null;
  89.     public function __clone() {
  90.         if ($this->id) {
  91.             if (!is_null($this->province)) {
  92.                 $this->province = clone $this->province;
  93.             }
  94.         }
  95.     }
  96.     public function getStreet1(): string
  97.     {
  98.         return $this->street1;
  99.     }
  100.     public function setStreet1(string $street1): self
  101.     {
  102.         $this->street1 $street1;
  103.         return $this;
  104.     }
  105.     public function getStreet2(): ?string
  106.     {
  107.         return $this->street2;
  108.     }
  109.     public function setStreet2(?string $street2): self
  110.     {
  111.         $this->street2 $street2;
  112.         return $this;
  113.     }
  114.     public function getNumber(): ?string
  115.     {
  116.         return $this->number;
  117.     }
  118.     public function setNumber(?string $number): self
  119.     {
  120.         $this->number $number;
  121.         return $this;
  122.     }
  123.     public function getLocality(): string
  124.     {
  125.         return $this->locality;
  126.     }
  127.     public function setLocality(string $locality): self
  128.     {
  129.         $this->locality $locality;
  130.         return $this;
  131.     }
  132.     public function getZone(): ?string
  133.     {
  134.         return $this->zone;
  135.     }
  136.     public function setZone(?string $zone): self
  137.     {
  138.         $this->zone $zone;
  139.         return $this;
  140.     }
  141.     public function getZipCode(): string
  142.     {
  143.         return $this->zipCode;
  144.     }
  145.     public function setZipCode(string $zipCode): self
  146.     {
  147.         $this->zipCode $zipCode;
  148.         return $this;
  149.     }
  150.     public function getShortPrintableString(): string
  151.     {
  152.         return $this->getStreet1().', '.$this->getNumber().' ('.$this->getZipCode().' '.$this->getLocality().')';
  153.     }
  154.     public function getLongPrintableString(): string
  155.     {
  156.         $str$this->getStreet1();
  157.         if ($this->getStreet2()) {
  158.             $str.= ', '.$this->getStreet2();
  159.         }
  160.         return $str.', '.$this->getNumber().', '.$this->getZipCode().' '.$this->getLocality();
  161.     }
  162.     public function getLat(): ?float
  163.     {
  164.         return (float) $this->lat;
  165.     }
  166.     public function setLat(?string $lat): self
  167.     {
  168.         $this->lat $lat;
  169.         return $this;
  170.     }
  171.     public function getLon(): ?float
  172.     {
  173.         return (float) $this->lon;
  174.     }
  175.     public function setLon(?string $lon): self
  176.     {
  177.         $this->lon $lon;
  178.         return $this;
  179.     }
  180.     public function getLatLng(): array
  181.     {
  182.         return [
  183.             'latitude' => $this->getLat(),
  184.             'longitude' => $this->getLon(),
  185.         ];
  186.     }
  187.     public function setLatLng(array $latlng): self
  188.     {
  189.         if (array_key_exists('latitude'$latlng) && array_key_exists('longitude'$latlng)) {
  190.             $this->setLat($latlng['latitude']);
  191.             $this->setLon($latlng['longitude']);
  192.         }
  193.         return $this;
  194.     }
  195.     public function getShowInSite(): ?bool
  196.     {
  197.         return $this->showInSite;
  198.     }
  199.     public function setShowInSite(?bool $showInSite): self
  200.     {
  201.         $this->showInSite $showInSite;
  202.         return $this;
  203.     }
  204.     public function getPhone(): ?string
  205.     {
  206.         return $this->phone;
  207.     }
  208.     public function setPhone(?string $phone): self
  209.     {
  210.         $this->phone $phone;
  211.         return $this;
  212.     }
  213.     public function getMobile(): ?string
  214.     {
  215.         return $this->mobile;
  216.     }
  217.     public function setMobile(?string $mobile): self
  218.     {
  219.         $this->mobile $mobile;
  220.         return $this;
  221.     }
  222.     public function getFax(): ?string
  223.     {
  224.         return $this->fax;
  225.     }
  226.     public function setFax(?string $fax): self
  227.     {
  228.         $this->fax $fax;
  229.         return $this;
  230.     }
  231.     public function getEmail(): ?string
  232.     {
  233.         return $this->email;
  234.     }
  235.     public function setEmail(?string $email): self
  236.     {
  237.         $this->email $email;
  238.         return $this;
  239.     }
  240.     public function getTimetableMorning(): ?string
  241.     {
  242.         return $this->timetableMorning;
  243.     }
  244.     public function setTimetableMorning(?string $timetableMorning): self
  245.     {
  246.         $this->timetableMorning $timetableMorning;
  247.         return $this;
  248.     }
  249.     public function getTimetableAfternoon(): ?string
  250.     {
  251.         return $this->timetableAfternoon;
  252.     }
  253.     public function setTimetableAfternoon(?string $timetableAfternoon): self
  254.     {
  255.         $this->timetableAfternoon $timetableAfternoon;
  256.         return $this;
  257.     }
  258.     public function getTimetableSaturday(): ?string
  259.     {
  260.         return $this->timetableSaturday;
  261.     }
  262.     public function setTimetableSaturday(?string $timetableSaturday): self
  263.     {
  264.         $this->timetableSaturday $timetableSaturday;
  265.         return $this;
  266.     }
  267.     public function getProvince(): ?Province
  268.     {
  269.         return $this->province;
  270.     }
  271.     public function setProvince(?Province $province): self
  272.     {
  273.         $this->province $province;
  274.         return $this;
  275.     }
  276.     
  277.     public function diff(Address $address): array
  278.     {
  279.         $diff = array();
  280.         if ($this->street1 !== $address->street1) {
  281.             $diff[] = ['address.street_1'$this->street1];
  282.         }
  283.         if ($this->street2 !== $address->street2) {
  284.             $diff[] = ['address.street_2'$this->street2];
  285.         }
  286.         if ($this->number !== $address->number) {
  287.             $diff[] = ['address.number'$this->number];
  288.         }
  289.         if ($this->zipCode !== $address->zipCode) {
  290.             $diff[] = ['address.zip_code'$this->zipCode];
  291.         }
  292.         if ($this->locality !== $address->locality) {
  293.             $diff[] = ['address.locality'$this->locality];
  294.         }
  295.         if ($this->zone !== $address->zone) {
  296.             $diff[] = ['address.zone'$this->zone];
  297.         }
  298.         if ($this->getProvince()) {
  299.             if ($address->getProvince()) {
  300.                 if ($this->getProvince()->diff($address->getProvince())) {
  301.                     $diff[] = ['address.province'$this->getProvince()->getName()];
  302.                 }
  303.             }
  304.         }
  305.         return $diff;
  306.     }
  307.     public function displayRawFields(): array
  308.     {
  309.         $fields = array();
  310.         if ($this->street1) {
  311.             $fields[] = ['address.street_1'$this->street1];
  312.         }
  313.         if ($this->street2) {
  314.             $fields[] = ['address.street_2'$this->street2];
  315.         }
  316.         if ($this->number) {
  317.             $fields[] = ['address.number'$this->number];
  318.         }
  319.         if ($this->zipCode) {
  320.             $fields[] = ['address.zip_code'$this->zipCode];
  321.         }
  322.         if ($this->locality) {
  323.             $fields[] = ['address.locality'$this->locality];
  324.         }
  325.         if ($this->zone) {
  326.             $fields[] = ['address.zone'$this->zone];
  327.         }
  328.         if ($this->getProvince()) {
  329.             $fields[] = ['address.province'$this->getProvince()->getName()];
  330.         }
  331.         return $fields;
  332.     }
  333. }