src/Entity/Media/Category.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Media;
  3. use App\Entity\Site\Site;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use App\Entity\Federation\Race;
  10. use Gedmo\Translatable\Translatable;
  11. use App\Form\Media\DocumentsType;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\Media\CategoryRepository")
  14.  * @ORM\Table(name="categories")
  15.  * @Gedmo\TranslationEntity(class="App\Entity\Translation\CategoryTranslation")
  16.  */
  17. class Category
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\Column(type="integer")
  22.      * @ORM\GeneratedValue(strategy="AUTO")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, nullable=true)
  27.      * @Assert\NotBlank()
  28.      * @Gedmo\Translatable
  29.      */
  30.     private $name "";
  31.     
  32.     /**
  33.      * @ORM\Column(type="string", length=255, nullable=true)
  34.      * @Assert\NotBlank()
  35.      */
  36.     private $code;
  37.     
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity="App\Entity\Media\Category", inversedBy="childrenCategories")
  40.      */
  41.     private $parentCategory;
  42.     
  43.     /**
  44.      * @ORM\OneToMany(targetEntity="App\Entity\Media\Category", mappedBy="parentCategory")
  45.      */
  46.     private $childrenCategories;
  47.     /**
  48.      * @ORM\Column(type="boolean", nullable=false, name="restrictive_category", options={"default":"0"})
  49.      */
  50.     private $restrictiveCategory false;
  51.     /**
  52.      * @ORM\Column(type="datetime", nullable=false, name="created_date")
  53.      * @Gedmo\Timestampable(on="create")
  54.      */
  55.     private $createdDate;
  56.     /**
  57.      * @ORM\Column(type="datetime", nullable=true, name="updated_date")
  58.      * @Gedmo\Timestampable(on="update")
  59.      */
  60.     private $updatedDate;
  61.     /**
  62.      * @ORM\Column(type="integer", nullable=false, name="status")
  63.      */
  64.     private $status 1;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity="App\Entity\Media\DocumentType", inversedBy="categories")
  67.      * @ORM\JoinColumn(name="document_type_id", referencedColumnName="id")
  68.      * @Assert\NotBlank()
  69.      */
  70.     private $documentType;
  71.     /**
  72.      * @ORM\ManyToMany(targetEntity="App\Entity\Media\Document", mappedBy="categories")
  73.      */
  74.     private $documents;
  75.     /**
  76.      * @ORM\ManyToMany(targetEntity="App\Entity\Federation\Race", inversedBy="categories")
  77.      * @ORM\JoinTable(
  78.      *     name="races_categories",
  79.      *     joinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id", nullable=false)},
  80.      *     inverseJoinColumns={@ORM\JoinColumn(name="race_id", referencedColumnName="id", nullable=false)}
  81.      * )
  82.      */
  83.     private $races;
  84.     /**
  85.      * @ORM\ManyToMany(targetEntity="App\Entity\Site\AccessSite", mappedBy="categories")
  86.      */
  87.     private $accessSites;
  88.     
  89.     /**
  90.      * @ORM\Column(type="integer", nullable=true, name="position")
  91.      */
  92.     private $position;
  93.     /**
  94.      * @Gedmo\Locale
  95.      */
  96.     private $locale
  97.     
  98.     public function __construct()
  99.     {
  100.         $this->documents = new ArrayCollection();
  101.         $this->sites = new ArrayCollection();
  102.         $this->races = new ArrayCollection();
  103.         $this->childrenCategories = new ArrayCollection();
  104.         $this->accessSites =new ArrayCollection();
  105.     }
  106.     public function getId(): ?int
  107.     {
  108.         return $this->id;
  109.     }
  110.     public function getName(): ?string
  111.     {
  112.         return $this->name;
  113.     }
  114.     public function setName(?string $name): self
  115.     {
  116.         $this->name $name;
  117.         return $this;
  118.     }
  119.     
  120.     public function getCode(): ?string
  121.     {
  122.         return $this->code;
  123.     }
  124.     
  125.     public function setCode(?string $code): self
  126.     {
  127.         $this->code $code;
  128.         
  129.         return $this;
  130.     }
  131.     public function getCreatedDate(): ?\DateTimeInterface
  132.     {
  133.         return $this->createdDate;
  134.     }
  135.    
  136.     public function getUpdatedDate(): ?\DateTimeInterface
  137.     {
  138.         return $this->updatedDate;
  139.     }
  140.     public function getStatus(): ?int
  141.     {
  142.         return $this->status;
  143.     }
  144.     public function setStatus(int $status): self
  145.     {
  146.         $this->status $status;
  147.         return $this;
  148.     }
  149.     
  150.     public function getPosition(): ?int
  151.     {
  152.         return $this->position;
  153.     }
  154.     public function setPosition(int $position): self
  155.     {
  156.         $this->position $position;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection|Document[]
  161.      */
  162.     public function getDocuments(): Collection
  163.     {
  164.         return $this->documents;
  165.     }
  166.     public function addDocument(Document $document): self
  167.     {
  168.         if (!$this->documents->contains($document)) {
  169.             $this->documents[] = $document;
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeDocument(Document $document): self
  174.     {
  175.         if ($this->documents->contains($document)) {
  176.             $this->documents->removeElement($document);
  177.         }
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return Collection|Race[]
  182.      */
  183.     public function getRaces(): Collection
  184.     {
  185.         return $this->races;
  186.     }
  187.     public function addRace(Race $race): self
  188.     {
  189.         if (!$this->races->contains($race)) {
  190.             $this->races[] = $race;
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeRace(Race $race): self
  195.     {
  196.         if ($this->races->contains($race)) {
  197.             $this->races->removeElement($race);
  198.         }
  199.         return $this;
  200.     }
  201.     public function getDocumentType(): ?DocumentType
  202.     {
  203.         return $this->documentType;
  204.     }
  205.     
  206.     public function setDocumentType(?DocumentType $documentType): self
  207.     {
  208.         $this->documentType $documentType;
  209.         
  210.         return $this;
  211.     }
  212.     
  213.     public function getParentCategory()
  214.     {
  215.         return $this->parentCategory;
  216.     }
  217.     
  218.     public function setParentCategory($parentCategory): self
  219.     {
  220.         $this->parentCategory $parentCategory;
  221.         
  222.         return $this;
  223.     }
  224.     
  225.     /**
  226.      * @return Collection|Category[]
  227.      */
  228.     public function getChildrenCategories(): Collection
  229.     {
  230.         return $this->childrenCategories;
  231.     }
  232.     
  233.     public function addChildrenCategories(Category $category): self
  234.     {
  235.         if (!$this->childrenCategories->contains($category)) {
  236.             $this->childrenCategories[] = $category;
  237.             $category->setParentCategory($this);
  238.         }
  239.         
  240.         return $this;
  241.     }
  242.     
  243.     public function removeChildrenCategories(Category $category): self
  244.     {
  245.         if ($this->childrenCategories->contains($category)) {
  246.             $this->childrenCategories->removeElement($category);
  247.             // set the owning side to null (unless already changed)
  248.             if ($category->getParentCategory() === $this) {
  249.                 $category->setParentCategory(null);
  250.             }
  251.         }
  252.         
  253.         return $this;
  254.     }
  255.     
  256.     public function setTranslatableLocale($locale)
  257.     {
  258.         $this->locale $locale;
  259.     }
  260.     public function isRestrictiveCategory(): bool
  261.     {
  262.         return $this->restrictiveCategory;
  263.     }
  264.     public function setRestrictiveCategory(bool $restrictiveCategory): self
  265.     {
  266.         $this->restrictiveCategory $restrictiveCategory;
  267.         return $this;
  268.     }
  269.     public function getAccessSites(): Collection
  270.     {
  271.         return $this->accessSites;
  272.     }
  273.     public function __toString(): string
  274.     {
  275.         if(empty($this->name))
  276.             return "";
  277.         return $this->name;
  278.     }
  279. }