<?php
namespace App\Entity;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\FileGroupRepository")
* @ORM\HasLifecycleCallbacks()
*/
class FileGroup
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="fileGroups")
* @ORM\JoinColumn(nullable=false)
**/
private $user;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\File", inversedBy="fileGroups")
* @ORM\JoinTable(name="file_group_file")
* joinColumns={
* @ORM\JoinColumn(name="file_group_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="file_id", referencedColumnName="id")
* }
*/
private $files;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $created;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Workspace", inversedBy="fileGroups")
*/
private $workspace;
/**
* FileGroup constructor.
*/
public function __construct()
{
$this->files = new ArrayCollection();
}
/**
* @return string|null
*/
public function __toString()
{
return ($this->getName() !== "" ? $this->getName() : (string)$this->getId());
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return DateTimeImmutable|null
*/
public function getCreated(): ?DateTimeImmutable
{
return $this->created;
}
/**
* @param DateTimeImmutable $created
* @return $this
*/
public function setCreated(DateTimeImmutable $created): self
{
$this->created = $created;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setCreatedValue()
{
$this->created = new DateTimeImmutable();
}
/**
* @return Collection|File[]
*/
public function getFiles(): Collection
{
return $this->files;
}
/**
* Set user
*
* @param User|null $user
* @return FileGroup
*/
public function setUser(?User $user = null): self
{
$this->user = $user;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
/**
* @param File $file
*/
public function addFile(File $file)
{
if ($this->files->contains($file)) {
return;
}
$this->files->add($file);
$file->addFileGroup($this);
}
public function removeFile(File $file)
{
if (!$this->files->contains($file)) {
return;
}
$this->files->removeElement($file);
$file->removeFileGroup($this);
}
/**
* @return mixed
*/
public function getWorkspace()
{
return $this->workspace;
}
/**
* @param mixed $workspace
*/
public function setWorkspace($workspace): void
{
$this->workspace = $workspace;
}
}