From 5ec93ba619fd8895daf0f4873dede45bf10f70c5 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Fri, 4 Apr 2025 17:20:16 +0200 Subject: [PATCH] Add enums for loan types, exhiibition contributor roles --- src/enums/MDExhibitionContributorRole.php | 177 ++++++++++++++++++++++ src/enums/MDLoanType.php | 143 +++++++++++++++++ 2 files changed, 320 insertions(+) create mode 100644 src/enums/MDExhibitionContributorRole.php create mode 100644 src/enums/MDLoanType.php diff --git a/src/enums/MDExhibitionContributorRole.php b/src/enums/MDExhibitionContributorRole.php new file mode 100644 index 0000000..198a74a --- /dev/null +++ b/src/enums/MDExhibitionContributorRole.php @@ -0,0 +1,177 @@ + + */ +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 + */ + 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 + */ + 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 + */ + 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 + */ + 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; + + } +} diff --git a/src/enums/MDLoanType.php b/src/enums/MDLoanType.php new file mode 100644 index 0000000..132c68c --- /dev/null +++ b/src/enums/MDLoanType.php @@ -0,0 +1,143 @@ + 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 + */ + 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 + */ + 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 + */ + public static function getSortedList(MDTlLoader $tlLoader):array { + return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "loan_types", "loan_types"); + + } + + /** + * Lists all available names. + * + * @return array + */ + 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; + + } +}