Add new enums for object document type, institution categorization
Close #24, close #25, close #26, close #27
This commit is contained in:
153
src/enums/MDInstitutionUseCase.php
Normal file
153
src/enums/MDInstitutionUseCase.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Represents the use case an institution uses museum-digital's tools for.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents the use case an institution uses museum-digital's tools for.
|
||||
*/
|
||||
enum MDInstitutionUseCase implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case collection_management;
|
||||
case publication;
|
||||
case collection_management_and_publication;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDInstitutionUseCase
|
||||
*/
|
||||
public static function fromString(string $input):MDInstitutionUseCase {
|
||||
|
||||
return match($input) {
|
||||
"collection_management" => self::collection_management,
|
||||
"publication" => self::publication,
|
||||
"collection_management_and_publication" => self::collection_management_and_publication,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown use case for museum-digital"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDInstitutionUseCase
|
||||
*/
|
||||
public static function fromInt(int $input):MDInstitutionUseCase {
|
||||
|
||||
return match($input) {
|
||||
0 => self::collection_management,
|
||||
1 => self::publication,
|
||||
2 => self::collection_management_and_publication,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown use case for museum-digital"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_musdb_use_case_set", "institution_musdb_use_case_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_musdb_use_case_set", "institution_musdb_use_case_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::collection_management => 0,
|
||||
self::publication => 1,
|
||||
self::collection_management_and_publication => 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("institution_musdb_use_case_set", "institution_musdb_use_case_set", $this->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user