diff --git a/l18n b/l18n index 04b1e8d..dcd03ce 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit 04b1e8d678fbb37cac7d96b167be5822bab2491a +Subproject commit dcd03ce585f08b1793de30c7733dde6655c69595 diff --git a/src/enums/MDCustomReportFormat.php b/src/enums/MDCustomReportFormat.php new file mode 100644 index 0000000..29c800d --- /dev/null +++ b/src/enums/MDCustomReportFormat.php @@ -0,0 +1,78 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a format in which custom reports can be generated. + */ +enum MDCustomReportFormat implements MDValueEnumInterface, JsonSerializable { + + case csv; + case html; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDCustomReportTarget + */ + public static function fromString(string $input):MDObjectDamageType { + + return match($input) { + 'csv' => self::csv, + 'html' => self::html, + default => throw new MDpageParameterNotFromListException("Unknown custom report format"), + }; + + } + + /** + * Lists all available names. + * + * @return array + */ + public static function caseNames():array { + + $output = []; + + $cases = self::cases(); + foreach ($cases as $case) { + $output[] = $case->name; + } + + return $output; + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } + + /** + * Sanitizes a string for input into a file of the current format. + * + * @param string $input Input string to sanitize. + * + * @return string + */ + public function sanitize(string $input):string { + + return match($this) { + self::csv => '"' . strtr($input, ['"' => '\'']) . '"', + self::html => htmlspecialchars($input), + }; + + } +} diff --git a/src/enums/MDCustomReportTarget.php b/src/enums/MDCustomReportTarget.php new file mode 100644 index 0000000..820f8ec --- /dev/null +++ b/src/enums/MDCustomReportTarget.php @@ -0,0 +1,99 @@ + + */ +declare(strict_types = 1); + +/** + * Represents a type of page for which custom reports can be generated in musdb. + */ +enum MDCustomReportTarget implements MDValueEnumInterface, JsonSerializable { + + case object_single; + case object_list; + + /** + * Returns a value of this type based on a string. + * + * @param string $input Input to get a value from. + * + * @return MDCustomReportTarget + */ + public static function fromString(string $input):MDObjectDamageType { + + return match($input) { + 'object_single' => self::object_single, + 'object_list' => self::object_list, + default => throw new MDpageParameterNotFromListException("Unknown custom report target"), + }; + + } + + /** + * 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(), "custom_report_targets_set", "custom_report_targets_set"); + + } + + /** + * 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(), "custom_report_targets_set", "custom_report_targets_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("custom_report_targets_set", "custom_report_targets_set", $this->name); + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->name; + + } +}