permission = FileWebPermission::PRIVATE; $this->lastModified = $this->updateLastModified(); $this->dateCreated = new \DateTime(); $this->guid = $this->generateToken(); $this->visible = true; $this->files = new ArrayCollection(); $this->folderOwners = new ArrayCollection(); $this->folderGroupPermission = new ArrayCollection(); $this->directories = new ArrayCollection(); } /** * @ORM\PrePersist * @ORM\PreUpdate */ public function prePersist(){ $this->updateLastModified(); } public function updateLastModified(){ $this->lastModified = new \DateTime(); return $this->lastModified; } /** * @param int $length * @return bool|string */ private function generateToken($length = 64){ $hash = ""; while(strlen($hash) < $length){ try { $hash .= hash('sha512', random_bytes($length)); } catch (\Exception $e) { $hash .= hash('sha512', mt_rand(0,$length*10000)); } } return substr($hash, 0,$length); } /** * use to change the pk if its not unique */ public function regenerateGuid(){ $this->guid = $this->generateToken(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): FolderItemInterface { $this->name = $name; return $this; } public function isVisible(): ?bool { return $this->visible; } public function setVisible(bool $visible): FolderItemInterface { $this->visible = $visible; return $this; } public function getDescription(): ?string { return $this->description; } public function setDescription(?string $description): FolderItemInterface { $this->description = $description; return $this; } public function getPermission(): ?int { return $this->permission; } public function setPermission(int $permission): FolderItemInterface { $this->permission = $permission; return $this; } public function getGuid(): ?string { return $this->guid; } public function setGuid(string $guid): FolderItemInterface { $this->guid = $guid; return $this; } public function getLastModified(): ?\DateTimeInterface { return $this->lastModified; } public function setLastModified(?\DateTimeInterface $lastModified): FolderItemInterface { $this->lastModified = $lastModified; return $this; } public function getDateCreated(): ?\DateTimeInterface { return $this->dateCreated; } public function setDateCreated(\DateTimeInterface $dateCreated): FolderItemInterface { $this->dateCreated = $dateCreated; return $this; } /** * @return Collection|FileItem[] */ public function getFiles(): Collection { return $this->files; } public function addFile(FileItem $file): FolderItemInterface { if (!$this->files->contains($file)) { $this->files[] = $file; $file->setParentFolder($this); } return $this; } public function removeFile(FileItem $file): FolderItemInterface { if ($this->files->contains($file)) { $this->files->removeElement($file); // set the owning side to null (unless already changed) if ($file->getParentFolder() === $this) { $file->setParentFolder(null); } } return $this; } /** * @return Collection|FolderOwner[] */ public function getFolderOwners(): Collection { return $this->folderOwners; } public function addFolderOwner(FolderOwner $folderOwner): FolderItemInterface { if (!$this->folderOwners->contains($folderOwner)) { $this->folderOwners[] = $folderOwner; $folderOwner->setFolder($this); } return $this; } public function removeFolderOwner(FolderOwner $folderOwner): FolderItemInterface { if ($this->folderOwners->contains($folderOwner)) { $this->folderOwners->removeElement($folderOwner); // set the owning side to null (unless already changed) if ($folderOwner->getFolder() === $this) { $folderOwner->setFolder(null); } } return $this; } /** * @return Collection|FolderGroupPermission[] */ public function getFolderGroupPermission(): Collection { return $this->folderGroupPermission; } public function addFolderGroupPermission(FolderGroupPermission $folderGroupPermission): FolderItemInterface { if (!$this->folderGroupPermission->contains($folderGroupPermission)) { $this->folderGroupPermission[] = $folderGroupPermission; $folderGroupPermission->setFolder($this); } return $this; } public function removeFolderGroupPermission(FolderGroupPermission $folderGroupPermission): FolderItemInterface { if ($this->folderGroupPermission->contains($folderGroupPermission)) { $this->folderGroupPermission->removeElement($folderGroupPermission); // set the owning side to null (unless already changed) if ($folderGroupPermission->getFolder() === $this) { $folderGroupPermission->setFolder(null); } } return $this; } /** * @return Collection|FolderItemInterface[] */ public function getDirectories(): Collection { return $this->directories; } public function addDirectory(?FolderItemInterface $directory): FolderItemInterface { if (!$this->directories->contains($directory)) { $this->directories[] = $directory; $directory->setParent($this); } return $this; } public function removeDirectory(?FolderItemInterface $directory): FolderItemInterface { if ($this->directories->contains($directory)) { $this->directories->removeElement($directory); // set the owning side to null (unless already changed) if ($directory->getParent() === $this) { $directory->setParent(null); } } return $this; } // public function getParent(): ?FolderItemInterface // { // return $this->parent; // } // // public function setParent(?FolderItemInterface $parent): self // { // $this->parent = $parent; // // return $this; // } }