<?php
namespace App\Entity;
use App\Repository\ProviderRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ProviderRepository::class)]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: "dtype", type: "string")]
#[ORM\DiscriminatorMap(['hotel' => Hotel::class , 'hotelchain' => HotelChain::class, 'other' => OtherProvider::class])]
#[UniqueEntity(['name'])]
class Provider
{
// use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 128)]
#[Assert\NotBlank(message: 'This value should not be blank')]
#[Assert\Length(max: 128)]
#[Assert\Regex(
pattern: '/^[\p{L}\p{M}\s\'\-_&]+$/u',
)]
private ?string $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $address;
#[ORM\Column(type: 'decimal', precision: 16, scale: 12, nullable: true)]
private ?string $longitude;
#[ORM\Column(type: 'decimal', precision: 16, scale: 12, nullable: true)]
private ?string $latitude;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $email;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $website;
#[ORM\Column(type: 'string', length: 32, nullable: true)]
private ?string $phone;
#[ORM\Column(type: 'string', length: 32, nullable: true)]
private ?string $fax;
#[ORM\Column(type: 'string', length: 64, nullable: true)]
private ?string $rib;
#[ORM\Column(type: 'boolean')]
private bool $active;
#[ORM\ManyToOne(targetEntity: City::class)]
private ?City $city;
#[ORM\OneToMany(mappedBy: 'provider', targetEntity: FileData::class, cascade: ['persist'])]
private $images;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
private ?FileData $logo = null;
#[ORM\Column(length: 3)]
private ?string $currency = null;
public function __construct()
{
$this->images = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getLongitude(): ?string
{
return $this->longitude;
}
public function setLongitude(?string $longitude): self
{
$this->longitude = $longitude;
return $this;
}
public function getLatitude(): ?string
{
return $this->latitude;
}
public function setLatitude(?string $latitude): self
{
$this->latitude = $latitude;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): self
{
$this->website = $website;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getFax(): ?string
{
return $this->fax;
}
public function setFax(?string $fax): self
{
$this->fax = $fax;
return $this;
}
public function getRib(): ?string
{
return $this->rib;
}
public function setRib(?string $rib): self
{
$this->rib = $rib;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getCity(): ?City
{
return $this->city;
}
public function setCity(?City $city): self
{
$this->city = $city;
return $this;
}
public function __toString(): string
{
return $this->name;
}
/**
* @return Collection<int, FileData>
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(FileData $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
$image->setProvider($this);
}
return $this;
}
public function removeImage(FileData $image): self
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getProvider() === $this) {
$image->setProvider(null);
}
}
return $this;
}
public function getPrimaryImageUrl(): ?string
{
foreach ($this->images as $image){
if($image->getDisplayOrder()==1){
return $image->getUrl();
}
}
return null;
}
public function getLogo(): ?FileData
{
return $this->logo;
}
public function setLogo(?FileData $logo): self
{
$this->logo = $logo;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
}