-
Notifications
You must be signed in to change notification settings - Fork 399
Add qualified Dublin Core record driver. #5053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+584
−7
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
847dcd7
Add initial support for qualified Dublin Core records.
EreMaijala 350d8d9
Tweaks,
EreMaijala d007612
Move locale methods to a trait.
EreMaijala 1c0454f
Merge remote-tracking branch 'origin/dev' into dev-qdc
EreMaijala 9f86355
Switch to LocaleSettingsAwareInterface/Trait.
EreMaijala 99022a3
Tweak locale matching.
EreMaijala 76dad0e
Fix code style.
EreMaijala 07a1daa
Merge remote-tracking branch 'origin/dev' into dev-qdc
EreMaijala de5fe6e
Switch to vufind-xml and fix code style.
EreMaijala b62d8a1
Add a note about prereqs, fix.
EreMaijala 6b08d41
Throw exception if LocaleSettings not available.
EreMaijala 0d71a10
Merge branch 'dev' into dev-qdc
demiankatz 8b4de86
Merge remote-tracking branch 'origin/dev' into dev-qdc
EreMaijala f3a6267
Fix order of namespaces checked in getElements.
EreMaijala 7ee2455
Add en-gb to fixture and test.
EreMaijala 488d20b
Improve doc comments.
EreMaijala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
module/VuFind/src/VuFind/RecordDriver/Feature/LocaleSupportTrait.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Functions for locale-specific processing in record drivers. | ||
| * | ||
| * PHP version 8 | ||
| * | ||
| * Copyright (C) The National Library of Finland 2026. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, see | ||
| * <https://www.gnu.org/licenses/>. | ||
| * | ||
| * @category VuFind | ||
| * @package RecordDrivers | ||
| * @author Ere Maijala <ere.maijala@helsinki.fi> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
| */ | ||
|
|
||
| namespace VuFind\RecordDriver\Feature; | ||
|
|
||
| /** | ||
| * Functions for locale-specific processing in record drivers. | ||
| * | ||
| * @category VuFind | ||
| * @package RecordDrivers | ||
| * @author Ere Maijala <ere.maijala@helsinki.fi> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
| */ | ||
| trait LocaleSupportTrait | ||
| { | ||
| /** | ||
| * Pick correct results from locale-specific results with fallback to all results. | ||
| * | ||
| * @param array $localeResults Result(s) keyed by locale | ||
| * @param array|string $allResults All results | ||
| * | ||
| * @return array|string | ||
| */ | ||
| protected function getLocaleSpecificResults(array $localeResults, array|string $allResults): array|string | ||
| { | ||
| if (null === $this->localeSettings) { | ||
| return $allResults; | ||
| } | ||
| $userLocale = $this->localeSettings->getUserLocale(); | ||
| if (null !== ($results = $this->getBestLocaleMatch($userLocale, $localeResults))) { | ||
| return $results; | ||
| } | ||
| // Check for matching language in locale-specific results: | ||
| [$userLanguage] = explode('-', $userLocale); | ||
| foreach ($localeResults as $locale => $results) { | ||
| [$lang] = explode('-', $locale); | ||
| if ($lang === $userLanguage) { | ||
| return $results; | ||
| } | ||
| } | ||
|
demiankatz marked this conversation as resolved.
Outdated
|
||
| // Check for match in default and fallback locales: | ||
| $locales = [$this->localeSettings->getDefaultLocale(), ...$this->localeSettings->getFallbackLocales()]; | ||
| foreach ($locales as $locale) { | ||
| if (null !== ($results = $this->getBestLocaleMatch($locale, $localeResults))) { | ||
| return $results; | ||
| } | ||
| } | ||
| // Could not find anything else, so return all: | ||
| return $allResults; | ||
| } | ||
|
|
||
| /** | ||
| * Pick best match for a locale from the results. | ||
| * | ||
| * @param string $locale Locale | ||
| * @param array $localeResults Result(s) keyed by locale | ||
| * | ||
| * @return mixed | ||
| */ | ||
| protected function getBestLocaleMatch(string $locale, array $localeResults): mixed | ||
| { | ||
| [$language] = explode('-', $locale); | ||
| return $localeResults[$locale] ?? $localeResults[$language] ?? null; | ||
| } | ||
| } | ||
97 changes: 97 additions & 0 deletions
97
module/VuFind/src/VuFind/RecordDriver/Feature/XmlTrait.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Functions for reading XML records. | ||
| * | ||
| * PHP version 8 | ||
| * | ||
| * Copyright (C) The National Library of Finland 2026. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, see | ||
| * <https://www.gnu.org/licenses/>. | ||
| * | ||
| * @category VuFind | ||
| * @package RecordDrivers | ||
| * @author Ere Maijala <ere.maijala@helsinki.fi> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
| */ | ||
|
|
||
| namespace VuFind\RecordDriver\Feature; | ||
|
|
||
| use FinnaXml\XmlDoc; | ||
|
|
||
| /** | ||
| * Functions for reading XML records. | ||
| * | ||
| * Assumption: raw XML data can be found in $this->fields['fullrecord']. | ||
| * | ||
| * @category VuFind | ||
| * @package RecordDrivers | ||
| * @author Ere Maijala <ere.maijala@helsinki.fi> | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
| * @link https://vufind.org/wiki/development:plugins:record_drivers Wiki | ||
| */ | ||
| trait XmlTrait | ||
| { | ||
| /** | ||
| * The XML namespace. | ||
| * | ||
| * Note: this is a property instead of a constant to make use of it in strings cleaner. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected string $xmlNs = 'http://www.w3.org/2000/xmlns/'; | ||
|
|
||
| /** | ||
| * XML class to use. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected string $xmlClass = \FinnaXml\XmlDoc::class; | ||
|
|
||
| /** | ||
| * XML instance. Access only via getXmlReader() as this is initialized lazily. | ||
| * | ||
| * @var XmlDoc | ||
| */ | ||
|
demiankatz marked this conversation as resolved.
|
||
| protected ?XmlDoc $lazyXmlReader = null; | ||
|
|
||
| /** | ||
| * Get access to the XML object. | ||
| * | ||
| * @return XmlDoc | ||
| */ | ||
| public function getXmlReader(): XmlDoc | ||
| { | ||
| if (null === $this->lazyXmlReader) { | ||
| $this->lazyXmlReader = new $this->xmlClass(); | ||
| $this->lazyXmlReader->parse($this->fields['fullrecord']); | ||
| } | ||
|
|
||
| return $this->lazyXmlReader; | ||
| } | ||
|
|
||
| /** | ||
| * Get lang attribute from xml namespace with fallback to default namespace. | ||
| * | ||
| * @param array $node XmlDoc node | ||
| * | ||
| * @return ?string | ||
| */ | ||
| protected function getLangAttr(array $node): ?string | ||
| { | ||
| $xml = $this->getXmlReader(); | ||
| return $xml->attr($node, '{{$this->xmlNs}}lang') ?? $xml->attr($node, 'lang'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.