<?php
namespace App\Entity\Media;
use App\Entity\Site\Site;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Federation\Race;
use Gedmo\Translatable\Translatable;
use App\Form\Media\DocumentsType;
/**
* @ORM\Entity(repositoryClass="App\Repository\Media\CategoryRepository")
* @ORM\Table(name="categories")
* @Gedmo\TranslationEntity(class="App\Entity\Translation\CategoryTranslation")
*/
class Category
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank()
* @Gedmo\Translatable
*/
private $name = "";
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank()
*/
private $code;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media\Category", inversedBy="childrenCategories")
*/
private $parentCategory;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Media\Category", mappedBy="parentCategory")
*/
private $childrenCategories;
/**
* @ORM\Column(type="boolean", nullable=false, name="restrictive_category", options={"default":"0"})
*/
private $restrictiveCategory = false;
/**
* @ORM\Column(type="datetime", nullable=false, name="created_date")
* @Gedmo\Timestampable(on="create")
*/
private $createdDate;
/**
* @ORM\Column(type="datetime", nullable=true, name="updated_date")
* @Gedmo\Timestampable(on="update")
*/
private $updatedDate;
/**
* @ORM\Column(type="integer", nullable=false, name="status")
*/
private $status = 1;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media\DocumentType", inversedBy="categories")
* @ORM\JoinColumn(name="document_type_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
private $documentType;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Media\Document", mappedBy="categories")
*/
private $documents;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Federation\Race", inversedBy="categories")
* @ORM\JoinTable(
* name="races_categories",
* joinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=false)},
* inverseJoinColumns={@ORM\JoinColumn(name="race_id", referencedColumnName="id", nullable=false)}
* )
*/
private $races;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Site\AccessSite", mappedBy="categories")
*/
private $accessSites;
/**
* @ORM\Column(type="integer", nullable=true, name="position")
*/
private $position;
/**
* @Gedmo\Locale
*/
private $locale;
public function __construct()
{
$this->documents = new ArrayCollection();
$this->sites = new ArrayCollection();
$this->races = new ArrayCollection();
$this->childrenCategories = new ArrayCollection();
$this->accessSites =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 getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getCreatedDate(): ?\DateTimeInterface
{
return $this->createdDate;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
}
return $this;
}
/**
* @return Collection|Race[]
*/
public function getRaces(): Collection
{
return $this->races;
}
public function addRace(Race $race): self
{
if (!$this->races->contains($race)) {
$this->races[] = $race;
}
return $this;
}
public function removeRace(Race $race): self
{
if ($this->races->contains($race)) {
$this->races->removeElement($race);
}
return $this;
}
public function getDocumentType(): ?DocumentType
{
return $this->documentType;
}
public function setDocumentType(?DocumentType $documentType): self
{
$this->documentType = $documentType;
return $this;
}
public function getParentCategory()
{
return $this->parentCategory;
}
public function setParentCategory($parentCategory): self
{
$this->parentCategory = $parentCategory;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getChildrenCategories(): Collection
{
return $this->childrenCategories;
}
public function addChildrenCategories(Category $category): self
{
if (!$this->childrenCategories->contains($category)) {
$this->childrenCategories[] = $category;
$category->setParentCategory($this);
}
return $this;
}
public function removeChildrenCategories(Category $category): self
{
if ($this->childrenCategories->contains($category)) {
$this->childrenCategories->removeElement($category);
// set the owning side to null (unless already changed)
if ($category->getParentCategory() === $this) {
$category->setParentCategory(null);
}
}
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function isRestrictiveCategory(): bool
{
return $this->restrictiveCategory;
}
public function setRestrictiveCategory(bool $restrictiveCategory): self
{
$this->restrictiveCategory = $restrictiveCategory;
return $this;
}
public function getAccessSites(): Collection
{
return $this->accessSites;
}
public function __toString(): string
{
if(empty($this->name))
return "";
return $this->name;
}
}