Skip to content

Commit

Permalink
Replace hardcoded VGW URLs with linked_art_json [API-285]
Browse files Browse the repository at this point in the history
  • Loading branch information
IllyaMoskvin committed Mar 31, 2022
1 parent e324dbb commit 8c861f0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 53 deletions.
64 changes: 11 additions & 53 deletions app/Http/Controllers/LinkedArtController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@

class LinkedArtController extends BaseController
{
private $fnumbers = [
28560 => 'F484',
80607 => 'F345',
14586 => 'F470',
28862 => 'F139',
79349 => 'F667',
109314 => 'F354',
27949 => 'F506',
27954 => 'F272',
64957 => 'F382',
52733 => 'F1468',
59774 => 'F1069',
31640 => 'F1240a',
65479 => 'F1642',
87327 => 'F1524',
150802 => 'F1690',
133605 => 'F1518',
88393 => null,
202382 => 'F1241',
];

public function showObject(Request $request, $id)
{
$artwork = Artwork::find($id);
Expand All @@ -45,7 +24,6 @@ public function showObject(Request $request, $id)
$item = array_merge_recursive(
$item,
$this->getArtworkType($artwork),
$this->getLinkToVgwUri($artwork),
$this->getIdentifiers($artwork),
$this->getTitles($artwork),
$this->getCurrentOwner($artwork),
Expand All @@ -61,6 +39,7 @@ public function showObject(Request $request, $id)
$this->getProvenanceStatement($artwork),
$this->getBibliographyStatement($artwork),
$this->getExhibitionStatement($artwork),
$this->getExtraLinkedArtJson($artwork),
);

return $item;
Expand All @@ -87,23 +66,6 @@ private function getArtworkType($artwork): array
];
}

private function getLinkToVgwUri($artwork): array
{
$fnumber = $this->fnumbers[$artwork->getKey()] ?? null;

if (!$fnumber) {
return [];
}

return [
'see_also' => [
[
'id' => 'https://vangoghworldwide.org/data/artwork/' . $fnumber,
],
],
];
}

private function getIdentifiers($artwork): array
{
$identifiers = [];
Expand All @@ -122,20 +84,6 @@ private function getIdentifiers($artwork): array
];
}

if ($fnumber = $this->fnumbers[$artwork->getKey()] ?? null) {
$identifiers[] = [
'type' => 'Identifier',
'content' => $fnumber,
'classified_as' => [
[
'id' => 'https://vangoghworldwide.org/data/concept/f_number',
'type' => 'Type',
'_label' => 'De La Faille number',
],
],
];
}

if (empty($identifiers)) {
return [];
}
Expand Down Expand Up @@ -598,4 +546,14 @@ private function getExhibitionStatement($artwork): array
],
];
}

private function getExtraLinkedArtJson($artwork): array
{
if (empty($artwork->linked_art_json)) {
return [];
}

// convert object to array recursively
return json_decode(json_encode($artwork->linked_art_json), true);
}
}
1 change: 1 addition & 0 deletions app/Models/Collections/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Artwork extends CollectionsModel
'is_public_domain' => 'boolean',
'is_zoomable' => 'boolean',
'is_on_view' => 'boolean',
'linked_art_json' => 'object',
];

protected $primaryKey = 'citi_id';
Expand Down
1 change: 1 addition & 0 deletions app/Transformers/Inbound/Enhancer/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected function getExtraFields(Datum $datum)
'support_aat_id' => $datum->support_aat_id,
'dimension_width' => $datum->width,
'dimension_height' => $datum->height,
'linked_art_json' => $datum->linked_art_json,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddLinkedArtJsonToArtworks extends Migration
{
public function up()
{
Schema::table('artworks', function (Blueprint $table) {
$table->json('linked_art_json')->nullable()->after('provenance');

});
}

public function down()
{
Schema::table('artworks', function (Blueprint $table) {
$table->dropColumn('linked_art_json');
});
}
}

0 comments on commit 8c861f0

Please sign in to comment.