318 lines
7.0 KiB
PHP
318 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Entity\Traits\BlameableEntity;
|
|
use App\Entity\Traits\TimestampableEntity;
|
|
use App\Model\UploadDto;
|
|
use App\Repository\UploadRepository;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
#[ORM\Entity(repositoryClass: UploadRepository::class)]
|
|
class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
|
{
|
|
use BlameableEntity;
|
|
use TimestampableEntity;
|
|
|
|
public const TYPE_PHOTO = 'photo';
|
|
public const TYPE_CERTIFICATE = 'certificate';
|
|
public const TYPE_CONTRACT = 'contract';
|
|
public const TYPE_INVOICE = 'invoice';
|
|
public const TYPE_DOCUMENT = 'document';
|
|
|
|
public const STATUS_NEW = 'new';
|
|
public const STATUS_PENDING = 'pending';
|
|
public const STATUS_CHECKED = 'checked';
|
|
public const STATUS_PAID = 'paid';
|
|
public const STATUS_REJECTED = 'rejected';
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\Column(length: 64)]
|
|
private ?string $type = null;
|
|
|
|
#[ORM\Column(length: 64, nullable: true)]
|
|
private ?string $status = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $filename = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $originalFilename = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
private ?string $displayName = null;
|
|
|
|
#[ORM\Column]
|
|
private ?int $size = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $mimeType = null;
|
|
|
|
#[ORM\ManyToOne]
|
|
private ?User $owner = null;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'documents')]
|
|
private ?Disposition $disposition = null;
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
private ?string $comment = null;
|
|
|
|
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
|
private ?\DateTimeImmutable $downloadedAt = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?string $downloadedBy = null;
|
|
|
|
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
|
private ?\DateTimeImmutable $approvedAt = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?string $approvedBy = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->uuid = Uuid::v4();
|
|
}
|
|
|
|
public static function fromUploadDto(UploadDto $uploadDto, User $owner, string $type, ?Upload $instance = null): static
|
|
{
|
|
$instance = $instance ?? new static();
|
|
$instance
|
|
->setFilename($uploadDto->getFilename())
|
|
->setOriginalFilename($uploadDto->getOriginalFilename())
|
|
->setMimeType($uploadDto->getMimeType())
|
|
->setSize($uploadDto->getSize())
|
|
->setOwner($owner)
|
|
->setType($type)
|
|
;
|
|
|
|
return $instance;
|
|
}
|
|
|
|
public function __toString()
|
|
{
|
|
return $this->getDisplayName() ?? $this->getOriginalFilename();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUuid(): string
|
|
{
|
|
return $this->uuid;
|
|
}
|
|
|
|
public function getType(): ?string
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
public function setType(string $type): static
|
|
{
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTypeLabel(): string
|
|
{
|
|
return match ($this->getType()) {
|
|
self::TYPE_PHOTO => 'Foto',
|
|
self::TYPE_CERTIFICATE => 'Lizenz',
|
|
self::TYPE_CONTRACT => 'Honorarvertrag',
|
|
self::TYPE_INVOICE => 'Honorarnote',
|
|
self::TYPE_DOCUMENT => 'Info',
|
|
default => 'Dokument',
|
|
};
|
|
}
|
|
|
|
public function getStatus(): ?string
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function setStatus(?string $status): static
|
|
{
|
|
$this->status = $status;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isConfirmed(): bool
|
|
{
|
|
return in_array($this->getStatus(), [static::STATUS_CHECKED, static::STATUS_PAID]);
|
|
}
|
|
|
|
public function isRejected(): bool
|
|
{
|
|
return static::STATUS_REJECTED === $this->getStatus();
|
|
}
|
|
|
|
public function getFilename(): ?string
|
|
{
|
|
return $this->filename;
|
|
}
|
|
|
|
public function setFilename(string $filename): static
|
|
{
|
|
$this->filename = $filename;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getOriginalFilename(): ?string
|
|
{
|
|
return $this->originalFilename;
|
|
}
|
|
|
|
public function setOriginalFilename(string $originalFilename): static
|
|
{
|
|
$this->originalFilename = $originalFilename;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDisplayName(): ?string
|
|
{
|
|
return $this->displayName;
|
|
}
|
|
|
|
public function setDisplayName(?string $displayName): static
|
|
{
|
|
$this->displayName = $displayName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSize(): ?int
|
|
{
|
|
return $this->size;
|
|
}
|
|
|
|
public function setSize(int $size): static
|
|
{
|
|
$this->size = $size;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMimeType(): ?string
|
|
{
|
|
return $this->mimeType;
|
|
}
|
|
|
|
public function setMimeType(string $mimeType): static
|
|
{
|
|
$this->mimeType = $mimeType;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getOwner(): ?User
|
|
{
|
|
return $this->owner;
|
|
}
|
|
|
|
public function setOwner(?User $owner): static
|
|
{
|
|
$this->owner = $owner;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDisposition(): ?Disposition
|
|
{
|
|
return $this->disposition;
|
|
}
|
|
|
|
public function setDisposition(?Disposition $disposition): static
|
|
{
|
|
$this->disposition = $disposition;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getComment(): ?string
|
|
{
|
|
return $this->comment;
|
|
}
|
|
|
|
public function setComment(?string $comment): static
|
|
{
|
|
$this->comment = $comment;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDownloadedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->downloadedAt;
|
|
}
|
|
|
|
public function setDownloadedAt(?\DateTimeImmutable $downloadedAt): static
|
|
{
|
|
$this->downloadedAt = $downloadedAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isDownloaded(): bool
|
|
{
|
|
return null !== $this->downloadedAt;
|
|
}
|
|
|
|
public function setDownloaded(): static
|
|
{
|
|
$this->downloadedAt = new \DateTimeImmutable();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDownloadedBy(): ?string
|
|
{
|
|
return $this->downloadedBy;
|
|
}
|
|
|
|
public function setDownloadedBy(?string $downloadedBy): static
|
|
{
|
|
$this->downloadedBy = $downloadedBy;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getApprovedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->approvedAt;
|
|
}
|
|
|
|
public function setApprovedAt(?\DateTimeImmutable $approvedAt): static
|
|
{
|
|
$this->approvedAt = $approvedAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getApprovedBy(): ?string
|
|
{
|
|
return $this->approvedBy;
|
|
}
|
|
|
|
public function setApprovedBy(?string $approvedBy): static
|
|
{
|
|
$this->approvedBy = $approvedBy;
|
|
|
|
return $this;
|
|
}
|
|
}
|