parent
32a1e8b1be
commit
99e0f9b655
176
src/enums/MDGender.php
Normal file
176
src/enums/MDGender.php
Normal file
|
@ -0,0 +1,176 @@
|
|||
<?PHP
|
||||
/**
|
||||
* Represents a gender.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a gender.
|
||||
*/
|
||||
enum MDGender implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case none;
|
||||
case female;
|
||||
case male;
|
||||
case other;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDGender
|
||||
*/
|
||||
public static function fromString(string $input):MDGender {
|
||||
|
||||
return match($input) {
|
||||
"" => self::none,
|
||||
"none" => self::none,
|
||||
"female" => self::female,
|
||||
"male" => self::male,
|
||||
"other" => self::other,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown series place role"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDGender
|
||||
*/
|
||||
public static function fromInt(int $input):MDGender {
|
||||
|
||||
return match($input) {
|
||||
0 => self::none,
|
||||
1 => self::female,
|
||||
2 => self::male,
|
||||
3 => self::other,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown series place role"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all available names.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function caseNames():array {
|
||||
|
||||
$output = [];
|
||||
|
||||
$cases = self::cases();
|
||||
foreach ($cases as $case) {
|
||||
$output[] = $case->toString();
|
||||
}
|
||||
|
||||
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(), "gender_set", "gender_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(), "gender_set", "gender_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::none => 0,
|
||||
self::female => 1,
|
||||
self::male => 2,
|
||||
self::other => 3,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString():string {
|
||||
|
||||
return match($this) {
|
||||
self::none => '',
|
||||
self::female => 'female',
|
||||
self::male => 'male',
|
||||
self::other => 'other',
|
||||
# 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 {
|
||||
|
||||
if ($this === self::none) return '';
|
||||
return $tlLoader->tl("gender_set", "gender_set", $this->toString());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
237
src/enums/MDLicense.php
Normal file
237
src/enums/MDLicense.php
Normal file
|
@ -0,0 +1,237 @@
|
|||
<?PHP
|
||||
/**
|
||||
* Represents a license.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a license.
|
||||
*/
|
||||
enum MDLicense implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case CC_BY_NC_SA;
|
||||
case CC_BY_NC_ND;
|
||||
case CC_BY_NC;
|
||||
case CC_BY_ND;
|
||||
case CC_BY_SA;
|
||||
case CC_BY;
|
||||
case CC0;
|
||||
case RR_F;
|
||||
case RR_P;
|
||||
case RR_R;
|
||||
case Public_Domain_Mark;
|
||||
case Orphan_Work;
|
||||
|
||||
public const AVAILABLE_LICENSES = [
|
||||
|
||||
'CC BY-NC-SA' => 'https://creativecommons.org/licenses/by-nc-sa/4.0/',
|
||||
'CC BY-NC-ND' => 'https://creativecommons.org/licenses/by-nc-nd/4.0/',
|
||||
'CC BY-NC' => 'https://creativecommons.org/licenses/by-nc/4.0/',
|
||||
'CC BY-ND' => 'https://creativecommons.org/licenses/by-nd/4.0/',
|
||||
'CC BY-SA' => 'https://creativecommons.org/licenses/by-sa/4.0/',
|
||||
'CC BY' => 'https://creativecommons.org/licenses/by/4.0/',
|
||||
'CC0' => 'https://creativecommons.org/publicdomain/zero/1.0/',
|
||||
'RR-F' => 'https://www.europeana.eu/rights/rr-f/',
|
||||
'RR-P' => 'https://www.europeana.eu/rights/rr-p/',
|
||||
'RR-R' => 'https://www.europeana.eu/rights/rr-r/',
|
||||
'Public Domain Mark' => 'https://creativecommons.org/publicdomain/mark/1.0/',
|
||||
'Orphan Work' => 'https://www.europeana.eu/rights/orphan-work-eu/',
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDLicense
|
||||
*/
|
||||
public static function fromString(string $input):MDLicense {
|
||||
|
||||
return match($input) {
|
||||
'CC BY-NC-SA' => self::CC_BY_NC_SA,
|
||||
'CC BY-NC-ND' => self::CC_BY_NC_ND,
|
||||
'CC BY-NC' => self::CC_BY_NC,
|
||||
'CC BY-ND' => self::CC_BY_ND,
|
||||
'CC BY-SA' => self::CC_BY_SA,
|
||||
'CC BY' => self::CC_BY,
|
||||
'CC0' => self::CC0,
|
||||
'RR-F' => self::RR_F,
|
||||
'RR-P' => self::RR_P,
|
||||
'RR-R' => self::RR_R,
|
||||
'Public Domain Mark' => self::Public_Domain_Mark,
|
||||
'Orphan Work' => self::Orphan_Work,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown license role"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDLicense
|
||||
*/
|
||||
public static function fromInt(int $input):MDLicense {
|
||||
|
||||
return match($input) {
|
||||
1 => self::CC_BY_NC_SA,
|
||||
2 => self::CC_BY_NC_ND,
|
||||
3 => self::CC_BY_NC,
|
||||
4 => self::CC_BY_ND,
|
||||
5 => self::CC_BY_SA,
|
||||
6 => self::CC_BY,
|
||||
7 => self::CC0,
|
||||
8 => self::RR_F,
|
||||
9 => self::RR_P,
|
||||
10 => self::RR_R,
|
||||
11 => self::Public_Domain_Mark,
|
||||
12 => self::Orphan_Work,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown license role"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all available names.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function caseNames():array {
|
||||
|
||||
$output = [];
|
||||
|
||||
$cases = self::cases();
|
||||
foreach ($cases as $case) {
|
||||
$output[] = $case->toString();
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
$output = [];
|
||||
foreach (self::caseNames() as $name) $output[$name] = $name;
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
$output = self::getUnsortedList();
|
||||
asort($output);
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::CC_BY_NC_SA => 1,
|
||||
self::CC_BY_NC_ND => 2,
|
||||
self::CC_BY_NC => 3,
|
||||
self::CC_BY_ND => 4,
|
||||
self::CC_BY_SA => 5,
|
||||
self::CC_BY => 6,
|
||||
self::CC0 => 7,
|
||||
self::RR_F => 8,
|
||||
self::RR_P => 9,
|
||||
self::RR_R => 10,
|
||||
self::Public_Domain_Mark => 11,
|
||||
self::Orphan_Work => 12,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString():string {
|
||||
|
||||
return match($this) {
|
||||
self::CC_BY_NC_SA => 'CC BY-NC-SA',
|
||||
self::CC_BY_NC_ND => 'CC BY-NC-ND',
|
||||
self::CC_BY_NC => 'CC BY-NC',
|
||||
self::CC_BY_ND => 'CC BY-ND',
|
||||
self::CC_BY_SA => 'CC BY-SA',
|
||||
self::CC_BY => 'CC BY',
|
||||
self::CC0 => 'CC0',
|
||||
self::RR_F => 'RR-F',
|
||||
self::RR_P => 'RR-P',
|
||||
self::RR_R => 'RR-R',
|
||||
self::Public_Domain_Mark => 'Public Domain Mark',
|
||||
self::Orphan_Work => 'Orphan Work',
|
||||
# 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 $this->toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user