2022-12-29 23:16:27 +01:00
|
|
|
<?PHP
|
|
|
|
/**
|
|
|
|
* Represents a format in which custom reports can be generated.
|
|
|
|
*
|
|
|
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
|
|
|
*/
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a format in which custom reports can be generated.
|
|
|
|
*/
|
2022-12-30 00:05:05 +01:00
|
|
|
enum MDCustomReportFormat implements JsonSerializable {
|
2022-12-29 23:16:27 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2022-12-30 05:11:41 +01:00
|
|
|
public static function fromString(string $input):MDCustomReportFormat {
|
2022-12-29 23:16:27 +01:00
|
|
|
|
|
|
|
return match($input) {
|
|
|
|
'csv' => self::csv,
|
|
|
|
'html' => self::html,
|
|
|
|
default => throw new MDpageParameterNotFromListException("Unknown custom report format"),
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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),
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|