<?php
namespace App\Entity;
use App\Repository\CountryRepository;
use Cocur\Slugify\Slugify;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=CountryRepository::class)
* @Vich\Uploadable
*/
class Country
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $position;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\OneToMany(targetEntity=Departement::class, mappedBy="country")
*/
private $departements;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $slug;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $topDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $bottomDescription;
/**
* @ORM\ManyToMany(targetEntity=Sejour::class, mappedBy="themes")
*/
private $sejours;
/**
* @ORM\Column(type="string", length=255)
*/
private $country;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $flag;
/**
* @Vich\UploadableField(mapping="frontend_image", fileNameProperty="flag")
*
* @var File|null
*/
private $flagFile;
public function __construct()
{
$this->departements = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $pos): self
{
$this->position = $pos;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $name): self
{
$this->title = $name;
$slugify = new Slugify();
$this->slug = $slugify->Slugify($name, '_');
return $this;
}
/**
* @return Collection|Departement[]
*/
public function getDepartements(): Collection
{
return $this->departements;
}
public function addDepartement(Departement $departement): self
{
if (!$this->departements->contains($departement)) {
$this->departements[] = $departement;
$departement->setCountry($this);
}
return $this;
}
public function removeDepartement(Departement $departement): self
{
if ($this->departements->removeElement($departement)) {
// set the owning side to null (unless already changed)
if ($departement->getCountry() === $this) {
$departement->setCountry(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getTopDescription(): ?string
{
return $this->topDescription;
}
public function setTopDescription(?string $topDescription): self
{
$this->topDescription = $topDescription;
return $this;
}
public function getBottomDescription(): ?string
{
return $this->bottomDescription;
}
public function setBottomDescription(?string $bottomDescription): self
{
$this->bottomDescription = $bottomDescription;
return $this;
}
/**
* @return Collection|Sejour[]
*/
public function getSejours(): Collection
{
return $this->sejours;
}
public function addSejour(Sejour $sejour): self
{
if (!$this->sejours->contains($sejour)) {
$this->sejours[] = $sejour;
$sejour->addCountry($this);
}
return $this;
}
public function removeSejour(Sejour $sejour): self
{
if ($this->sejours->removeElement($sejour)) {
$sejour->removeCountry($this);
}
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getFlag(): ?string
{
return $this->flag;
}
public function setFlag(?string $flag): self
{
$this->flag = $flag;
if ($flag !== null) {
$this->updatedDate = new \Datetime();
}
return $this;
}
public function getFlagFile(): ?File
{
return $this->flagFile;
}
public function setFlagFile(?File $flagFile): self
{
$this->flagFile = $flagFile;
if ($flagFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
}