Add MDTimingInterval for controlling intervals at which (for now)
autogenerated reports can be timed in musdb
This commit is contained in:
parent
663edea4db
commit
be01725a6f
2
l18n
2
l18n
|
@ -1 +1 @@
|
|||
Subproject commit 69d86e4bf56528e9e1ddc8e4330a9f7c0b3d4880
|
||||
Subproject commit 8313264c585b13440f67b5922b918ba8198d24a5
|
101
src/enums/MDTimingInterval.php
Normal file
101
src/enums/MDTimingInterval.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?PHP
|
||||
/**
|
||||
* Represents timing intervals for autogenerated exports etc.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
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<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(), "timing_intervals_set", "timing_intervals_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(), "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;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user