From 10b9c58a1b79137b99a0fc243d595a5f5d47df48 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Fri, 12 Jan 2024 18:52:21 +0100 Subject: [PATCH] Add MDObjectRecordStatus to track record status --- l18n | 2 +- src/enums/MDObjectRecordStatus.php | 170 +++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/enums/MDObjectRecordStatus.php diff --git a/l18n b/l18n index 5ba11ff..992922c 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 5ba11ffba98cf0d702eb583e1d2d46b6995a8d7b +Subproject commit 992922cb369c10ac7e6ffdad22c5a9dea800b28c diff --git a/src/enums/MDObjectRecordStatus.php b/src/enums/MDObjectRecordStatus.php new file mode 100644 index 0000000..6b049de --- /dev/null +++ b/src/enums/MDObjectRecordStatus.php @@ -0,0 +1,170 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a type of link between tag and object (e.g. the tag being the object + * type, a material used for creating the object, etc.). + */ +enum MDObjectRecordStatus implements MDValueEnumInterface, JsonSerializable { + + case unlocked; + case locked; + case revision; + case deleted; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDObjectRecordStatus + */ + public static function fromString(string $input):MDTagRelationType { + + return match($input) { + 'unlocked' => self::unlocked, + 'locked' => self::locked, + 'revision' => self::revision, + 'deleted' => self::deleted, + default => throw new MDpageParameterNotFromListException("Unknown object record status"), + }; + + } + + /** + * Returns a value of this type based on an integer. + * + * @param integer $input Input to get a value from. + * + * @return MDObjectRecordStatus + */ + public static function fromInt(int $input):MDTagRelationType { + + return match($input) { + 0 => self::unlocked, + 1 => self::locked, + 2 => self::revision, + 3 => self::deleted, + default => throw new MDpageParameterNotFromListException("Unknown object record status"), + }; + + } + + /** + * Returns the default status. + * + * @return MDObjectRecordStatus + */ + public static function getDefault():MDTagRelationType { + + return self::unlocked; + + } + + /** + * Lists all available names. + * + * @return array + */ + public static function caseNames():array { + + $output = []; + + $cases = self::cases(); + foreach ($cases as $case) { + $output[] = $case->name; + } + + return $output; + + } + + /** + * Lists all available names. + * + * @return array + */ + public static function caseInts():array { + + $output = []; + + $cases = self::cases(); + foreach ($cases as $case) { + $output[] = $case->toInt(); + } + + return $output; + + } + + /** + * Returns integer representation of tag relations. + * + * @return integer + */ + public function toInt():int { + + return match($this) { + self::unlocked => 0, + self::locked => 1, + self::revision > 2, + self::deleted => 3, + // default => throw new MDpageParameterNotFromListException("Unknown tag relation type"), + }; + + } + + /** + * 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(), "object_record_status", "object_record_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(), "object_record_status", "object_record_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("object_record_status", "object_record_status", $this->name); + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } +}