Files
construprogress/app/Services/ReportGenerator.php
T

58 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Services;
use App\DTO\ReportFilters;
2026-08-28 13:04:28 +02:00
use App\Models\Project;
use App\Services\Report\DataAggregator;
use App\Services\Report\HtmlExporter;
use App\Services\Report\ExcelExporter;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class ReportGenerator
{
protected Project $project;
protected ReportFilters $filters;
protected DataAggregator $dataAggregator;
protected HtmlExporter $htmlExporter;
protected ExcelExporter $excelExporter;
public function __construct(
Project $project,
ReportFilters $filters,
?DataAggregator $dataAggregator = null,
?HtmlExporter $htmlExporter = null,
?ExcelExporter $excelExporter = null
) {
$this->project = $project;
$this->filters = $filters;
$this->dataAggregator = $dataAggregator ?? new DataAggregator($project, $filters);
$this->htmlExporter = $htmlExporter ?? new HtmlExporter();
$this->excelExporter = $excelExporter ?? new ExcelExporter();
}
public function generate(): array
{
return $this->dataAggregator->aggregate();
}
public function renderHtml(): View
{
$data = $this->generate();
return $this->htmlExporter->export($this->project, $data);
}
public function renderPreview(): View
{
$data = $this->generate();
return $this->htmlExporter->exportPreview($data);
}
public function exportExcel(): BinaryFileResponse
{
$data = $this->generate();
return $this->excelExporter->export($this->project, $this->filters, $data);
}
}