Files
MDAllowedValueSets/src/enums/MDVocabularyRedactionLevel.php

175 lines
4.3 KiB
PHP

<?PHP
/**
* Represents a redaction level for vocabulary entries (checked, unchecked, questionable).
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a type of contribution to an object group.
*/
enum MDVocabularyRedactionLevel implements MDValueEnumInterface, JsonSerializable {
case checked;
case unchecked;
case questionable;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDVocabularyRedactionLevel
*/
public static function fromString(string $input):MDVocabularyRedactionLevel {
return match($input) {
"+" => self::checked,
"checked" => self::checked,
"-" => self::unchecked,
"unchecked" => self::unchecked,
"" => self::questionable,
"questionable" => self::questionable,
default => throw new MDpageParameterNotFromListException("Unknown vocabulary redaction level"),
};
}
/**
* Returns a value of this type based on an integer.
*
* @param integer $input Input to get a value from.
*
* @return MDVocabularyRedactionLevel
*/
public static function fromInt(int $input):MDVocabularyRedactionLevel {
return match($input) {
0 => self::checked,
1 => self::unchecked,
2 => self::questionable,
default => throw new MDpageParameterNotFromListException("Unknown vocabulary redaction level"),
};
}
/**
* 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(), "vocabulary_redaction_level", "vocabulary_redaction_level");
}
/**
* 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(), "vocabulary_redaction_level", "vocabulary_redaction_level");
}
/**
* 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 name as noted in DB.
*
* @return string
*/
public function toDbString():string {
return match($this) {
self::checked => '+',
self::unchecked => '-',
self::questionable => '',
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
};
}
/**
* Returns integer representation of object record status.
*
* @return integer
*/
public function toInt():int {
return match($this) {
self::checked => 0,
self::unchecked => 1,
self::questionable => 2,
# 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("vocabulary_redaction_level", "vocabulary_redaction_level", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->toDbString();
}
}