Add controlled list of todo status
This commit is contained in:
parent
b4611a6e22
commit
a24c57395f
105
src/enums/MDTodoStatus.php
Normal file
105
src/enums/MDTodoStatus.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Represents a possible status for to-dos.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
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<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>
|
||||
*/
|
||||
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<string>
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user