Add enum for MDConservationReportType
This commit is contained in:
@@ -0,0 +1,181 @@
|
|||||||
|
<?PHP
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a type of conservation report.
|
||||||
|
*/
|
||||||
|
enum MDConservationReportType implements MDValueEnumInterface, JsonSerializable {
|
||||||
|
|
||||||
|
case damage;
|
||||||
|
case conservation;
|
||||||
|
case condition;
|
||||||
|
case restoration;
|
||||||
|
case other;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value of this type based on a string.
|
||||||
|
*
|
||||||
|
* @param string $input Input to get a value from.
|
||||||
|
*
|
||||||
|
* @return MDConservationReportType
|
||||||
|
*/
|
||||||
|
public static function fromString(string $input):MDConservationReportType {
|
||||||
|
|
||||||
|
return match($input) {
|
||||||
|
"damage" => self::damage,
|
||||||
|
"conservation" => self::conservation,
|
||||||
|
"condition" => self::condition,
|
||||||
|
"restoration" => self::restoration,
|
||||||
|
"other" => self::other,
|
||||||
|
default => throw new MDpageParameterNotFromListException("Unknown conservation report type"),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value of this type based on an integer.
|
||||||
|
*
|
||||||
|
* @param integer $input Input to get a value from.
|
||||||
|
*
|
||||||
|
* @return MDConservationReportType
|
||||||
|
*/
|
||||||
|
public static function fromInt(int $input):MDConservationReportType {
|
||||||
|
|
||||||
|
return match($input) {
|
||||||
|
0 => self::damage,
|
||||||
|
1 => self::conservation,
|
||||||
|
2 => self::condition,
|
||||||
|
3 => self::restoration,
|
||||||
|
4 => self::other,
|
||||||
|
default => throw new MDpageParameterNotFromListException("Unknown conservation report 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 {
|
||||||
|
|
||||||
|
$output = [];
|
||||||
|
foreach (self::cases() as $case) {
|
||||||
|
$output[$case->toString()] = $tlLoader->tl("conservation_report_type_set", "conservation_report_type_set", $case->toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
|
||||||
|
$output = self::getUnsortedList($tlLoader);
|
||||||
|
asort($output);
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all available names.
|
||||||
|
*
|
||||||
|
* @return array<integer>
|
||||||
|
*/
|
||||||
|
public static function caseInts():array {
|
||||||
|
|
||||||
|
$output = [];
|
||||||
|
|
||||||
|
$cases = self::cases();
|
||||||
|
foreach ($cases as $case) {
|
||||||
|
$output[] = $case->toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns integer representation of conservation report type.
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function toInt():int {
|
||||||
|
|
||||||
|
return match($this) {
|
||||||
|
self::damage => 0,
|
||||||
|
self::conservation => 1,
|
||||||
|
self::condition => 2,
|
||||||
|
self::restoration => 3,
|
||||||
|
self::other => 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns canonical string representation of conservation report type.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function toString():string {
|
||||||
|
|
||||||
|
return match($this) {
|
||||||
|
self::damage => "damage",
|
||||||
|
self::conservation => "conservation",
|
||||||
|
self::condition => "condition",
|
||||||
|
self::restoration => "restoration",
|
||||||
|
self::other => "other",
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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("conservation_report_type_set", "conservation_report_type_set", $this->toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the option to serialize as a string during json_encode().
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function jsonSerialize():string {
|
||||||
|
|
||||||
|
return $this->toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user