<?php
namespace App\Entity;
use App\Entity\Stat\Report;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\HearingBrandRepository")
* @Vich\Uploadable
*/
class HearingBrand
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $type = "big_brand";
/**
* @ORM\Column(type="string", length=255)
* @Gedmo\Slug(fields={"name"})
*/
private $slug;
/**
* @ORM\Column(type="string", length=255)
*/
private $logoPath;
/**
* @assert\File( mimeTypes = {"image/jpeg", "image/png", "image/gif", "image/jpg"})
* @Vich\UploadableField(mapping="brand_logo", fileNameProperty="logoPath")
* @var File
*/
private $logoFile;
/**
* @Vich\UploadableField(mapping="brand_logo", fileNameProperty="logoVariationPath")
* @var File
*/
private $logoVariationFile;
/**
* @ORM\Column(type="string", length=255)
*/
private $logoVariationPath;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var DateTime
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phoneNumber;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $openingHours;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Store", mappedBy="hearingBrand")
*/
private $stores;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Stat\Report", mappedBy="brand")
*/
private $reports;
/**
* @ORM\Column(type="boolean")
*/
private $presentable = 0; // Logo présentable
/**
* @ORM\Column(type="text", nullable=true)
*/
private $wording;
/**
* indexable in file sitemap.xml
* @ORM\Column(type="boolean")
* @var boolean
*/
private $indexable = true;
public function __construct()
{
$this->stores = new ArrayCollection();
$this->reports = new ArrayCollection();
}
/**
* Représente l'entité par défault
* @return string
*/
public function __toString(){
return 'HearingBrand '.$this->getName().' ['.$this->getId().']';
}
/**
* Représente l'entité dans le BO
* @return string
*/
public function getLabel(){
return $this->getName();
}
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 getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection|HearingBrand[]
*/
public function getStores(): Collection
{
return $this->stores;
}
public function addStore(HearingBrand $store): self
{
if (!$this->stores->contains($store)) {
$this->stores[] = $store;
$store->setStore($this);
}
return $this;
}
public function removeStore(HearingBrand $store): self
{
if ($this->stores->contains($store)) {
$this->stores->removeElement($store);
// set the owning side to null (unless already changed)
if ($store->getStore() === $this) {
$store->setStore(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* @return mixed
*/
public function getReports()
{
return $this->reports;
}
/**
* @param mixed $reports
*/
public function setReports($reports): void
{
$this->reports = $reports;
}
public function getPresentable(): ?bool
{
return $this->presentable;
}
public function setPresentable(bool $presentable): self
{
$this->presentable = $presentable;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function addReport(Report $report): self
{
if (!$this->reports->contains($report)) {
$this->reports[] = $report;
$report->setBrand($this);
}
return $this;
}
public function removeReport(Report $report): self
{
if ($this->reports->contains($report)) {
$this->reports->removeElement($report);
// set the owning side to null (unless already changed)
if ($report->getBrand() === $this) {
$report->setBrand(null);
}
}
return $this;
}
public function getOpeningHours(): ?string
{
return $this->openingHours;
}
public function setOpeningHours(?string $openingHours): self
{
$this->openingHours = $openingHours;
return $this;
}
public function getLogoPath(): ?string
{
return $this->logoPath;
}
public function setLogoPath(string $logoPath=null): self
{
$this->logoPath = $logoPath;
return $this;
}
public function hasLogo(){
return !is_null($this->logoPath);
}
public function setLogoFile(File $image = null)
{
$this->logoFile = $image;
//update timestamp
if ($image) {
$this->updatedAt = new DateTime('now');
}
}
public function getLogoFile()
{
return $this->logoFile;
}
public function getLogoVariationPath(): ?string
{
return $this->logoVariationPath;
}
public function setLogoVariationPath(string $logoVariationPath=null): self
{
$this->logoVariationPath = $logoVariationPath;
return $this;
}
public function setLogoVariationFile(File $image = null)
{
$this->logoVariationFile = $image;
//update timestamp
if ($image) {
$this->updatedAt = new DateTime('now');
}
}
public function getLogoVariationFile()
{
return $this->logoVariationFile;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function isUpdated():bool
{
if($this->updatedAt !== NULL) {
if (date_diff($this->updatedAt, new \DateTime('now'))->days < 31) {
return true;
}
}
return false;
}
public function getWording(): ?string
{
return $this->wording;
}
public function setWording(?string $wording): self
{
$this->wording = $wording;
return $this;
}
public function getIndexable(): ?bool
{
return $this->indexable;
}
public function setIndexable(bool $indexable): self
{
$this->indexable = $indexable;
return $this;
}
}