Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix template and added text/docx to getAcceptType #1550

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/migrations/Version20230907115512.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230907115512 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
2 changes: 2 additions & 0 deletions api/src/Controller/ZZController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
127 changes: 99 additions & 28 deletions api/src/Entity/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Loading