<?phpnamespace App\Entity;use App\Entity\Common\LibraryVoterInterface;use App\Entity\Common\ResourceFolderInterface;use App\Entity\Traits\FolderTrait;use App\Repository\WorkroomFolderRepository;use App\Security\Voter\Library\WorkroomLibraryVoter;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: WorkroomFolderRepository::class)]#[ORM\HasLifecycleCallbacks]class WorkroomFolder implements LibraryVoterInterface, ResourceFolderInterface{ use FolderTrait; #[ORM\OneToMany(targetEntity: WorkroomResource::class, mappedBy: 'workroomFolder')] private $workroomResources; #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'personalFolders')] private $user; #[ORM\ManyToOne(targetEntity: Workroom::class, inversedBy: 'workroomFolders')] private $workroom; #[ORM\OneToMany(targetEntity: WorkroomFolder::class, mappedBy: 'parent')] protected $children; #[ORM\ManyToOne(targetEntity: WorkroomFolder::class, inversedBy: 'children')] #[ORM\JoinColumn(name: 'parent', referencedColumnName: 'id', onDelete: 'CASCADE')] private $parent; public function __construct() { $this->workroomResources = new ArrayCollection(); $this->children = new ArrayCollection(); } /** * @return Collection|WorkroomResource[] */ public function getWorkroomResources(): Collection { return $this->workroomResources; } public function addWorkroomResource(WorkroomResource $workroomResource): self { if (!$this->workroomResources->contains($workroomResource)) { $this->workroomResources[] = $workroomResource; $workroomResource->setWorkroomFolder($this); } return $this; } public function removeWorkroomResource(WorkroomResource $workroomResource): self { if ($this->workroomResources->removeElement($workroomResource)) { // set the owning side to null (unless already changed) if ($workroomResource->getWorkroomFolder() === $this) { $workroomResource->setWorkroomFolder(null); } } return $this; } public function getUser(): ?User { return $this->user; } public function setUser(?User $user): self { $this->user = $user; return $this; } public function getWorkroom(): ?Workroom { return $this->workroom; } public function setWorkroom(?Workroom $workroom): self { $this->workroom = $workroom; return $this; } /** * {@inheritdoc} */ public function getLibraryVoter(): string { return WorkroomLibraryVoter::class; } /** * {@inheritdoc} */ public function getResources(): ?array { return $this->workroomResources->toArray(); } public function getParent(): ?self { return $this->parent; } public function setParent(?self $parent): self { $this->parent = $parent; return $this; } public function getChildren(): Collection { return $this->children; } public function hasChildren(): bool { return count($this->children) > 0 ? true : false; }}