111 lines
2.3 KiB
PHP
111 lines
2.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
#[ORM\Entity]
|
|
class Document
|
|
{
|
|
public const STATUS_ACTIVE = 'ACTIVE';
|
|
public const STATUS_ARCHIVED = 'ARCHIVED';
|
|
|
|
#[ORM\Id]
|
|
#[ORM\Column(type: 'uuid', unique: true)]
|
|
private Uuid $id;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private string $title;
|
|
|
|
#[ORM\Column(length: 20)]
|
|
private string $status = self::STATUS_ACTIVE;
|
|
|
|
#[ORM\ManyToOne]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
private User $createdBy;
|
|
|
|
#[ORM\Column]
|
|
private \DateTimeImmutable $createdAt;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'document', targetEntity: DocumentVersion::class, cascade: ['persist'], orphanRemoval: true)]
|
|
private Collection $versions;
|
|
|
|
#[ORM\ManyToOne]
|
|
private ?DocumentVersion $currentVersion = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->id = Uuid::v4();
|
|
$this->createdAt = new \DateTimeImmutable();
|
|
$this->versions = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): Uuid
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getCreatedAt(): \DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function setTitle(string $title): static
|
|
{
|
|
$this->title = $title;
|
|
return $this;
|
|
}
|
|
|
|
|
|
public function getStatus(): string
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function archive(): void
|
|
{
|
|
$this->status = self::STATUS_ARCHIVED;
|
|
}
|
|
|
|
public function getCreatedBy(): User
|
|
{
|
|
return $this->createdBy;
|
|
}
|
|
|
|
public function setCreatedBy(User $user): static
|
|
{
|
|
$this->createdBy = $user;
|
|
return $this;
|
|
}
|
|
|
|
public function getVersions(): Collection
|
|
{
|
|
return $this->versions;
|
|
}
|
|
|
|
public function addVersion(DocumentVersion $version): void
|
|
{
|
|
$this->versions->add($version);
|
|
$version->setDocument($this);
|
|
}
|
|
|
|
public function setCurrentVersion(?DocumentVersion $version): void
|
|
{
|
|
$this->currentVersion = $version;
|
|
}
|
|
|
|
public function getCurrentVersion(): ?DocumentVersion
|
|
{
|
|
return $this->currentVersion;
|
|
}
|
|
}
|