Add enum for object check types

See museum-digital/musdb#724
This commit is contained in:
Joshua Ramon Enslin 2022-12-17 22:48:59 +01:00
parent a79b239b27
commit fb0146cde6
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 102 additions and 1 deletions

2
l18n

@ -1 +1 @@
Subproject commit 250421445141edcaaede162576b337140696b82a
Subproject commit 7aae0b8edbede8054e6d5e28c3a8a7dcc88734bd

View File

@ -0,0 +1,101 @@
<?PHP
/**
* Represents a type of check an object may be subject to (completeness, condition, general audit).
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a type of check an object may be subject to (completeness, condition, general audit).
*/
enum MDObjectCheckType implements MDValueEnumInterface, JsonSerializable {
case condition_check;
case completeness_check;
case data_correctness_check;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDObjectCheckType
*/
public static function fromString(string $input):MDObjectCheckType {
return match($input) {
'condition_check' => self::condition_check,
'completeness_check' => self::completeness_check,
'data_correctness_check' => self::data_correctness_check,
default => throw new MDpageParameterNotFromListException("Unknown check 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(), "object_check_types_set", "object_check_types_set");
}
/**
* 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(), "object_check_types_set", "object_check_types_set");
}
/**
* 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("object_check_types_set", "object_check_types_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}