<?php
namespace App\Entity\Otpusk;
use App\Entity\Stock\Stock;
use App\Repository\Otpusk\RubricRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=RubricRepository::class)
* @Vich\Uploadable()
*/
class Rubric implements TranslatableInterface
{
use TimestampableEntity;
use TranslatableTrait;
private $imgFolder = '/upload/rubric/';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=1024)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Vich\UploadableField(mapping="rubric", fileNameProperty="image")
*/
private $imageFile;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Otpusk\RubricCity", mappedBy="rubric", cascade={"persist"}, orphanRemoval=true)
*/
private $cities;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Otpusk\RubricCountry", mappedBy="rubric", cascade={"persist"}, orphanRemoval=true)
*/
private $countries;
private $citiesOutput;
public function __construct()
{
$this->countries = new ArrayCollection();
$this->cities = new ArrayCollection();
$this->updatedAt = new \DateTime();
}
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 getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return mixed
*/
public function getImage()
{
return $this->image;
}
/**
* @param mixed $image
*/
public function setImage($image): void
{
$this->image = $image;
}
public function getLinkImage()
{
return (!is_null($this->getImage())) ? $this->imgFolder.$this->getImage() : '#';
}
/**
* @return mixed
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param mixed $imageFile
*/
public function setImageFile($imageFile = null): void
{
$this->imageFile = $imageFile;
if ($imageFile) {
$this->updatedAt = new \DateTime();
}
}
public function __toString()
{
return $this->getName();
}
/**
* @return Collection|RubricCity[]
*/
public function getCities(): Collection
{
return $this->cities;
}
public function addCity(RubricCity $city): self
{
if (!$this->cities->contains($city)) {
$this->cities[] = $city;
$city->setRubric($this);
}
return $this;
}
public function removeCity(RubricCity $city): self
{
if ($this->cities->contains($city)) {
$this->cities->removeElement($city);
if ($city->getRubric() === $this) {
$city->setRubric(null);
}
}
return $this;
}
/**
* @return Collection|RubricCountry[]
*/
public function getCountries(): Collection
{
return $this->countries;
}
public function addCountry(RubricCountry $country): self
{
if (!$this->countries->contains($country)) {
$this->countries[] = $country;
$country->setRubric($this);
}
return $this;
}
public function removeCountry(RubricCountry $country): self
{
if ($this->countries->contains($country)) {
$this->countries->removeElement($country);
if ($country->getRubric() === $this) {
$country->setRubric(null);
}
}
return $this;
}
public function getCitiesOutput()
{
return $this->citiesOutput;
}
public function setCitiesOutput($citiesOutput): void
{
$this->citiesOutput = $citiesOutput;
}
}