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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Transformers;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use Livewire\Wireable;
  6. abstract class BaseReportTransformer implements ExportableReport, Wireable
  7. {
  8. protected ReportDTO $report;
  9. public function __construct(ReportDTO $report)
  10. {
  11. $this->report = $report;
  12. }
  13. public function getAlignmentClass(int $index): string
  14. {
  15. if (in_array($index, $this->getRightAlignedColumns())) {
  16. return 'text-right';
  17. }
  18. if (in_array($index, $this->getCenterAlignedColumns())) {
  19. return 'text-center';
  20. }
  21. return 'text-left';
  22. }
  23. abstract public function getRightAlignedColumns(): array;
  24. abstract public function getCenterAlignedColumns(): array;
  25. abstract public function getLeftAlignedColumns(): array;
  26. public function toLivewire(): array
  27. {
  28. return [
  29. 'report' => $this->report->toLivewire(),
  30. ];
  31. }
  32. public static function fromLivewire($value): static
  33. {
  34. return new static(
  35. ReportDTO::fromLivewire($value['report']),
  36. );
  37. }
  38. }