src/Entity/Folder.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\EntityTrait;
  4. use App\Repository\FolderRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=FolderRepository::class)
  10.  */
  11. class Folder
  12. {
  13.     use EntityTrait{
  14.         EntityTrait::__construct as private __entityConstruct;
  15.     }
  16.     /**
  17.      * @ORM\Column(type="string", length=255)
  18.      */
  19.     private $name;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity=Folder::class)
  22.      */
  23.     private $folder_parent;
  24.     /**
  25.      * @ORM\OneToMany(targetEntity=Document::class, mappedBy="folder")
  26.      */
  27.     private $documents;
  28.     public function __construct()
  29.     {
  30.         $this->__entityConstruct();
  31.         $this->documents = new ArrayCollection();
  32.     }
  33.     public function getName(): ?string
  34.     {
  35.         return $this->name;
  36.     }
  37.     public function setName(string $name): self
  38.     {
  39.         $this->name $name;
  40.         return $this;
  41.     }
  42.     public function getFolderParent(): ?self
  43.     {
  44.         return $this->folder_parent;
  45.     }
  46.     public function setFolderParent(?self $folder_parent): self
  47.     {
  48.         $this->folder_parent $folder_parent;
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return Collection|Document[]
  53.      */
  54.     public function getDocuments(): Collection
  55.     {
  56.         return $this->documents;
  57.     }
  58.     public function addDocument(Document $document): self
  59.     {
  60.         if (!$this->documents->contains($document)) {
  61.             $this->documents[] = $document;
  62.             $document->setFolder($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function removeDocument(Document $document): self
  67.     {
  68.         if ($this->documents->removeElement($document)) {
  69.             // set the owning side to null (unless already changed)
  70.             if ($document->getFolder() === $this) {
  71.                 $document->setFolder(null);
  72.             }
  73.         }
  74.         return $this;
  75.     }
  76.     public function __toString(){
  77.         $string '';
  78.         if($this->getFolderParent() != null){
  79.             $string .= $this->getFolderParent()->__toString().' - ';
  80.         }
  81.         $string .= $this->name;
  82.         return $string;
  83.     }
  84. }