<?php
namespace App\Entity;
use App\Entity\Application\Store;
use Cocur\Slugify\Slugify;
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\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Behaviors\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity(repositoryClass="App\Repository\BrandRepository")
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @UniqueEntity(fields={"name"}, message="Tato značka je již vytvořena!")
* @Vich\Uploadable()
*/
class Brand implements TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Assert\NotBlank()
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("brand")
* @ORM\Column(type="string", length=190, unique=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=190, unique=true)
*/
private $slug;
/**
* @Vich\UploadableField(mapping="brand_logo", fileNameProperty="image")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=199, nullable=true)
*/
private $image;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $groupBrands;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $createUser;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editts;
/**
* @ORM\Column(type="boolean")
*/
private $atHomePage = false;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $editUser;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="brand")
*/
private $products;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Application\Store", mappedBy="brands")
*/
private $stores;
public function __construct()
{
$this->stores = 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;
$this->setSlug(Slugify::create()->slugify($name));
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getCreatets(): ?\DateTimeInterface
{
return $this->createts;
}
public function setCreatets(\DateTimeInterface $createts): self
{
$this->createts = $createts;
return $this;
}
public function getCreateUser(): ?User
{
return $this->createUser;
}
public function setCreateUser(?User $createUser): self
{
$this->createUser = $createUser;
return $this;
}
public function getEditts(): ?\DateTimeInterface
{
return $this->editts;
}
public function setEditts(?\DateTimeInterface $editts): self
{
$this->editts = $editts;
return $this;
}
public function getEditUser(): ?User
{
return $this->editUser;
}
public function setEditUser(?User $editUser): self
{
$this->editUser = $editUser;
return $this;
}
public function __call($method, $arguments)
{
$ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
if(empty($ret)) {
$ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
}
return $ret;
}
/**
* Get ImageFile
*
* @return null|File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->editts = new \DateTime();
}
}
/**
* Get AtHomePage
*
* @return mixed
*/
public function getAtHomePage()
{
return $this->atHomePage;
}
/**
* Set AtHomePage
*
* @param mixed $atHomePage
*/
public function setAtHomePage( $atHomePage )
{
$this->atHomePage = $atHomePage;
}
/**
* Get Products
*
* @return mixed
*/
public function getProducts()
{
return $this->products;
}
/**
* Set Products
*
* @param mixed $products
*/
public function setProducts( $products )
{
$this->products = $products;
}
/**
* Get GroupBrands
*
* @return mixed
*/
public function getGroupBrands()
{
return $this->groupBrands;
}
/**
* Set GroupBrands
*
* @param mixed $groupBrands
*/
public function setGroupBrands( $groupBrands )
{
$this->groupBrands = $groupBrands;
}
/**
* @return Collection|Store[]
*/
public function getStores(): Collection
{
return $this->stores;
}
public function addStore(Store $store): self
{
if (!$this->stores->contains($store)) {
$this->stores[] = $store;
$store->addBrand($this);
}
return $this;
}
public function removeStore(Store $store): self
{
if ($this->stores->contains($store)) {
$this->stores->removeElement($store);
}
return $this;
}
}