From be01725a6fa5ca99aa047a45539c84213df45e95 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 3 Jan 2023 01:33:16 +0100 Subject: [PATCH] Add MDTimingInterval for controlling intervals at which (for now) autogenerated reports can be timed in musdb --- l18n | 2 +- src/enums/MDTimingInterval.php | 101 +++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/enums/MDTimingInterval.php diff --git a/l18n b/l18n index 69d86e4..8313264 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 69d86e4bf56528e9e1ddc8e4330a9f7c0b3d4880 +Subproject commit 8313264c585b13440f67b5922b918ba8198d24a5 diff --git a/src/enums/MDTimingInterval.php b/src/enums/MDTimingInterval.php new file mode 100644 index 0000000..6645ede --- /dev/null +++ b/src/enums/MDTimingInterval.php @@ -0,0 +1,101 @@ + + */ +declare(strict_types = 1); + +/** + * Represents timing intervals for autogenerated exports etc. + */ +enum MDTimingInternal implements MDValueEnumInterface, JsonSerializable { + + case weekly; + case monthly; + case annual; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDTimingInternal + */ + public static function fromString(string $input):MDTimingInternal { + + return match($input) { + 'weekly' => self::weekly, + 'monthly' => self::weekly, + 'annual' => self::weekly, + default => throw new MDpageParameterNotFromListException("Unknown timing interval: " . $input), + }; + + } + + /** + * 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(), "timing_intervals_set", "timing_intervals_set"); + + } + + /** + * 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(), "timing_intervals_set", "timing_intervals_set"); + + } + + /** + * 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("timing_intervals_set", "timing_intervals_set", $this->name); + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } +}