src/Entity/Document.php line 13
<?phpnamespace App\Entity;use App\Entity\Document\Block;use App\Repository\DocumentRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: DocumentRepository::class)]class Document{const TYPE_WEB = 0;const TYPE_DOCX = 1;const STATUS_DRAFT=0;const STATUS_ON_PROGRESS=1;const STATUS_FINALIZED=2;const STATUSES = [self::STATUS_DRAFT => "Draft",self::STATUS_ON_PROGRESS => "On progress",self::STATUS_FINALIZED => "Finalized"];#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 255)]private ?string $title = null;#[ORM\Column(type: Types::TEXT, nullable: true)]private ?string $description = null;#[ORM\Column(type: Types::TEXT, nullable: true)]private ?string $tags = null;#[ORM\ManyToOne(inversedBy: 'docs')]private ?User $owner = null;#[ORM\Column(nullable: true)]private ?bool $isTemplate = null;#[ORM\ManyToOne(targetEntity: self::class)]private ?self $sourceTemplate = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?\DateTimeInterface $dateCreated = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?\DateTimeInterface $dateUpdated = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?\DateTimeInterface $version = null;#[ORM\ManyToOne(targetEntity: self::class)]private ?self $versionOf = null;#[ORM\Column]private ?int $type = null;/* web specific attributes */#[ORM\OneToMany(mappedBy: 'document', targetEntity: Block::class)]#[ORM\OrderBy(["blockorder" => "ASC"])]private Collection $blocks;/* docx specific attributes */#[ORM\ManyToOne]private ?File $file = null;#[ORM\OneToMany(mappedBy: 'document', targetEntity: DocumentPermission::class, orphanRemoval: true)]private Collection $documentPermissions;#[ORM\Column]private ?int $status = 0;#[ORM\Column]private ?bool $isLastVersion = null;public function __construct(){$this->blocks = new ArrayCollection();$this->documentPermissions = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getTitle(): ?string{return $this->title;}public function setTitle(string $title): self{$this->title = $title;return $this;}public function getDescription(): ?string{return $this->description;}public function setDescription(?string $description): self{$this->description = $description;return $this;}public function getTags(): ?string{return $this->tags;}public function setTags(?string $tags): self{$this->tags = $tags;return $this;}public function getOwner(): ?User{return $this->owner;}public function setOwner(?User $owner): self{$this->owner = $owner;return $this;}public function isIsTemplate(): ?bool{return $this->isTemplate;}public function setIsTemplate(?bool $isTemplate): self{$this->isTemplate = $isTemplate;return $this;}public function getSourceTemplate(): ?self{return $this->sourceTemplate;}public function setSourceTemplate(?self $sourceTemplate): self{$this->sourceTemplate = $sourceTemplate;return $this;}public function getDateCreated(): ?\DateTimeInterface{return $this->dateCreated;}public function setDateCreated(\DateTimeInterface $dateCreated): self{$this->dateCreated = $dateCreated;return $this;}public function getDateUpdated(): ?\DateTimeInterface{return $this->dateUpdated;}public function setDateUpdated(\DateTimeInterface $dateUpdated): self{$this->dateUpdated = $dateUpdated;return $this;}public function getVersion(): ?\DateTimeInterface{return $this->version;}public function setVersion(\DateTimeInterface $version): self{$this->version = $version;return $this;}public function getVersionOf(): ?self{return $this->versionOf;}public function setVersionOf(?self $versionOf): self{$this->versionOf = $versionOf;return $this;}public function getType(): ?int{return $this->type;}public function getTypeToString(){$strType = $this->type == Document::TYPE_WEB ? "Web" : "";$strType = $this->type == Document::TYPE_DOCX ? "Docx" : $strType;return $strType;}public function typeIsWeb(){return $this->type == Document::TYPE_WEB;}public function setType(int $type): self{$this->type = $type;return $this;}/*** @return Collection<int, Block>*/public function getBlocks(): Collection{return $this->blocks;}public function addBlock(Block $block): self{if (!$this->blocks->contains($block)) {$this->blocks->add($block);$block->setDocument($this);}return $this;}public function removeBlock(Block $block): self{if ($this->blocks->removeElement($block)) {// set the owning side to null (unless already changed)if ($block->getDocument() === $this) {$block->setDocument(null);}}return $this;}public function getFile(): ?File{return $this->file;}public function setFile(?File $file): self{$this->file = $file;return $this;}public static function clone(Document $source){$document = new Document();$document->setTags($source->getTags());$document->setDescription($source->getDescription());$document->setTitle($source->getTitle());$document->setOwner($source->getOwner());foreach($source->getBlocks() as $block)$document->addBlock(Block::clone($block));return $document;}public function getNextBlockId() {if(count($this->getBlocks()) == 0)return 1;$ids = [];/** @var Block $block */foreach($this->getBlocks() as $block)array_push($ids, $block->getIdInDoc());sort($ids);return ($ids[count($ids) - 1]) + 1;}/*** @return Collection<int, DocumentPermission>*/public function getDocumentPermissions(): Collection{return $this->documentPermissions;}public function addDocumentPermission(DocumentPermission $documentPermission): self{if (!$this->documentPermissions->contains($documentPermission)) {$this->documentPermissions->add($documentPermission);$documentPermission->setDocument($this);}return $this;}public function removeDocumentPermission(DocumentPermission $documentPermission): self{if ($this->documentPermissions->removeElement($documentPermission)) {// set the owning side to null (unless already changed)if ($documentPermission->getDocument() === $this) {$documentPermission->setDocument(null);}}return $this;}public function allows(User $user) {/** @var DocumentPermission $p */foreach($this->documentPermissions as $p){if($p->getUser() === $user)return true;}return false;}public function getStatus(): ?int{return $this->status;}public function setStatus(int $status): self{$this->status = $status;return $this;}public function toArray(){return ["id" => $this->getId(),"tags" => $this->getTags(),"description" => $this->getDescription(),"title" => $this->getTitle(),];}public function isIsLastVersion(): ?bool{return $this->isLastVersion;}public function setIsLastVersion(bool $isLastVersion){$this->isLastVersion = $isLastVersion;return $this;}}