Compare commits

...

5 Commits

6 changed files with 271 additions and 4 deletions
+1 -1
Submodule l18n updated: 963412a4d2...38eb44046b
+1
View File
@@ -56,6 +56,7 @@ final class MDNodaRepositoriesSet extends MDValueSet {
public const REPOSITORIES_TAG = [ public const REPOSITORIES_TAG = [
'aat', 'aat',
'ackerbau', 'ackerbau',
'avefi',
'allgemein', 'allgemein',
'col', 'col',
'bne', 'bne',
+104
View File
@@ -0,0 +1,104 @@
<?PHP
declare(strict_types = 1);
/**
* Represents an allowed hoster for videos of events.
*/
enum MDAppointmentRecordingHoster implements MDValueEnumInterface, JsonSerializable {
case archive_org;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDAppointmentRecordingHoster
*/
public static function fromString(string $input):MDAppointmentRecordingHoster {
return match($input) {
'archive_org' => self::archive_org,
'Archive.org' => self::archive_org,
default => throw new MDpageParameterNotFromListException("Unknown hoster"),
};
}
/**
* To string.
*
* @return string
*/
public function toString():string {
return match($this) {
self::archive_org => 'Archive.org',
};
}
/**
* Lists all available names.
*
* @return array<string>
*/
public static function caseNames():array {
$output = [];
$cases = self::cases();
foreach ($cases as $case) {
$output[] = $case->toString();
}
return $output;
}
/**
* Gets an unsorted list of the entries in a translated version.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return array<string, string>
*/
public static function getUnsortedList(MDTlLoader $tlLoader):array {
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "appointment_recording_hoster", "appointment_recording_hoster");
}
/**
* Gets a sorted list of the entries in a translated version.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return array<string, string>
*/
public static function getSortedList(MDTlLoader $tlLoader):array {
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "appointment_recording_hoster", "appointment_recording_hoster");
}
/**
* Returns the name of the current value in translation.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return string
*/
public function getTledName(MDTlLoader $tlLoader):string {
return $tlLoader->tl("appointment_recording_hoster", "appointment_recording_hoster", $this->toString());
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->toString();
}
}
+92
View File
@@ -0,0 +1,92 @@
<?PHP
declare(strict_types = 1);
/**
* Represents an allowed type of recording for events / appointments.
*/
enum MDAppointmentRecordingType implements MDValueEnumInterface, JsonSerializable {
case video;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDAppointmentRecordingType
*/
public static function fromString(string $input):MDAppointmentRecordingType {
return match($input) {
'video' => self::video,
default => throw new MDpageParameterNotFromListException("Unknown appointment recording type"),
};
}
/**
* Lists all available names.
*
* @return array<string>
*/
public static function caseNames():array {
$output = [];
$cases = self::cases();
foreach ($cases as $case) {
$output[] = $case->name;
}
return $output;
}
/**
* Gets an unsorted list of the entries in a translated version.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return array<string, string>
*/
public static function getUnsortedList(MDTlLoader $tlLoader):array {
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "appointment_recording_types", "appointment_recording_types");
}
/**
* Gets a sorted list of the entries in a translated version.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return array<string, string>
*/
public static function getSortedList(MDTlLoader $tlLoader):array {
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "appointment_recording_types", "appointment_recording_types");
}
/**
* Returns the name of the current value in translation.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return string
*/
public function getTledName(MDTlLoader $tlLoader):string {
return $tlLoader->tl("appointment_recording_types", "appointment_recording_types", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}
+34 -3
View File
@@ -14,6 +14,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
case allgemein; // General link to a good source case allgemein; // General link to a good source
case aat; case aat;
case ackerbau; case ackerbau;
case avefi;
case bne; case bne;
case bnf; case bnf;
case col; case col;
@@ -57,6 +58,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
'AAT-ID', 'AAT-ID',
'aat' => self::aat, 'aat' => self::aat,
'ackerbau' => self::ackerbau, 'ackerbau' => self::ackerbau,
'avefi' => self::avefi,
'bne' => self::bne, 'bne' => self::bne,
'bnf' => self::bnf, 'bnf' => self::bnf,
'col', 'col',
@@ -156,6 +158,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::allgemein => 'allgemein', // General link to a good source self::allgemein => 'allgemein', // General link to a good source
self::aat => 'aat', self::aat => 'aat',
self::ackerbau => 'ackerbau', self::ackerbau => 'ackerbau',
self::avefi => 'avefi',
self::bne => 'bne', self::bne => 'bne',
self::bnf => 'bnf', self::bnf => 'bnf',
self::col => 'col', self::col => 'col',
@@ -199,6 +202,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::allgemein => 'General', // General link to a good source self::allgemein => 'General', // General link to a good source
self::aat => 'Art & Architecture Thesaurus (AAT)', self::aat => 'Art & Architecture Thesaurus (AAT)',
self::ackerbau => 'Ackerbau-Thesaurus', self::ackerbau => 'Ackerbau-Thesaurus',
self::avefi => 'AVefi',
self::bne => 'Biblioteca Nacional de España (BNE)', self::bne => 'Biblioteca Nacional de España (BNE)',
self::bnf => 'Bibliothèque nationale de France (BNF)', self::bnf => 'Bibliothèque nationale de France (BNF)',
self::col => 'Catalogue of Life', self::col => 'Catalogue of Life',
@@ -242,6 +246,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::allgemein => '', self::allgemein => '',
self::aat => 'https://vocab.getty.edu/page/aat/', self::aat => 'https://vocab.getty.edu/page/aat/',
self::ackerbau => 'https://term.museum-digital.de/ackerbau/tag/', self::ackerbau => 'https://term.museum-digital.de/ackerbau/tag/',
self::avefi => 'https://hdl.handle.net/',
self::bne => 'http://datos.bne.es/persona/', self::bne => 'http://datos.bne.es/persona/',
self::bnf => "https://catalogue.bnf.fr/ark:/12148/cb", self::bnf => "https://catalogue.bnf.fr/ark:/12148/cb",
self::col => 'https://www.catalogueoflife.org/data/taxon/', self::col => 'https://www.catalogueoflife.org/data/taxon/',
@@ -304,6 +309,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::allgemein => 'https://www.google.de/search?q=' . urlencode($searchTerm), self::allgemein => 'https://www.google.de/search?q=' . urlencode($searchTerm),
self::aat => 'https://www.getty.edu/vow/AATServlet?english=N&find=' . urlencode($searchTerm) . '&page=1&note=', self::aat => 'https://www.getty.edu/vow/AATServlet?english=N&find=' . urlencode($searchTerm) . '&page=1&note=',
self::ackerbau => 'https://term.museum-digital.de/redir.php?search=' . urlencode($searchTerm) . '&kind=tag|ackerbau', self::ackerbau => 'https://term.museum-digital.de/redir.php?search=' . urlencode($searchTerm) . '&kind=tag|ackerbau',
self::avefi => 'https://www.av-efi.net/search?query=' . urlencode($searchTerm),
self::bne => 'http://datos.bne.es/persona/' . urlencode($searchTerm), self::bne => 'http://datos.bne.es/persona/' . urlencode($searchTerm),
self::bnf => 'https://catalogue.bnf.fr/resultats-auteur.do?nomAuteur=' . urlencode($searchTerm) . '+&filtre=1&pageRech=rau', self::bnf => 'https://catalogue.bnf.fr/resultats-auteur.do?nomAuteur=' . urlencode($searchTerm) . '+&filtre=1&pageRech=rau',
self::col => 'https://www.catalogueoflife.org/data/search?q=' . urlencode($searchTerm), self::col => 'https://www.catalogueoflife.org/data/search?q=' . urlencode($searchTerm),
@@ -422,6 +428,28 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
} }
/**
* Validates an AVefi ID. AVefi IDs are not numeric.
*
* @param string $id ID to validate.
*
* @return string|false
*/
private static function validateAvefiId(string $id):string|false {
if (str_contains($id, 'https://www.av-efi.net/')) {
$id = str_replace('https://www.av-efi.net/res/', '', $id);
}
if (str_contains($id, 'https://hdl.handle.net/')) {
$id = str_replace('https://hdl.handle.net/', '', $id);
}
if (substr_count($id, '/') !== 1) return false;
return $id;
}
/** /**
* Validates a BNE ID, returning a string or false. The BNE is basically equalivalent to the * Validates a BNE ID, returning a string or false. The BNE is basically equalivalent to the
* GND, just that the X character can be prepended to the number. * GND, just that the X character can be prepended to the number.
@@ -746,11 +774,13 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
public static function validateBnfId(string $id):string|false { public static function validateBnfId(string $id):string|false {
if (!is_numeric(substr($id, -1))) { if (!is_numeric(substr($id, -1))) {
$validation = self::validateNumericId(substr($id, 0, -1), ["https://catalogue.bnf.fr/ark:/12148/cb"]); $id = self::validateNumericId(substr($id, 0, -1), ["https://catalogue.bnf.fr/ark:/12148/cb"]) . substr($id, -1);
} }
else $validation = self::validateNumericId($id, ["https://catalogue.bnf.fr/ark:/12148/cb"]); else $id = self::validateNumericId($id, ["https://catalogue.bnf.fr/ark:/12148/cb"]);
if ($validation === false) return false; if ($id === false) {
return false;
}
return $id; return $id;
@@ -776,6 +806,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
'https://vocab.getty.edu/page/aat/', 'https://vocab.getty.edu/page/aat/',
]), ]),
self::ackerbau => self::validateNumericId($id, ['https://term.museum-digital.de/ackerbau/tag/']), self::ackerbau => self::validateNumericId($id, ['https://term.museum-digital.de/ackerbau/tag/']),
self::avefi => self::validateAvefiId($id),
self::bne => self::validateBneId($id, ['http://datos.bne.es/persona/', 'https://datos.bne.es/persona/']), self::bne => self::validateBneId($id, ['http://datos.bne.es/persona/', 'https://datos.bne.es/persona/']),
self::bnf => self::validateBnfId($id), self::bnf => self::validateBnfId($id),
self::col => self::validateColId($id), self::col => self::validateColId($id),
+39
View File
@@ -48,6 +48,34 @@ final class MDNodaRepositoryTest extends TestCase {
} }
/**
* Data provider for validating AVefi IDs.
*
* @return Generator<string, array{0: string|false, 1: string}>
*/
public static function avefiIdForValidationProvider():Generator {
yield "Full URL, https" => ["21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8", "https://www.av-efi.net/res/21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8"];
yield "ID" => ["21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8", "21.11155/D80067AB-B4F5-4139-8D78-540D8BC001B8"];
yield "Broken input / XX503494safdsaf;3" => [false, "XX503494safdsaf;3"];
}
/**
* Ensure validating references to the AVefi works.
*
* @param string|false $expected Expected output.
* @param string $inputString Input string.
*
* @return void
*/
#[DataProvider('avefiIdForValidationProvider')]
public function testAvefiIdValidation(string|false $expected, string $inputString):void {
self::assertEquals($expected, MDNodaRepository::avefi->validateId($inputString));
}
/** /**
* Data provider for validating BNE IDs. * Data provider for validating BNE IDs.
* *
@@ -77,6 +105,17 @@ final class MDNodaRepositoryTest extends TestCase {
} }
/**
* Data provider for validating BNE IDs.
*
* @return Generator<string, array{0: string|false, 1: string}>
*/
public static function bnfIdForValidationProvider():Generator {
yield "Broken input / duplicate https" => [false, "https://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cb104183522"];
}
/** /**
* Data provider for validating GND IDs. * Data provider for validating GND IDs.
* *