From 82715dfe63e41c3de9285147f11aff7f4e90ff2a Mon Sep 17 00:00:00 2001 From: mlnkng Date: Fri, 9 Feb 2024 14:46:29 -0800 Subject: [PATCH] Fix GUI CSV export for translations. (#1750) --- .../translationLinksComponent.class.php | 82 +++++++++++-------- .../arInformationObjectCsvExportJob.class.php | 20 +++-- 2 files changed, 62 insertions(+), 40 deletions(-) diff --git a/apps/qubit/modules/default/actions/translationLinksComponent.class.php b/apps/qubit/modules/default/actions/translationLinksComponent.class.php index 240de5cc07..c1f1684920 100644 --- a/apps/qubit/modules/default/actions/translationLinksComponent.class.php +++ b/apps/qubit/modules/default/actions/translationLinksComponent.class.php @@ -1,5 +1,7 @@ getUser()->getCulture(); @@ -26,103 +32,113 @@ public function execute($request) switch (get_class($this->resource)) { case 'QubitInformationObject': $this->module = 'informationobject'; - $i18ns = $this->resource->informationObjectI18ns; - $propertyName = 'title'; - $sourceCultureProperty = $this->resource->getTitle(['sourceCulture' => true]); + $this->i18ns = $this->resource->informationObjectI18ns; + $this->propertyName = 'title'; + $this->sourceCultureProperty = $this->resource->getTitle(['sourceCulture' => true]); break; case 'QubitActor': $this->module = 'actor'; - $i18ns = $this->resource->actorI18ns; - $propertyName = 'authorizedFormOfName'; - $sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); + $this->i18ns = $this->resource->actorI18ns; + $this->propertyName = 'authorizedFormOfName'; + $this->sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); break; case 'QubitRepository': $this->module = 'repository'; - $i18ns = $this->resource->actorI18ns; - $propertyName = 'authorizedFormOfName'; - $sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); + $this->i18ns = $this->resource->actorI18ns; + $this->propertyName = 'authorizedFormOfName'; + $this->sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); break; case 'QubitAccession': $this->module = 'accession'; - $i18ns = $this->resource->accessionI18ns; - $sourceCultureProperty = $this->resource->identifier; + $this->i18ns = $this->resource->accessionI18ns; + $this->sourceCultureProperty = $this->resource->identifier; break; case 'QubitDeaccession': $this->module = 'deaccession'; - $i18ns = $this->resource->deaccessionI18ns; - $sourceCultureProperty = $this->resource->identifier; + $this->i18ns = $this->resource->deaccessionI18ns; + $this->sourceCultureProperty = $this->resource->identifier; break; case 'QubitDonor': $this->module = 'donor'; - $i18ns = $this->resource->actorI18ns; - $propertyName = 'authorizedFormOfName'; - $sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); + $this->i18ns = $this->resource->actorI18ns; + $this->propertyName = 'authorizedFormOfName'; + $this->sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); break; case 'QubitFunctionObject': $this->module = 'function'; - $i18ns = $this->resource->functionObjectI18ns; - $propertyName = 'authorizedFormOfName'; - $sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); + $this->i18ns = $this->resource->functionObjectI18ns; + $this->propertyName = 'authorizedFormOfName'; + $this->sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); break; case 'QubitPhysicalObject': $this->module = 'physicalobject'; - $i18ns = $this->resource->physicalObjectI18ns; - $propertyName = 'name'; - $sourceCultureProperty = $this->resource->getName(['sourceCulture' => true]); + $this->i18ns = $this->resource->physicalObjectI18ns; + $this->propertyName = 'name'; + $this->sourceCultureProperty = $this->resource->getName(['sourceCulture' => true]); break; case 'QubitRightsHolder': $this->module = 'rightsholder'; - $i18ns = $this->resource->actorI18ns; - $propertyName = 'authorizedFormOfName'; - $sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); + $this->i18ns = $this->resource->actorI18ns; + $this->propertyName = 'authorizedFormOfName'; + $this->sourceCultureProperty = $this->resource->getAuthorizedFormOfName(['sourceCulture' => true]); break; case 'QubitTerm': $this->module = 'term'; - $i18ns = $this->resource->termI18ns; - $propertyName = 'name'; - $sourceCultureProperty = $this->resource->getName(['sourceCulture' => true]); + $this->i18ns = $this->resource->termI18ns; + $this->propertyName = 'name'; + $this->sourceCultureProperty = $this->resource->getName(['sourceCulture' => true]); break; } // Return nothing if the resource only has the current culture - if (1 == count($i18ns) && $i18ns[0]->culture == $currentCulture) { + if (1 == count($this->i18ns) && $this->i18ns[0]->culture == $currentCulture) { return sfView::NONE; } - // Get other cultures available - $this->translations = []; - foreach ($i18ns as $i18n) { + $this->translations = self::getOtherCulturesAvailable($this->i18ns, $this->propertyName, $this->sourceCultureProperty); + + foreach ($this->i18ns as $i18n) { if ($i18n->culture == $currentCulture) { continue; } + } + } + + public static function getOtherCulturesAvailable($i18ns, $propertyName, $sourceCultureProperty) + { + // Get other cultures available + $translations = []; + foreach ($i18ns as $i18n) { $name = isset($propertyName) && isset($i18n->{$propertyName}) ? $i18n->{$propertyName} : $sourceCultureProperty; $langCode = $i18n->culture; $langName = format_language($langCode); - $this->translations[$langCode] = [ + $translations[$langCode] = [ 'name' => $name, 'language' => ucfirst($langName), ]; } + + return $translations; } } diff --git a/lib/job/arInformationObjectCsvExportJob.class.php b/lib/job/arInformationObjectCsvExportJob.class.php index ea01ec36f2..eeb5217b64 100644 --- a/lib/job/arInformationObjectCsvExportJob.class.php +++ b/lib/job/arInformationObjectCsvExportJob.class.php @@ -72,16 +72,22 @@ protected function exportResource($resource, $path) */ protected function exportDataAndDigitalObject($resource, $path) { - // Pass parameters to QubitFlatfileExport to determine hidden visible elements - $this->csvWriter->setParams($this->params); + $cultures = array_keys(DefaultTranslationLinksComponent::getOtherCulturesAvailable($resource->informationObjectI18ns, 'title', $resource->getTitle(['sourceCulture' => true]))); - // Append resource metadata to CSV file - $this->csvWriter->exportResource($resource); + foreach ($cultures as $culture) { + $this->csvWriter->user->setCulture($culture); - $this->addDigitalObject($resource, $path); + // Pass parameters to QubitFlatfileExport to determine hidden visible elements + $this->csvWriter->setParams($this->params); - ++$this->itemsExported; - $this->logExportProgress(); + // Append resource metadata to CSV file + $this->csvWriter->exportResource($resource); + + $this->addDigitalObject($resource, $path); + + ++$this->itemsExported; + $this->logExportProgress(); + } } protected function getCsvWriter($path)