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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. protected array $options;
  10. public function __construct(ReportDTO $report, array $options = [])
  11. {
  12. $this->report = $report;
  13. $this->options = $options;
  14. }
  15. public function getAlignmentClass(int $index): string
  16. {
  17. if (in_array($index, $this->getRightAlignedColumns())) {
  18. return 'text-right';
  19. }
  20. if (in_array($index, $this->getCenterAlignedColumns())) {
  21. return 'text-center';
  22. }
  23. return 'text-left';
  24. }
  25. abstract public function getRightAlignedColumns(): array;
  26. abstract public function getCenterAlignedColumns(): array;
  27. abstract public function getLeftAlignedColumns(): array;
  28. public function toLivewire(): array
  29. {
  30. return [
  31. 'report' => $this->report->toLivewire(),
  32. ];
  33. }
  34. public static function fromLivewire($value): static
  35. {
  36. return new static(
  37. ReportDTO::fromLivewire($value['report']),
  38. );
  39. }
  40. }