Add enums for object damage status and type

This commit is contained in:
Joshua Ramon Enslin 2022-12-21 18:45:13 +01:00
parent fb0146cde6
commit 4ac43ec62b
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
3 changed files with 207 additions and 1 deletions

2
l18n

@ -1 +1 @@
Subproject commit 7aae0b8edbede8054e6d5e28c3a8a7dcc88734bd
Subproject commit ca22b133ecc12ad49b8d17519571cc2eb8a03df7

View File

@ -0,0 +1,107 @@
<?PHP
/**
* Represents a type of status that can be assigned to an object in the process
* from identification to fixing or recognizing it is permanent.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a type of status that can be assigned to an object in the process
* from identification to fixing or recognizing it is permanent.
*/
enum MDObjectDamageStatus implements MDValueEnumInterface, JsonSerializable {
case identified;
case repair_possible;
case repair_scheduled; // By conservator
case repaired;
case irreparable;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDObjectDamageType
*/
public static function fromString(string $input):MDObjectDamageType {
return match($input) {
'identified' => self::identified,
'repair_possible' => self::repair_possible,
'repair_scheduled' => self::repair_scheduled,
'repaired' => self::repaired,
'irreparable' => self::irreparable,
default => throw new MDpageParameterNotFromListException("Unknown damage 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_damage_status_set", "object_damage_status_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_damage_status_set", "object_damage_status_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_damage_status_set", "object_damage_status_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}

View File

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