Add new enums for object document type, institution categorization
Close #24, close #25, close #26, close #27
This commit is contained in:
169
src/enums/MDObjectDocumentType.php
Normal file
169
src/enums/MDObjectDocumentType.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Represents a type of document published alongside an object.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a type of document published alongside an object.
|
||||
*/
|
||||
enum MDObjectDocumentType implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case undefined;
|
||||
case provenance_report;
|
||||
case purchase_contract;
|
||||
case restoration_report;
|
||||
case assessment;
|
||||
case correspondence;
|
||||
case legacy_documentation;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDObjectDocumentType
|
||||
*/
|
||||
public static function fromString(string $input):MDObjectDocumentType {
|
||||
|
||||
return match($input) {
|
||||
"undefined" => self::undefined,
|
||||
"provenance_report" => self::provenance_report,
|
||||
"purchase_contract" => self::purchase_contract,
|
||||
"restoration_report" => self::restoration_report,
|
||||
"assessment" => self::assessment,
|
||||
"correspondence" => self::correspondence,
|
||||
"legacy_documentation" => self::legacy_documentation,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown document type"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDObjectDocumentType
|
||||
*/
|
||||
public static function fromInt(int $input):MDObjectDocumentType {
|
||||
|
||||
return match($input) {
|
||||
0 => self::undefined,
|
||||
1 => self::provenance_report,
|
||||
2 => self::purchase_contract,
|
||||
3 => self::restoration_report,
|
||||
4 => self::assessment,
|
||||
5 => self::correspondence,
|
||||
6 => self::legacy_documentation,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown document 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_document_type_set", "object_document_type_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_document_type_set", "object_document_type_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::undefined => 0,
|
||||
self::provenance_report => 1,
|
||||
self::purchase_contract => 2,
|
||||
self::restoration_report => 3,
|
||||
self::assessment => 4,
|
||||
self::correspondence => 5,
|
||||
self::legacy_documentation => 6,
|
||||
# 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("object_document_type_set", "object_document_type_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