Feature: [docgen] create a service to generate a document from a template

This commit is contained in:
2023-02-14 19:35:28 +01:00
parent eac3471cbb
commit bb05ba0f17
8 changed files with 415 additions and 17 deletions

View File

@@ -14,6 +14,9 @@ namespace Chill\DocStoreBundle\Entity;
use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
use ChampsLibres\WopiLib\Contract\Entity\Document;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
@@ -30,8 +33,14 @@ use Symfony\Component\Serializer\Annotation as Serializer;
* message="The file is not stored properly"
* )
*/
class StoredObject implements AsyncFileInterface, Document
class StoredObject implements AsyncFileInterface, Document, TrackCreationInterface
{
public const STATUS_READY = "ready";
public const STATUS_PENDING = "pending";
public const STATUS_FAILURE = "failure";
use TrackCreationTrait;
/**
* @ORM\Column(type="datetime", name="creation_date")
* @Serializer\Groups({"read", "write"})
@@ -48,7 +57,7 @@ class StoredObject implements AsyncFileInterface, Document
* @ORM\Column(type="text")
* @Serializer\Groups({"read", "write"})
*/
private $filename;
private string $filename = '';
/**
* @ORM\Id
@@ -56,7 +65,7 @@ class StoredObject implements AsyncFileInterface, Document
* @ORM\Column(type="integer")
* @Serializer\Groups({"read", "write"})
*/
private $id;
private ?int $id;
/**
* @var int[]
@@ -89,28 +98,44 @@ class StoredObject implements AsyncFileInterface, Document
*/
private UuidInterface $uuid;
public function __construct()
/**
* @ORM\ManyToOne(targetEntity=DocGeneratorTemplate::class)
*/
private ?DocGeneratorTemplate $template;
/**
* @ORM\Column(type="text", options={"default": "ready"})
*/
private string $status;
/**
* @param StoredObject::STATUS_* $status
*/
public function __construct(string $status = "ready")
{
$this->creationDate = new DateTime();
$this->uuid = Uuid::uuid4();
$this->status = $status;
}
/**
* @Serializer\Groups({"read", "write"})
*/
public function getCreationDate(): DateTime
{
return $this->creationDate;
return DateTime::createFromImmutable($this->createdAt);
}
public function getDatas()
public function getDatas(): array
{
return $this->datas;
}
public function getFilename()
public function getFilename(): string
{
return $this->filename;
}
public function getId()
public function getId(): ?int
{
return $this->id;
}
@@ -133,6 +158,11 @@ class StoredObject implements AsyncFileInterface, Document
return $this->getFilename();
}
public function getStatus(): string
{
return $this->status;
}
public function getTitle()
{
return $this->title;
@@ -153,49 +183,62 @@ class StoredObject implements AsyncFileInterface, Document
return (string) $this->uuid;
}
public function setCreationDate(DateTime $creationDate)
/**
* @Serializer\Groups({"write"})
*/
public function setCreationDate(DateTime $creationDate): self
{
$this->creationDate = $creationDate;
$this->createdAt = \DateTimeImmutable::createFromMutable($creationDate);
return $this;
}
public function setDatas(?array $datas)
public function setDatas(?array $datas): self
{
$this->datas = (array) $datas;
return $this;
}
public function setFilename(?string $filename)
public function setFilename(?string $filename): self
{
$this->filename = (string) $filename;
return $this;
}
public function setIv(?array $iv)
public function setIv(?array $iv): self
{
$this->iv = (array) $iv;
return $this;
}
public function setKeyInfos(?array $keyInfos)
public function setKeyInfos(?array $keyInfos): self
{
$this->keyInfos = (array) $keyInfos;
return $this;
}
public function setTitle(?string $title)
/**
* @param StoredObject::STATUS_* $status
*/
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function setTitle(?string $title): self
{
$this->title = (string) $title;
return $this;
}
public function setType(?string $type)
public function setType(?string $type): self
{
$this->type = (string) $type;