Skip to content

Commit

Permalink
add/introduce locale for the publication format
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed Feb 7, 2025
1 parent 36d5be4 commit fd528a1
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 12 deletions.
1 change: 1 addition & 0 deletions classes/migration/install/OMPMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function up(): void
Schema::create('publication_formats', function (Blueprint $table) {
$table->comment('Publication formats are representations of a publication in a particular format, e.g. PDF, hardcover, etc. Each publication format may contain many chapters.');
$table->bigInteger('publication_format_id')->autoIncrement();
$table->string('locale', 28)->nullable();

$table->bigInteger('publication_id');
$table->foreign('publication_id', 'publication_formats_publication_id')->references('publication_id')->on('publications')->onDelete('cascade');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I9485_PublicationFormatsLocale.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I9485_PublicationFormatsLocale
*
* @brief Add column locale to the DB table publication_formats.
*/

namespace APP\migration\upgrade\v3_5_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use PKP\migration\Migration;

class I9485_PublicationFormatsLocale extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('publication_formats', function (Blueprint $table) {
$table->string('locale', 28)->nullable();
});
DB::table('publication_formats as pf')
->join('publications as p', 'p.publication_id', '=', 'pf.publication_id')
->join('submissions as s', 's.submission_id', '=', 'p.submission_id')
->update(['pf.locale' => DB::raw('s.locale')]);

}

/**
* Reverse the migration.
*/
public function down(): void
{
Schema::table('publication_formats', function (Blueprint $table) {
if (Schema::hasColumn($table->getTable(), 'locale')) {
$table->dropColumn('maslocalethead');
};
});
}
}
23 changes: 23 additions & 0 deletions classes/publicationFormat/PublicationFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use APP\facades\Repo;
use PKP\db\DAORegistry;
use PKP\db\DAOResultFactory;
use PKP\facades\Locale;
use PKP\submission\Representation;
use PKP\submissionFile\SubmissionFile;

Expand Down Expand Up @@ -663,6 +664,28 @@ public function setStoredPubId($pubIdType, $pubId)
parent::setStoredPubId($pubIdType, $pubId);
}
}

/**
* Get display label that contains the publication format localized name and,
* in case when the publication format locale is different than the current UI language,
* also the publicaiton format language.
*/
public function getDisplayLabel(): string
{
$label = $this->getLocalizedName();
if ($this->getLocale() && $this->getLocale() !== Locale::getLocale()) {
$label .= ' (' . \Locale::getDisplayLanguage($this->getLocale(), $this->getLocale()) . ')';
}
return $label;
}

/**
* Get multilingual properties
*/
protected function getMultilingualProps(): array
{
return ['name'];
}
}

if (!PKP_STRICT_MODE) {
Expand Down
12 changes: 8 additions & 4 deletions classes/publicationFormat/PublicationFormatDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public function _fromRow($row, $params = [], $callHooks = true)
$publicationFormat->setData('urlPath', $row['url_path']);
$publicationFormat->setIsAvailable($row['is_available']);
$publicationFormat->setData('doiId', $row['doi_id']);
$publicationFormat->setData('locale', $row['locale']);

if (!empty($publicationFormat->getData('doiId'))) {
$publicationFormat->setData('doiObject', Repo::doi()->get($publicationFormat->getData('doiId')));
Expand Down Expand Up @@ -356,9 +357,9 @@ public function insertObject($publicationFormat)
{
$this->update(
'INSERT INTO publication_formats
(is_approved, entry_key, physical_format, publication_id, seq, file_size, front_matter, back_matter, height, height_unit_code, width, width_unit_code, thickness, thickness_unit_code, weight, weight_unit_code, product_composition_code, product_form_detail_code, country_manufacture_code, imprint, product_availability_code, technical_protection_code, returnable_indicator_code, remote_url, url_path, is_available, doi_id)
(is_approved, entry_key, physical_format, publication_id, seq, file_size, front_matter, back_matter, height, height_unit_code, width, width_unit_code, thickness, thickness_unit_code, weight, weight_unit_code, product_composition_code, product_form_detail_code, country_manufacture_code, imprint, product_availability_code, technical_protection_code, returnable_indicator_code, remote_url, url_path, is_available, doi_id, locale)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[
(int) $publicationFormat->getIsApproved(),
$publicationFormat->getEntryKey(),
Expand Down Expand Up @@ -386,7 +387,8 @@ public function insertObject($publicationFormat)
$publicationFormat->getData('urlRemote'),
$publicationFormat->getData('urlPath'),
(int) $publicationFormat->getIsAvailable(),
$publicationFormat->getData('doiId') === null ? null : (int) $publicationFormat->getData('doiId')
$publicationFormat->getData('doiId') === null ? null : (int) $publicationFormat->getData('doiId'),
$publicationFormat->getData('locale'),
]
);

Expand Down Expand Up @@ -430,7 +432,8 @@ public function updateObject(Representation $publicationFormat): void
remote_url = ?,
url_path = ?,
is_available = ?,
doi_id = ?
doi_id = ?,
locale = ?
WHERE publication_format_id = ?',
[
(int) $publicationFormat->getIsApproved(),
Expand Down Expand Up @@ -459,6 +462,7 @@ public function updateObject(Representation $publicationFormat): void
$publicationFormat->getData('urlPath'),
(int) $publicationFormat->getIsAvailable(),
$publicationFormat->getData('doiId'),
$publicationFormat->getData('locale'),
(int) $publicationFormat->getId()
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PKP\controllers\grid\GridColumn;
use PKP\controllers\grid\GridHandler;
use PKP\controllers\grid\GridRow;
use PKP\facades\Locale;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\linkAction\request\RemoteActionConfirmationModal;
Expand Down Expand Up @@ -106,6 +107,10 @@ public function getTemplateVarsFromRowColumn($row, $column)
return ['label' => '<a href="' . htmlspecialchars($remoteURL) . '" target="_blank">' . htmlspecialchars($data->getLocalizedName()) . '</a>' . '<span class="onix_code">' . $data->getNameForONIXCode() . '</span>'];
}
return ['label' => htmlspecialchars($data->getLocalizedName()) . '<span class="onix_code">' . $data->getNameForONIXCode() . '</span>'];
case 'language':
return [
'label' => Locale::getSubmissionLocaleDisplayNames([$data->getData('locale')], $this->getLocale())[$data->getData('locale')]
];
case 'isAvailable':
return ['status' => $data->getIsAvailable() ? 'completed' : 'new'];
case 'isComplete':
Expand All @@ -120,6 +125,10 @@ public function getTemplateVarsFromRowColumn($row, $column)
case 'name':
$fileNameGridColumn = new FileNameGridColumn(true, WORKFLOW_STAGE_ID_PRODUCTION);
return $fileNameGridColumn->getTemplateVarsFromRow($row);
case 'language':
return [
'label' => ''
];
case 'isComplete':
return ['status' => $proofFile->getViewable() ? 'completed' : 'new'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ public function initialize($request, $args = null)
['width' => 60, 'anyhtml' => true]
)
);
$this->addColumn(new GridColumn(
'language',
'common.language',
null,
null,
$this->_cellProvider
));
if ($this->_canManage) {
$this->addColumn(
new GridColumn(
Expand Down
39 changes: 39 additions & 0 deletions controllers/grid/catalogEntry/form/PublicationFormatForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use PKP\core\Core;
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\form\Form;

class PublicationFormatForm extends Form
Expand Down Expand Up @@ -60,6 +61,27 @@ public function __construct($monograph, $publicationFormat, $publication)
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'urlPath', 'optional', 'validator.alpha_dash_period', '/^[a-zA-Z0-9]+([\\.\\-_][a-zA-Z0-9]+)*$/'));
$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));

// Ensure a locale is provided and valid:
// Publication format locale can be one of the context's supported submission locales, as well as
// the existing monograph locale or the existing local of this publication format.
$locales = collect(Application::get()->getRequest()->getContext()->getSupportedSubmissionLocales())
->concat([$monograph->getData('locale')])
->concat([$publicationFormat?->getData('locale')])
->flatten()
->filter()
->unique()
->values()
->toArray();
$this->addCheck(
new \PKP\form\validation\FormValidatorCustom(
$this,
'locale',
'required',
'grid.catalogEntry.publicationFormatLocaleRequired',
fn ($locale) => in_array($locale, $locales)
)
);
}

//
Expand Down Expand Up @@ -158,6 +180,7 @@ public function initData()
'isbn13' => $isbn13,
'remoteURL' => $format->getData('urlRemote'),
'urlPath' => $format->getData('urlPath'),
'locale' => $format->getLocale(),
];
} else {
$this->setData('entryKey', 'DA');
Expand All @@ -182,6 +205,20 @@ public function fetch($request, $template = null, $display = false)
$templateMgr->assign('representationId', $publicationFormat->getId());
}
$templateMgr->assign('publicationId', $this->getPublication()->getId());

// get supported submisison locales that can be chosen for this publication format locale
$supportedSubmissionLocales = collect(Application::get()->getRequest()->getContext()->getSupportedSubmissionLocales())
->concat([$monograph->getData('locale')])
->concat([$publicationFormat?->getData('locale')])
->flatten()
->filter()
->unique()
->values()
->toArray();
ksort($supportedSubmissionLocales);
$supportedSubmissionLocaleNames = Locale::getSubmissionLocaleDisplayNames($supportedSubmissionLocales);
$templateMgr->assign('supportedSubmissionLocaleNames', $supportedSubmissionLocaleNames);

return parent::fetch($request, $template, $display);
}

Expand All @@ -200,6 +237,7 @@ public function readInputData()
'isbn13',
'remoteURL',
'urlPath',
'locale',
]);
}

Expand Down Expand Up @@ -232,6 +270,7 @@ public function execute(...$functionParams)
$publicationFormat->setPhysicalFormat($this->getData('isPhysicalFormat') ? true : false);
$publicationFormat->setData('urlRemote', strlen($remoteUrl = (string) $this->getData('remoteURL')) ? $remoteUrl : null);
$publicationFormat->setData('urlPath', strlen($urlPath = (string) $this->getData('urlPath')) ? $urlPath : null);
$publicationFormat->setData('locale', $this->getData('locale'));
parent::execute(...$functionParams);

if ($existingFormat) {
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<migration class="PKP\migration\upgrade\v3_5_0\I7135_CreateAuthorAffiliationsTables"/>
<migration class="PKP\migration\upgrade\v3_5_0\I7135_CreateNewRorRegistryCacheTables"/>
<migration class="PKP\migration\upgrade\v3_5_0\I10759_AddReviewAssignmentSettings"/>
<migration class="APP\migration\upgrade\v3_5_0\I9485_PublicationFormatsLocale"/>
<note file="docs/release-notes/README-3.5.0" />
</upgrade>

Expand Down
25 changes: 19 additions & 6 deletions plugins/generic/dublinCoreMeta/DublinCoreMetaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public function monographFileView($hookName, $args)
$press = $request->getContext();

$publicationLocale = $publication->getData('locale');
$publicationFormatLocale = $publicationFormat->getData('locale');
$submissionBestId = strlen($urlPath = (string) $publication->getData('urlPath')) ? $urlPath : $monograph->getId();

$templateMgr = TemplateManager::getManager($request);
Expand All @@ -235,7 +236,11 @@ public function monographFileView($hookName, $args)

$authors = $chapter ? $chapter->getAuthors()->toArray() : $publication->getData('authors');
foreach ($authors as $i => $author) {
$templateMgr->addHeader('dublinCoreAuthor' . $i++, '<meta name="DC.Creator.PersonalName" content="' . htmlspecialchars($author->getFullName(false, false, $publicationLocale)) . '"/>');
$authorPreferedLocale = $publicationFormatLocale;
if (!$author->getGivenName($authorPreferedLocale)) {
$authorPreferedLocale = $publicationLocale;
}
$templateMgr->addHeader('dublinCoreAuthor' . $i++, '<meta name="DC.Creator.PersonalName" content="' . htmlspecialchars($author->getFullName(false, false, $authorPreferedLocale)) . '"/>');
}

$datePublished = $chapter
Expand Down Expand Up @@ -278,9 +283,13 @@ public function monographFileView($hookName, $args)

$templateMgr->addHeader('dublinCoreUri', '<meta name="DC.Identifier.URI" content="' . $request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'catalog', 'book', [$submissionBestId, $publicationFormat->getId(), $submissionFile->getId()], urlLocaleForPage: '') . '"/>');

$templateMgr->addHeader('dublinCoreLanguage', '<meta name="DC.Language" scheme="ISO639-1" content="' . str_replace(['_', '@'], '-', $publicationLocale) . '"/>');
$templateMgr->addHeader('dublinCoreLanguage', '<meta name="DC.Language" scheme="ISO639-1" content="' . str_replace(['_', '@'], '-', $publicationFormatLocale) . '"/>');

if (($copyrightHolder = $publication->getData('copyrightHolder', $publicationLocale)) && ($copyrightYear = $publication->getData('copyrightYear'))) {
$copyrightHolderPreferedLocale = $publicationFormatLocale;
if (!$publication->getData('copyrightHolder', $copyrightHolderPreferedLocale)) {
$copyrightHolderPreferedLocale = $publicationLocale;
}
if (($copyrightHolder = $publication->getData('copyrightHolder', $copyrightHolderPreferedLocale)) && ($copyrightYear = $publication->getData('copyrightYear'))) {
$templateMgr->addHeader('dublinCoreCopyright', '<meta name="DC.Rights" content="' . htmlspecialchars(__('submission.copyrightStatement', ['copyrightHolder' => $copyrightHolder, 'copyrightYear' => $copyrightYear])) . '"/>');
}
if ($licenseURL = $publication->getData('licenseUrl')) {
Expand Down Expand Up @@ -309,12 +318,16 @@ public function monographFileView($hookName, $args)
}
}


$title = $chapter ? $chapter->getLocalizedFullTitle($publicationLocale) : $publication->getLocalizedFullTitle($publicationLocale);
$titlePreferredLocale = $publicationFormatLocale;
$titleTmp = $chapter ? $chapter->getDate('title', $titlePreferredLocale) : $publication->getData('title', $titlePreferredLocale);
if (!$titleTmp) {
$titlePreferredLocale = $publicationLocale;
}
$title = $chapter ? $chapter->getLocalizedFullTitle($titlePreferredLocale) : $publication->getLocalizedFullTitle($titlePreferredLocale);
$templateMgr->addHeader('dublinCoreTitle', '<meta name="DC.Title" content="' . htmlspecialchars($title) . '"/>');
$titles = $chapter ? $chapter->getFullTitles() : $publication->getFullTitles();
foreach ($titles as $locale => $altTitle) {
if ($title != '' && $locale != $publicationLocale) {
if ($title != '' && $locale != $titlePreferredLocale) {
$templateMgr->addHeader('dublinCoreAltTitle' . $locale, '<meta name="DC.Title.Alternative" xml:lang="' . htmlspecialchars(str_replace(['_', '@'], '-', $locale)) . '" content="' . htmlspecialchars($altTitle) . '"/>');
}
}
Expand Down
1 change: 1 addition & 0 deletions plugins/importexport/csv/CSVImportExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public function executeCLI($scriptName, &$args)
$publicationFormat->setProductAvailabilityCode('20'); // ONIX code for Available.
$publicationFormat->setEntryKey('DA'); // ONIX code for Digital
$publicationFormat->setData('name', 'PDF', $submission->getData('locale'));
$publicationFormat->setData('locale', $submission->getData('locale'));
$publicationFormat->setSequence(REALLY_BIG_NUMBER);
$publicationFormatId = $publicationFormatDao->insertObject($publicationFormat);

Expand Down
Loading

0 comments on commit fd528a1

Please sign in to comment.