Skip to content

Commit

Permalink
Show publications catalogi & metadata as json objects instead of id
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Aug 12, 2024
1 parent 2f715e8 commit 8ae2428
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/Db/Listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function jsonSerialize(): array
'lastSync' => $this->lastSync->format('c'),
'default' => $this->default,
'available' => $this->available,
'organisation'=> $this->organisation,
'organisation'=> json_decode($this->organisation, true),
];

$jsonFields = $this->getJsonFields();
Expand Down
8 changes: 5 additions & 3 deletions lib/Db/ListingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,18 @@ public function createFromArray(array $object): Listing
$listing = new Listing();
$listing->hydrate(object: $object);

// var_dump($listing->getTitle());
$listing = $this->insert(entity: $listing);

return $this->insert(entity: $listing);
return $this->find($listing->getId());
}

public function updateFromArray(int $id, array $object): Listing
{
$listing = $this->find($id);
$listing->hydrate($object);

return $this->update($listing);
$listing = $this->update($listing);

return $this->find($listing->getId());
}
}
4 changes: 2 additions & 2 deletions lib/Db/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function jsonSerialize(): array
'image' => $this->image,
'category' => $this->category,
'portal' => $this->portal,
'catalogi' => $this->catalogi,
'metaData' => $this->metaData,
'catalogi' => json_decode($this->catalogi, true),
'metaData' => json_decode($this->metaData, true),
'published' => $this->published?->format('c'),
'modified' => $this->modified?->format('c'),
'featured' => $this->featured !== null ? (bool) $this->featured : null,
Expand Down
51 changes: 43 additions & 8 deletions lib/Db/PublicationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ public function find(int $id): Publication
'p.*',
'c.id AS catalogi_id',
'c.title AS catalogi_title',
'c.summary AS catalogi_summary',
'c.description AS catalogi_description',
'c.image AS catalogi_image',
'c.search AS catalogi_search',
'c.listed AS catalogi_listed',
'c.organisation AS catalogi_organisation',
'c.metadata AS catalogi_metadata',
'm.id AS metadata_id',
'm.title AS metadata_title'
'm.title AS metadata_title',
'm.version AS metadata_version',
'm.description AS metadata_description',
'm.required AS metadata_required',
'm.properties AS metadata_properties',
)
->from('publications', 'p')
->leftJoin('p', 'catalogi', 'c', 'p.catalogi = c.id')
->leftJoin('p', 'metadata', 'm', 'p.metaData = m.id')
->leftJoin('p', 'metadata', 'm', 'p.meta_data = m.id')
->where(
$qb->expr()->eq('p.id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
);
Expand Down Expand Up @@ -62,6 +73,13 @@ protected function mapRowToEntityCustom(array $row): Entity {
$catalogiData = [
'id' => $row['catalogi_id'] ?? null,
'title' => $row['catalogi_title'] ?? null,
'summary' => $row['catalogi_summary'] ?? null,
'description' => $row['catalogi_description'] ?? null,
'image' => $row['catalogi_image'] ?? null,
'search' => $row['catalogi_search'] ?? null,
'listed' => $row['catalogi_listed'] ?? null,
'organisation' => $row['catalogi_organisation'] ?? null,
'metadata' => $row['catalogi_metadata'] ?? null,
];

$catalogiIsEmpty = true;
Expand All @@ -79,6 +97,10 @@ protected function mapRowToEntityCustom(array $row): Entity {
$metaDataData = [
'id' => $row['metadata_id'] ?? null,
'title' => $row['metadata_title'] ?? null,
'version' => $row['metadata_version'] ?? null,
'description' => $row['metadata_description'] ?? null,
'required' => $row['metadata_required'] ?? null,
'properties' => $row['metadata_properties'] ?? null,
];

$metaDataIsEmpty = true;
Expand All @@ -93,7 +115,7 @@ protected function mapRowToEntityCustom(array $row): Entity {
}

$row['catalogi'] = $catalogiIsEmpty === true ? null : json_encode(Catalog::fromRow($catalogiData)->jsonSerialize());
$row['metadata'] = $catalogiIsEmpty === true ? null : json_encode(MetaData::fromRow($metaDataData)->jsonSerialize());
$row['metaData'] = $metaDataIsEmpty === true ? null : json_encode(MetaData::fromRow($metaDataData)->jsonSerialize());

return \call_user_func($this->entityClass .'::fromRow', $row);
}
Expand Down Expand Up @@ -198,12 +220,23 @@ public function findAll(?int $limit = null, ?int $offset = null, ?array $filters
'p.*',
'c.id AS catalogi_id',
'c.title AS catalogi_title',
'c.summary AS catalogi_summary',
'c.description AS catalogi_description',
'c.image AS catalogi_image',
'c.search AS catalogi_search',
'c.listed AS catalogi_listed',
'c.organisation AS catalogi_organisation',
'c.metadata AS catalogi_metadata',
'm.id AS metadata_id',
'm.title AS metadata_title'
'm.title AS metadata_title',
'm.version AS metadata_version',
'm.description AS metadata_description',
'm.required AS metadata_required',
'm.properties AS metadata_properties',
)
->from('publications', 'p')
->leftJoin('p', 'catalogi', 'c', 'p.catalogi = c.id')
->leftJoin('p', 'metadata', 'm', 'p.metaData = m.id')
->leftJoin('p', 'metadata', 'm', 'p.meta_data = m.id')
->setMaxResults($limit)
->setFirstResult($offset);

Expand Down Expand Up @@ -232,16 +265,18 @@ public function createFromArray(array $object): Publication
$publication = new Publication();
$publication->hydrate(object: $object);

// var_dump($publication->getTitle());
$publication = $this->insert(entity: $publication);

return $this->insert(entity: $publication);
return $this->find($publication->getId());
}

public function updateFromArray(int $id, array $object): Publication
{
$publication = $this->find(id: $id);
$publication->hydrate(object: $object);

return $this->update($publication);
$publication = $this->update($publication);

return $this->find($publication->getId());
}
}
6 changes: 3 additions & 3 deletions lib/Templates/publication.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Publicatie #{{ publication.title }}</h1>
{#<p>Catalogi: {{ publication.catalogi.title }}</p>#}
{#<p>Publicatie Type: {{ publication.metadata.title }}</p>#}
<h1>Publicatie {{ publication.title }}</h1>
<p>Catalogi: {{ publication.catalogi.title }}</p>
<p>Publicatie Type: {{ publication.metaData.title }}</p>
<p>Referentie: {{ publication.reference }}</p>
<p>Samenvatting: {{ publication.summary }}</p>
<p>Beschrijving: {{ publication.description }}</p>
Expand Down
12 changes: 6 additions & 6 deletions src/views/publications/PublicationDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ export default {
handler(newPublicationItem, oldPublicationItem) {
if (!this.upToDate || JSON.stringify(newPublicationItem) !== JSON.stringify(oldPublicationItem)) {
this.publication = publicationStore.publicationItem
this.fetchCatalogi(publicationStore.publicationItem.catalogi)
this.fetchMetaData(publicationStore.publicationItem.metaData)
this.fetchCatalogi(publicationStore.publicationItem.catalogi?.id)
this.fetchMetaData(publicationStore.publicationItem.metaData?.id)
publicationStore.publicationItem && this.fetchData(publicationStore.publicationItem.id)
}
},
Expand All @@ -460,8 +460,8 @@ export default {
this.publication = publicationStore.publicationItem
this.fetchCatalogi(publicationStore.publicationItem.catalogi, true)
this.fetchMetaData(publicationStore.publicationItem.metaData, true)
this.fetchCatalogi(publicationStore.publicationItem.catalogi?.id, true)
this.fetchMetaData(publicationStore.publicationItem.metaData?.id, true)
publicationStore.publicationItem && this.fetchData(publicationStore.publicationItem.id)
},
Expand All @@ -475,8 +475,8 @@ export default {
response.json().then((data) => {
this.publication = data
// this.oldZaakId = id
this.fetchCatalogi(data.catalogi)
this.fetchMetaData(data.metaData)
this.fetchCatalogi(data.catalogi?.id)
this.fetchMetaData(data.metaData?.id)
publicationStore.getPublicationAttachments()
// this.loading = false
})
Expand Down
2 changes: 1 addition & 1 deletion src/views/publications/PublicationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default {
filteredPublications() {
if (!publicationStore?.publicationList) return []
return publicationStore.publicationList.filter((publication) => {
return publication.catalogi.toString() === navigationStore.selectedCatalogus.toString()
return publication.catalogi?.id?.toString() === navigationStore.selectedCatalogus?.toString()
})
},
},
Expand Down

0 comments on commit 8ae2428

Please sign in to comment.