You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BaseReportTransformer.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 getAlignmentClass(int $index): string
  19. {
  20. $column = $this->getColumns()[$index];
  21. if ($column->getAlignment() === Alignment::Right) {
  22. return 'text-right';
  23. }
  24. if ($column->getAlignment() === Alignment::Center) {
  25. return 'text-center';
  26. }
  27. return 'text-left';
  28. }
  29. public function toLivewire(): array
  30. {
  31. return [
  32. 'report' => $this->report->toLivewire(),
  33. ];
  34. }
  35. public static function fromLivewire($value): static
  36. {
  37. return new static(
  38. ReportDTO::fromLivewire($value['report']),
  39. );
  40. }
  41. }