From 72279a285dceb813caf8ff8994517554c3a664d7 Mon Sep 17 00:00:00 2001 From: Charlie Butcosk Date: Fri, 12 Jul 2024 14:30:51 -0400 Subject: [PATCH] Clean up linting, switch and order fig layer annotations on fig options --- .../Commands/MigrateOSCIPublicationOne.php | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/app/Console/Commands/MigrateOSCIPublicationOne.php b/app/Console/Commands/MigrateOSCIPublicationOne.php index 4bf86fa95..697b23750 100644 --- a/app/Console/Commands/MigrateOSCIPublicationOne.php +++ b/app/Console/Commands/MigrateOSCIPublicationOne.php @@ -13,7 +13,6 @@ use App\Models\Vendor\Block; use A17\Twill\Models\Media; - class MigrateOSCIPublicationOne extends Command { /** @@ -90,7 +89,7 @@ private function mediaFactory($imageData, $caption_html, $fallback_url) private function configureFigBlock($figure, $block) { - $layers = isset($figure->layers_data) ? json_decode($figure->layers_data) : []; + $layers = isset($figure->layers_data) ? json_decode($figure->layers_data, true) : []; switch (true) { // Non-video embeds (HTML, mostly) become media_embed @@ -166,42 +165,43 @@ private function configureFigBlock($figure, $block) $block->save(); + $figure_opts = json_decode($figure->figure_opts, true); + + $imageLayerIds = $figure_opts->baseLayerPreset ?? []; + $overlayLayerIds = $figure_opts->annotationPreset ?? []; + foreach ($layers as $imageData) { // Each layer (image or overview) is a child block of the layered image viewer block, so: // - Create media record + move the asset (if not moved already) // - Configure a layer block for this layer (image or overview) // - Attach it to the layer viewer block + $layer_id = $imageData; + $media = $this->mediaFactory($imageData, $figure->caption_html, $figure->fallback_url); $layerBlock = new Block(); $layerBlock->blockable_id = $block->blockable_id; $layerBlock->blockable_type = 'digitalPublicationArticles'; - $layerBlock->position = 1; $layerBlock->parent_id = $block->id; - // TODO: Use $figure->$options->baseLayerPreset and $figure->$options->annotationPreset to determine the order and kind of this layer - - // OSCI doesn't expose overlay vs image data so parse the URL filename - $imageUrl = isset($imageData->static_url) ? $imageData->static_url : $figure->fallback_url ; - $imageUrlPath = parse_url($imageUrl, PHP_URL_PATH); - $imageExt = pathinfo($imageUrlPath, PATHINFO_EXTENSION); - - switch ($imageExt) { - case 'svg': - $layerBlock->child_key = 'layered_image_viewer_overlay'; - $layerBlock->type = 'layered_image_viewer_overlay'; - break; - - default: - $layerBlock->child_key = 'layered_image_viewer_img'; - $layerBlock->type = 'layered_image_viewer_img'; - break; + // Configure this as an image or overlay and set position + if (in_array($imageData['layer_id'], $imageLayerIds)) { + $layerBlock->position = array_search($imageData['layer_id'], $imageLayerIds) + 1; + $layerBlock->child_key = 'layered_image_viewer_img'; + $layerBlock->type = 'layered_image_viewer_img'; + } else if (in_array($imageData['layer_id'], $overlayLayerIds)) { + $layerBlock->position = array_search($imageData['layer_id'], $overlayLayerIds) + 1; + $layerBlock->child_key = 'layered_image_viewer_overlay'; + $layerBlock->type = 'layered_image_viewer_overlay'; + } else { + $layerBlock->position = 1; + $layerBlock->child_key = 'layered_image_viewer_img'; + $layerBlock->type = 'layered_image_viewer_img'; } - $layerBlock->content = [ - "label" => $imageData->title + "label" => $imageData['title'] ]; $layerBlock->save(); @@ -316,7 +316,7 @@ public function handle() // NB!: For each of these types in the admin UI it's impossible to validate the save without setting a date! // Fetch this publication's title by its package name (eg, `caillebotte`) - // TODO: Handle italics / etc in the title + // TODO: webPub->header_title_display = italicized OSCI title // TODO: Set publication date metadata $pubs = DB::connection('osci_migration')->select("SELECT json_extract(publications.data,'$._title') as title FROM publications LEFT JOIN tocs ON tocs.package=publications.pub_id WHERE pub_id=:id", ['id' => $pubId]); @@ -341,8 +341,9 @@ public function handle() // TODO: Add `toc_position`, `toc_parent` via json_tree against toc data $blockQuery = <<