Add enum for categorizing external repos
This commit is contained in:
parent
5c77d57b74
commit
06a39eb147
2
l18n
2
l18n
|
@ -1 +1 @@
|
|||
Subproject commit 8d83978b4f1159445f16ed9bb15b791ea9a4724a
|
||||
Subproject commit 808895ce187b34de591bbf7f4c1d9039a480e615
|
132
src/enums/MDInstitutionExternalIdRepository.php
Normal file
132
src/enums/MDInstitutionExternalIdRepository.php
Normal 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;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user