diff --git a/l18n b/l18n index 9ee0ddd..d2638c6 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 9ee0ddd18008f086a62f001969863971e02f656e +Subproject commit d2638c6f91395dc32c8b65ca68a3ae7bcac3b3e0 diff --git a/src/MDProcessTypesSet.php b/src/MDProcessTypesSet.php index 293e1e9..7155656 100644 --- a/src/MDProcessTypesSet.php +++ b/src/MDProcessTypesSet.php @@ -35,7 +35,7 @@ final class MDProcessTypesSet extends MDValueSet { * @return array */ public static function getSortedList(MDTlLoader $tlLoader):array { - return parent::getTlSortedList($tlLoader, self::POSITIONS, "process_types", "process_types"); + return parent::getTlSortedList($tlLoader, self::TYPES, "process_types", "process_types"); } } diff --git a/src/enums/MDProcessType.php b/src/enums/MDProcessType.php new file mode 100644 index 0000000..9db2500 --- /dev/null +++ b/src/enums/MDProcessType.php @@ -0,0 +1,110 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a possible type of internal processes in a museum. + */ +enum MDProcessType implements MDValueEnumInterface { + + case project; + case grant_application; + case exhibition; + case appointment; // This is MD's internally used name for events at the museum + case loan_incoming; + case loan_outgoing; + case employment_ad; + case purchase; + case deaccession; + case construction; + case pest_control_campaign; + case pr_campaign; + case relocation; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDProcessType + */ + public static function fromString(string $input):MDProcessType { + + return match($input) { + 'project' => self::project, + 'grant_application' => self::grant_application, + 'exhibition' => self::exhibition, + 'appointment' => self::appointment, + 'loan_incoming' => self::loan_incoming, + 'loan_outgoing' => self::loan_outgoing, + 'employment_ad' => self::employment_ad, + 'purchase' => self::purchase, + 'deaccession' => self::deaccession, + 'construction' => self::construction, + 'pest_control_campaign' => self::pest_control_campaign, + 'pr_campaign' => self::pr_campaign, + 'relocation' => self::relocation, + default => throw new MDpageParameterNotFromListException("Unknown process 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(), "process_types", "process_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(), "process_types", "process_types"); + + } + + /** + * 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("process_types", "process_types", $this->name); + + } +} diff --git a/src/enums/MDValueEnumInterface.php b/src/enums/MDValueEnumInterface.php new file mode 100644 index 0000000..bd7b6d5 --- /dev/null +++ b/src/enums/MDValueEnumInterface.php @@ -0,0 +1,58 @@ + + */ +declare(strict_types = 1); + +/** + * Describes an interface for a fully implemented enum describing a + * list of controlled values at md. + */ +interface MDValueEnumInterface { + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDValueEnumInterface + */ + public static function fromString(string $input):MDValueEnumInterface; + + /** + * Lists the case names available. + * + * @return array + */ + public static function caseNames():array; + + /** + * Gets an unsorted array based on provided keys and their translations. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return array + */ + public static function getUnsortedList(MDTlLoader $tlLoader):array; + + /** + * Gets a list of entries in a translated version. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return array + */ + public static function getSortedList(MDTlLoader $tlLoader):array; + + /** + * Returns the name of the current value in translation. + * + * @param MDTlLoader $tlLoader Translation loader. + * + * @return string + */ + public function getTledName(MDTlLoader $tlLoader):string; +}