Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

BaseReportTransformer.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Transformers;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use App\Support\Column;
  6. use Filament\Support\Enums\Alignment;
  7. abstract class BaseReportTransformer implements ExportableReport
  8. {
  9. protected ReportDTO $report;
  10. public function __construct(ReportDTO $report)
  11. {
  12. $this->report = $report;
  13. }
  14. /**
  15. * @return Column[]
  16. */
  17. public function getColumns(): array
  18. {
  19. return once(function (): array {
  20. return $this->report->fields;
  21. });
  22. }
  23. public function getHeaders(): array
  24. {
  25. return once(function (): array {
  26. $headers = [];
  27. foreach ($this->getColumns() as $column) {
  28. $headers[$column->getName()] = $column->getLabel();
  29. }
  30. return $headers;
  31. });
  32. }
  33. public function getPdfView(): string
  34. {
  35. return 'components.company.reports.report-pdf';
  36. }
  37. public function getAlignment(int $index): string
  38. {
  39. $column = $this->getColumns()[$index];
  40. if ($column->getAlignment() === Alignment::Right) {
  41. return 'right';
  42. }
  43. if ($column->getAlignment() === Alignment::Center) {
  44. return 'center';
  45. }
  46. return 'left';
  47. }
  48. public function getAlignmentClass(string $columnName): string
  49. {
  50. return once(function () use ($columnName): string {
  51. /** @var Column|null $column */
  52. $column = collect($this->getColumns())->first(fn (Column $column) => $column->getName() === $columnName);
  53. if ($column?->getAlignment() === Alignment::Right) {
  54. return 'text-right';
  55. }
  56. if ($column?->getAlignment() === Alignment::Center) {
  57. return 'text-center';
  58. }
  59. return 'text-left';
  60. });
  61. }
  62. }