Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BaseReportTransformer.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Transformers;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use Filament\Support\Enums\Alignment;
  6. use Livewire\Wireable;
  7. abstract class BaseReportTransformer implements ExportableReport, Wireable
  8. {
  9. protected ReportDTO $report;
  10. public function __construct(ReportDTO $report)
  11. {
  12. $this->report = $report;
  13. }
  14. public function getColumns(): array
  15. {
  16. return $this->report->fields;
  17. }
  18. public function getPdfView(): string
  19. {
  20. return 'components.company.reports.report-pdf';
  21. }
  22. public function getAlignmentClass(int $index): string
  23. {
  24. $column = $this->getColumns()[$index];
  25. if ($column->getAlignment() === Alignment::Right) {
  26. return 'text-right';
  27. }
  28. if ($column->getAlignment() === Alignment::Center) {
  29. return 'text-center';
  30. }
  31. return 'text-left';
  32. }
  33. public function toLivewire(): array
  34. {
  35. return [
  36. 'report' => $this->report->toLivewire(),
  37. ];
  38. }
  39. public static function fromLivewire($value): static
  40. {
  41. return new static(
  42. ReportDTO::fromLivewire($value['report']),
  43. );
  44. }
  45. }