2025-11-25 14:57:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
2025-12-02 09:48:28 +01:00
|
|
|
namespace App\Enums;
|
2025-11-25 14:57:34 +01:00
|
|
|
|
|
|
|
|
use Uwil\LaravelCommon\Traits\Enums\BaseEnum;
|
|
|
|
|
|
2025-12-02 09:48:28 +01:00
|
|
|
enum ExportFormat: int
|
2025-11-25 14:57:34 +01:00
|
|
|
{
|
|
|
|
|
use BaseEnum;
|
|
|
|
|
|
2025-11-27 16:19:48 +01:00
|
|
|
case csv = 1;
|
|
|
|
|
case csvWithoutAttachment = 2;
|
|
|
|
|
case pdf = 3;
|
2025-11-25 14:57:34 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Optionnal labels definition
|
|
|
|
|
*/
|
|
|
|
|
private const LABELS = [
|
2025-11-27 16:19:48 +01:00
|
|
|
self::csv->name => 'csv',
|
|
|
|
|
self::csvWithoutAttachment->name => 'csv sans pièces jointes',
|
|
|
|
|
self::pdf->name => 'pdf',
|
2025-11-25 14:57:34 +01:00
|
|
|
];
|
|
|
|
|
|
2025-11-27 16:19:48 +01:00
|
|
|
/**
|
|
|
|
|
* Bootstrap color class to use for the export buttons.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function class(): string
|
|
|
|
|
{
|
|
|
|
|
return match ($this) {
|
|
|
|
|
self::csv,
|
|
|
|
|
self::csvWithoutAttachment => 'success',
|
|
|
|
|
self::pdf => 'danger',
|
|
|
|
|
default => 'primary',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Font Awesome picto to use for the export buttons.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function picto(): string
|
2025-11-25 14:57:34 +01:00
|
|
|
{
|
|
|
|
|
return match ($this) {
|
2025-11-27 16:19:48 +01:00
|
|
|
self::csv,
|
|
|
|
|
self::csvWithoutAttachment => 'fa-solid fa-file-csv',
|
|
|
|
|
self::pdf => 'fa-solid fa-file-pdf',
|
|
|
|
|
default => 'fa-solid fa-file',
|
2025-11-25 14:57:34 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 16:19:48 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* File headers to use when the exported file is return with StreamedResponse.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function fileHeaders(): array
|
|
|
|
|
{
|
|
|
|
|
return match ($this) {
|
|
|
|
|
self::csv,
|
|
|
|
|
self::csvWithoutAttachment => [
|
|
|
|
|
'Content-Type' => 'text/csv',
|
|
|
|
|
'Content-Disposition' => 'attachment; filename="export.csv"',
|
|
|
|
|
],
|
|
|
|
|
default => [],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export file name.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function fileName(): string
|
2025-11-25 14:57:34 +01:00
|
|
|
{
|
|
|
|
|
return match ($this) {
|
2025-11-27 16:19:48 +01:00
|
|
|
self::csv,
|
|
|
|
|
self::csvWithoutAttachment => 'export.csv',
|
|
|
|
|
self::pdf => 'export.pdf',
|
2025-11-25 14:57:34 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|