Add enums for loan types, exhiibition contributor roles
This commit is contained in:
parent
1403f75447
commit
5ec93ba619
177
src/enums/MDExhibitionContributorRole.php
Normal file
177
src/enums/MDExhibitionContributorRole.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Represents a type of contribution to an exhibition.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a type of contribution to an exhibition.
|
||||
*/
|
||||
enum MDExhibitionContributorRole implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case concept;
|
||||
case curator;
|
||||
case design;
|
||||
case coordinator;
|
||||
case protagonist;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDExhibitionContributorRole
|
||||
*/
|
||||
public static function fromString(string $input):MDExhibitionContributorRole {
|
||||
|
||||
return match($input) {
|
||||
"concept" => self::concept,
|
||||
"curator" => self::curator,
|
||||
"design" => self::design,
|
||||
"coordinator" => self::coordinator,
|
||||
"protagonist" => self::protagonist,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown exhibition contributor role"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDExhibitionContributorRole
|
||||
*/
|
||||
public static function fromInt(int $input):MDExhibitionContributorRole {
|
||||
|
||||
return match($input) {
|
||||
0 => self::concept,
|
||||
1 => self::curator,
|
||||
2 => self::design,
|
||||
3 => self::coordinator,
|
||||
4 => self::protagonist,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown exhibition contributor role"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), "exhibition_contributor_roles", "exhibition_contributor_roles");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), "exhibition_contributor_roles", "exhibition_contributor_roles");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::concept => 0,
|
||||
self::curator => 1,
|
||||
self::design => 2,
|
||||
self::coordinator => 3,
|
||||
self::protagonist => 4,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns canonical string representation of object record status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString():string {
|
||||
|
||||
return match($this) {
|
||||
self::concept => 'concept',
|
||||
self::curator => 'curator',
|
||||
self::design => 'design',
|
||||
self::coordinator => 'coordinator',
|
||||
self::protagonist => 'protagonist',
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("exhibition_contributor_roles", "exhibition_contributor_roles", $this->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
143
src/enums/MDLoanType.php
Normal file
143
src/enums/MDLoanType.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a type of loan.
|
||||
*/
|
||||
enum MDLoanType implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case outgoing;
|
||||
case incoming;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDLoanType
|
||||
*/
|
||||
public static function fromString(string $input):MDLoanType {
|
||||
|
||||
return match($input) {
|
||||
"outgoing" => self::outgoing,
|
||||
"incoming" => self::incoming,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown loan type"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDLoanType
|
||||
*/
|
||||
public static function fromInt(int $input):MDLoanType {
|
||||
|
||||
return match($input) {
|
||||
0 => self::outgoing,
|
||||
1 => self::incoming,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown loan 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(), "loan_types", "loan_types");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), "loan_types", "loan_types");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::outgoing => 0,
|
||||
self::incoming => 1,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("loan_types", "loan_types", $this->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user