diff --git a/src/enums/MDTodoStatus.php b/src/enums/MDTodoStatus.php new file mode 100644 index 0000000..078e60a --- /dev/null +++ b/src/enums/MDTodoStatus.php @@ -0,0 +1,105 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a possible status for to-dos. + */ +enum MDTodoStatus implements MDValueEnumInterface, JsonSerializable { + + case suggested; + case planned; + case in_progress; + case done; + case cancelled; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDTodoStatus + */ + public static function fromString(string $input):MDTodoStatus { + + return match($input) { + 'suggested' => self::suggested, + 'planned' => self::planned, + 'in_progress' => self::in_progress, + 'done' => self::done, + 'cancelled' => self::cancelled, + default => throw new MDpageParameterNotFromListException("Unknown todo status"), + }; + + } + + /** + * 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(), "todo_status", "todo_status"); + + } + + /** + * 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(), "todo_status", "todo_status"); + + } + + /** + * 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("todo_status", "todo_status", $this->name); + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } +}