src/Entity/FileGroup.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTimeImmutable;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\FileGroupRepository")
  9.  * @ORM\HasLifecycleCallbacks()
  10.  */
  11. class FileGroup
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="fileGroups")
  25.      * @ORM\JoinColumn(nullable=false)
  26.      **/
  27.     private $user;
  28.     /**
  29.      * @ORM\ManyToMany(targetEntity="App\Entity\File", inversedBy="fileGroups")
  30.      * @ORM\JoinTable(name="file_group_file")
  31.      *  joinColumns={
  32.      * @ORM\JoinColumn(name="file_group_id", referencedColumnName="id")
  33.      *  },
  34.      *  inverseJoinColumns={
  35.      * @ORM\JoinColumn(name="file_id", referencedColumnName="id")
  36.      *  }
  37.      */
  38.     private $files;
  39.     /**
  40.      * @ORM\Column(type="datetime_immutable")
  41.      */
  42.     private $created;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity="App\Entity\Workspace", inversedBy="fileGroups")
  45.      */
  46.     private $workspace;
  47.     /**
  48.      * FileGroup constructor.
  49.      */
  50.     public function __construct()
  51.     {
  52.         $this->files = new ArrayCollection();
  53.     }
  54.     /**
  55.      * @return string|null
  56.      */
  57.     public function __toString()
  58.     {
  59.         return ($this->getName() !== "" $this->getName() : (string)$this->getId());
  60.     }
  61.     /**
  62.      * @return int
  63.      */
  64.     public function getId(): int
  65.     {
  66.         return $this->id;
  67.     }
  68.     /**
  69.      * @return string
  70.      */
  71.     public function getName(): ?string
  72.     {
  73.         return $this->name;
  74.     }
  75.     /**
  76.      * @param string $name
  77.      * @return $this
  78.      */
  79.     public function setName(string $name): self
  80.     {
  81.         $this->name $name;
  82.         return $this;
  83.     }
  84.     /**
  85.      * @return DateTimeImmutable|null
  86.      */
  87.     public function getCreated(): ?DateTimeImmutable
  88.     {
  89.         return $this->created;
  90.     }
  91.     /**
  92.      * @param DateTimeImmutable $created
  93.      * @return $this
  94.      */
  95.     public function setCreated(DateTimeImmutable $created): self
  96.     {
  97.         $this->created $created;
  98.         return $this;
  99.     }
  100.     /**
  101.      * @ORM\PrePersist
  102.      */
  103.     public function setCreatedValue()
  104.     {
  105.         $this->created = new DateTimeImmutable();
  106.     }
  107.     /**
  108.      * @return Collection|File[]
  109.      */
  110.     public function getFiles(): Collection
  111.     {
  112.         return $this->files;
  113.     }
  114.     /**
  115.      * Set user
  116.      *
  117.      * @param User|null $user
  118.      * @return FileGroup
  119.      */
  120.     public function setUser(?User $user null): self
  121.     {
  122.         $this->user $user;
  123.         return $this;
  124.     }
  125.     public function getUser(): ?User
  126.     {
  127.         return $this->user;
  128.     }
  129.     /**
  130.      * @param File $file
  131.      */
  132.     public function addFile(File $file)
  133.     {
  134.         if ($this->files->contains($file)) {
  135.             return;
  136.         }
  137.         $this->files->add($file);
  138.         $file->addFileGroup($this);
  139.     }
  140.     public function removeFile(File $file)
  141.     {
  142.         if (!$this->files->contains($file)) {
  143.             return;
  144.         }
  145.         $this->files->removeElement($file);
  146.         $file->removeFileGroup($this);
  147.     }
  148.     /**
  149.      * @return mixed
  150.      */
  151.     public function getWorkspace()
  152.     {
  153.         return $this->workspace;
  154.     }
  155.     /**
  156.      * @param mixed $workspace
  157.      */
  158.     public function setWorkspace($workspace): void
  159.     {
  160.         $this->workspace $workspace;
  161.     }
  162. }