Add enums for object damage status and type

This commit is contained in:
2022-12-21 18:45:13 +01:00
parent fb0146cde6
commit 4ac43ec62b
3 changed files with 207 additions and 1 deletions

2
l18n

Submodule l18n updated: 7aae0b8edb...ca22b133ec

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;
}
}