diff --git a/api/migrations/Version20230907115512.php b/api/migrations/Version20230907115512.php new file mode 100644 index 000000000..5735ba4dd --- /dev/null +++ b/api/migrations/Version20230907115512.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE template ADD version VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE template ALTER organization_id DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE template DROP version'); + $this->addSql('ALTER TABLE template ALTER organization_id SET NOT NULL'); + } +} diff --git a/api/src/Controller/ZZController.php b/api/src/Controller/ZZController.php index e011301c3..a39f51227 100644 --- a/api/src/Controller/ZZController.php +++ b/api/src/Controller/ZZController.php @@ -161,6 +161,8 @@ private function getAcceptType(Request $request): string return 'xml'; case 'text/html': return 'html'; + case 'text/docx': + return 'docx'; }//end switch throw new BadRequestHttpException('No proper accept could be determined'); diff --git a/api/src/Entity/Template.php b/api/src/Entity/Template.php index f4f372fa9..a400d7a1a 100644 --- a/api/src/Entity/Template.php +++ b/api/src/Entity/Template.php @@ -111,7 +111,7 @@ class Template * * @ORM\ManyToOne(targetEntity=Organization::class, inversedBy="templates") * - * @ORM\JoinColumn(nullable=false) + * @ORM\JoinColumn(nullable=true) */ private ?Organization $organization = null; @@ -122,7 +122,21 @@ class Template * * @ORM\Column(type="array") */ - private $supportedSchemas = []; + private array $supportedSchemas = []; + + /** + * @Groups({"read", "write"}) + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private ?string $reference = null; + + /** + * @Groups({"read", "write"}) + * + * @ORM\Column(type="string", length=255, nullable=true) + */ + private ?string $version = null; /** * @var Datetime|null The moment this resource was created @@ -146,29 +160,74 @@ class Template */ private ?DateTime $dateModified = null; + /** - * @Groups({"read", "write"}) + * Constructor for creating an Template. + * + * @param array|null $configuration A configuration array used to correctly create a Template. The following keys are supported: * - * @ORM\Column(type="string", length=255, nullable=true, options={"default": null}) */ - private ?string $reference = null; + public function __construct(?array $configuration = []) + { + if ($configuration) { + $this->fromSchema($configuration); + } + } - public function __construct(array $data) { - if (isset($data['organization']) === true) { - $this->setOrganization($data['organization']); + /** + * Uses given $configuration array to set the properties of this Template. + * + * @param array $schema The schema to load. + * + * @return void + */ + public function fromSchema(array $schema) + { + if (key_exists('$id', $schema) === true) { + $this->setReference($schema['$id']); } - if (isset($data['name']) === true) { - $this->setName($data['name']); + if (key_exists('version', $schema) === true) { + $this->setVersion($schema['version']); } - if (isset($data['content']) === true) { - $this->setContent($data['content']); + + if (key_exists('name', $schema) === true) { + $this->setName($schema['name']); } - if (isset($data['description'])) { - $this->setDescription($data['description']); + + if (key_exists('description', $schema) === true) { + $this->setDescription($schema['description']); } - if (isset($data['supportedSchemas']) === true) { - $this->setSupportedSchemas($data['supportedSchemas']); + + if (key_exists('content', $schema) === true) { + $this->setContent($schema['content']); } + + if (key_exists('organization', $schema) === true) { + $this->setOrganization($schema['organization']); + } + + if (key_exists('supportedSchemas', $schema) === true) { + $this->setSupportedSchemas($schema['supportedSchemas']); + } + } + + /** + * Convert this Template to a schema. + * + * @return array Schema array. + */ + public function toSchema(): array + { + return [ + '$id' => $this->getReference(), //@todo dit zou een interne uri verwijzing moeten zijn maar hebben we nog niet + '$schema' => 'https://docs.commongateway.nl/schemas/Template.schema.json', + 'name' => $this->getName(), + 'description' => $this->getDescription(), + 'content' => $this->getContent(), + 'version' => $this->getVersion(), + 'organization' => $this->getOrganization(), + 'supportedSchemas' => $this->getSupportedSchemas(), + ]; } public function setId(UuidInterface $id): self @@ -243,38 +302,50 @@ public function setSupportedSchemas(array $supportedSchemas): self return $this; } - public function getDateCreated(): ?\DateTimeInterface + public function getReference(): ?string { - return $this->dateCreated; + return $this->reference; } - public function setDateCreated(?\DateTimeInterface $dateCreated): self + public function setReference(?string $reference): self { - $this->dateCreated = $dateCreated; + $this->reference = $reference; return $this; } - public function getDateModified(): ?\DateTimeInterface + public function getVersion(): ?string { - return $this->dateModified; + return $this->version; } - public function setDateModified(?\DateTimeInterface $dateModified): self + public function setVersion(?string $version): self { - $this->dateModified = $dateModified; + $this->version = $version; return $this; } - public function getReference(): ?string + public function getDateCreated(): ?\DateTimeInterface { - return $this->reference; + return $this->dateCreated; } - public function setReference(?string $reference): self + public function setDateCreated(?\DateTimeInterface $dateCreated): self { - $this->reference = $reference; + $this->dateCreated = $dateCreated; + + return $this; + } + + public function getDateModified(): ?\DateTimeInterface + { + return $this->dateModified; + } + + public function setDateModified(?\DateTimeInterface $dateModified): self + { + $this->dateModified = $dateModified; return $this; }