diff --git a/l18n b/l18n index 42ef9d9..7683733 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 42ef9d90c7517f3ced76d7ec3326d8c804bd6e06 +Subproject commit 768373372342a24a117d3a59ca686469398912dc diff --git a/src/enums/MDDbQueryAscDesc.php b/src/enums/MDDbQueryAscDesc.php new file mode 100644 index 0000000..cc29842 --- /dev/null +++ b/src/enums/MDDbQueryAscDesc.php @@ -0,0 +1,146 @@ + self::ASC, + 'ASC' => self::ASC, + 'desc' => self::DESC, + 'DESC' => self::DESC, + default => throw new MDpageParameterNotFromListException("Unknown sort order"), + }; + + } + + /** + * Returns a value of this type based on an integer. + * + * @param integer $input Input to get a value from. + * + * @return MDDbQueryAscDesc + */ + public static function fromInt(int $input):MDDbQueryAscDesc { + + return match($input) { + 1 => self::ASC, + 2 => self::DESC, + default => throw new MDpageParameterNotFromListException("Unknown sort order"), + }; + + } + + /** + * + */ + + /** + * Lists all available names. + * + * @return array + */ + public static function caseNames():array { + + $output = []; + + $cases = self::cases(); + foreach ($cases as $case) { + $output[] = $case->name; + } + + return $output; + + } + + /** + * Returns an integer representation of the collective (for storage in DB). + * + * @return integer + */ + public function toInt():int { + + return match($this) { + self::ASC => 1, + self::DESC => 2, + # default => throw new MDpageParameterNotFromListException("Unknown measurement type"), + }; + + } + + /** + * Returns the SQL representation of the entity. + * + * @return string + */ + public function toDbName():string { + + return match ($this) { + self::ASC => 'ASC', + self::DESC => 'DESC', + }; + + } + + /** + * 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(), "query_asc_desc", "query_asc_desc"); + + } + + /** + * 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(), "query_asc_desc", "query_asc_desc"); + + } + + /** + * 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("query_asc_desc", "query_asc_desc", $this->name); + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } +}