<?php
namespace App\Entity;
use App\Annotation\SiteAware;
use App\Entity\Interfaces\SiteInterface;
use App\Entity\Traits\SiteTrait;
use App\Repository\AddressRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(name="vulco_address", indexes={@ORM\Index(name="address_site_idx", columns={"site"})})
*
* @ORM\Entity(repositoryClass=AddressRepository::class)
*
* @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
*
* @SiteAware(siteFieldName="site")
*/
class Address extends AbstractBase implements SiteInterface
{
use SiteTrait;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private string $street1;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $street2 = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $number = null;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private string $locality;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $zone = null;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private string $zipCode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $lat = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $lon = null;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": 0})
*/
private ?bool $showInSite = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $phone = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $mobile = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $fax = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $email = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $timetableMorning = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $timetableAfternoon = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $timetableSaturday = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Province", fetch="EAGER")
*/
private ?Province $province = null;
public function __clone() {
if ($this->id) {
if (!is_null($this->province)) {
$this->province = clone $this->province;
}
}
}
public function getStreet1(): string
{
return $this->street1;
}
public function setStreet1(string $street1): self
{
$this->street1 = $street1;
return $this;
}
public function getStreet2(): ?string
{
return $this->street2;
}
public function setStreet2(?string $street2): self
{
$this->street2 = $street2;
return $this;
}
public function getNumber(): ?string
{
return $this->number;
}
public function setNumber(?string $number): self
{
$this->number = $number;
return $this;
}
public function getLocality(): string
{
return $this->locality;
}
public function setLocality(string $locality): self
{
$this->locality = $locality;
return $this;
}
public function getZone(): ?string
{
return $this->zone;
}
public function setZone(?string $zone): self
{
$this->zone = $zone;
return $this;
}
public function getZipCode(): string
{
return $this->zipCode;
}
public function setZipCode(string $zipCode): self
{
$this->zipCode = $zipCode;
return $this;
}
public function getShortPrintableString(): string
{
return $this->getStreet1().', '.$this->getNumber().' ('.$this->getZipCode().' '.$this->getLocality().')';
}
public function getLongPrintableString(): string
{
$str= $this->getStreet1();
if ($this->getStreet2()) {
$str.= ', '.$this->getStreet2();
}
return $str.', '.$this->getNumber().', '.$this->getZipCode().' '.$this->getLocality();
}
public function getLat(): ?float
{
return (float) $this->lat;
}
public function setLat(?string $lat): self
{
$this->lat = $lat;
return $this;
}
public function getLon(): ?float
{
return (float) $this->lon;
}
public function setLon(?string $lon): self
{
$this->lon = $lon;
return $this;
}
public function getLatLng(): array
{
return [
'latitude' => $this->getLat(),
'longitude' => $this->getLon(),
];
}
public function setLatLng(array $latlng): self
{
if (array_key_exists('latitude', $latlng) && array_key_exists('longitude', $latlng)) {
$this->setLat($latlng['latitude']);
$this->setLon($latlng['longitude']);
}
return $this;
}
public function getShowInSite(): ?bool
{
return $this->showInSite;
}
public function setShowInSite(?bool $showInSite): self
{
$this->showInSite = $showInSite;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getFax(): ?string
{
return $this->fax;
}
public function setFax(?string $fax): self
{
$this->fax = $fax;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getTimetableMorning(): ?string
{
return $this->timetableMorning;
}
public function setTimetableMorning(?string $timetableMorning): self
{
$this->timetableMorning = $timetableMorning;
return $this;
}
public function getTimetableAfternoon(): ?string
{
return $this->timetableAfternoon;
}
public function setTimetableAfternoon(?string $timetableAfternoon): self
{
$this->timetableAfternoon = $timetableAfternoon;
return $this;
}
public function getTimetableSaturday(): ?string
{
return $this->timetableSaturday;
}
public function setTimetableSaturday(?string $timetableSaturday): self
{
$this->timetableSaturday = $timetableSaturday;
return $this;
}
public function getProvince(): ?Province
{
return $this->province;
}
public function setProvince(?Province $province): self
{
$this->province = $province;
return $this;
}
public function diff(Address $address): array
{
$diff = array();
if ($this->street1 !== $address->street1) {
$diff[] = ['address.street_1', $this->street1];
}
if ($this->street2 !== $address->street2) {
$diff[] = ['address.street_2', $this->street2];
}
if ($this->number !== $address->number) {
$diff[] = ['address.number', $this->number];
}
if ($this->zipCode !== $address->zipCode) {
$diff[] = ['address.zip_code', $this->zipCode];
}
if ($this->locality !== $address->locality) {
$diff[] = ['address.locality', $this->locality];
}
if ($this->zone !== $address->zone) {
$diff[] = ['address.zone', $this->zone];
}
if ($this->getProvince()) {
if ($address->getProvince()) {
if ($this->getProvince()->diff($address->getProvince())) {
$diff[] = ['address.province', $this->getProvince()->getName()];
}
}
}
return $diff;
}
public function displayRawFields(): array
{
$fields = array();
if ($this->street1) {
$fields[] = ['address.street_1', $this->street1];
}
if ($this->street2) {
$fields[] = ['address.street_2', $this->street2];
}
if ($this->number) {
$fields[] = ['address.number', $this->number];
}
if ($this->zipCode) {
$fields[] = ['address.zip_code', $this->zipCode];
}
if ($this->locality) {
$fields[] = ['address.locality', $this->locality];
}
if ($this->zone) {
$fields[] = ['address.zone', $this->zone];
}
if ($this->getProvince()) {
$fields[] = ['address.province', $this->getProvince()->getName()];
}
return $fields;
}
}