Files
MDAllowedValueSets/src/enums/MDInstitutionPublicPrivateStatus.php

158 lines
3.9 KiB
PHP

<?PHP
/**
* Represents the status of an institution as a public or privately-run one.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents the status of an institution as a public or privately-run one.
*/
enum MDInstitutionPublicPrivateStatus implements MDValueEnumInterface, JsonSerializable {
case public;
case private;
case religious;
case mixed;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDInstitutionPublicPrivateStatus
*/
public static function fromString(string $input):MDInstitutionPublicPrivateStatus {
return match($input) {
"public" => self::public,
"private" => self::private,
"religious" => self::religious,
"mixed" => self::mixed,
default => throw new MDpageParameterNotFromListException("Unknown public / private status"),
};
}
/**
* Returns a value of this type based on an integer.
*
* @param integer $input Input to get a value from.
*
* @return MDInstitutionPublicPrivateStatus
*/
public static function fromInt(int $input):MDInstitutionPublicPrivateStatus {
return match($input) {
0 => self::public,
1 => self::private,
2 => self::religious,
3 => self::mixed,
default => throw new MDpageParameterNotFromListException("Unknown public / private status"),
};
}
/**
* 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_public_private_category_set", "institution_public_private_category_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(), "institution_public_private_category_set", "institution_public_private_category_set");
}
/**
* 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 object record status.
*
* @return integer
*/
public function toInt():int {
return match($this) {
self::public => 0,
self::private => 1,
self::religious => 2,
self::mixed => 3,
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
};
}
/**
* 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_public_private_category_set", "institution_public_private_category_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}