Add enum for categorizing external repos

This commit is contained in:
Joshua Ramon Enslin 2023-04-09 01:37:39 +02:00
parent 5c77d57b74
commit 06a39eb147
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 133 additions and 1 deletions

2
l18n

@ -1 +1 @@
Subproject commit 8d83978b4f1159445f16ed9bb15b791ea9a4724a Subproject commit 808895ce187b34de591bbf7f4c1d9039a480e615

View File

@ -0,0 +1,132 @@
<?PHP
/**
* Represents a possible repository, in which an institution is listed with an ID.
* The ISIL is not covered in this list.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a possible status for to-dos.
*/
enum MDInstitutionExternalIdRepository implements MDValueEnumInterface, JsonSerializable {
case hu_ksh; // https://en.wikipedia.org/wiki/Hungarian_Central_Statistical_Office
const VALIDATION_PATTERN_HTML = [
'hu_ksh' => '[0-9]{8}-[0-9]{4}-[0-9]{3}-[0-9]{2}',
];
const VALIDATION_PATTERN_PHP = [
'hu_ksh' => '[0-9]{8}-[0-9]{4}-[0-9]{3}-[0-9]{2}',
];
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDInstitutionExternalIdRepository
*/
public static function fromString(string $input):MDInstitutionExternalIdRepository {
return match($input) {
'hu_ksh' => self::hu_ksh,
default => throw new MDpageParameterNotFromListException("Unknown external repository"),
};
}
/**
* 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(), "institution_external_id_repositories", "institution_external_id_repositories");
}
/**
* 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(), "institution_external_id_repositories", "institution_external_id_repositories");
}
/**
* 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("institution_external_id_repositories", "institution_external_id_repositories", $this->name);
}
/**
* Returns the HTML pattern.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return string
*/
public function getValidationPatternHtml():string {
return self::VALIDATION_PATTERN_HTML[$this->name];
}
/**
* Returns the PHP pattern.
*
* @param MDTlLoader $tlLoader Translation loader.
*
* @return string
*/
public function getValidationPatternPhp():string {
return self::VALIDATION_PATTERN_PHP[$this->name];
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}