Skip to content

Commit

Permalink
Fix GUI CSV export for translations. (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Feb 12, 2024
1 parent c55aba4 commit 82715df
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

require_once 'vendor/symfony/lib/helper/I18NHelper.php';

/*
* This file is part of the Access to Memory (AtoM) software.
*
Expand All @@ -19,110 +21,124 @@

class DefaultTranslationLinksComponent extends sfComponent
{
private $i18ns;
private $propertyName;
private $sourceCultureProperty;

public function execute($request)
{
$currentCulture = $this->getUser()->getCulture();

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;
}
}
20 changes: 13 additions & 7 deletions lib/job/arInformationObjectCsvExportJob.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 82715df

Please sign in to comment.