UI коструктора отчетов

This commit is contained in:
brusnitsyn
2026-06-22 17:02:36 +09:00
parent bdb16dac54
commit 13dfcc3e05
11 changed files with 1664 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Services\Analytics\Export;
use App\Exports\Sheets\ArraySheetExport;
use App\Services\Analytics\AnalyticsResult;
use App\Services\Analytics\Column;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class AnalyticsExcelExport implements WithMultipleSheets
{
public function __construct(
private readonly AnalyticsResult $result,
private readonly string $title,
) {}
public function sheets(): array
{
$rows = [array_map(fn (Column $c) => $c->label, $this->result->columns)];
if ($this->result->rows === []) {
$rows[] = ['Нет данных за выбранный период'];
}
foreach ($this->result->rows as $row) {
$line = [];
foreach ($this->result->columns as $column) {
$line[] = $row[$column->key] ?? '';
}
$rows[] = $line;
}
return [new ArraySheetExport($this->sheetTitle(), $rows)];
}
private function sheetTitle(): string
{
return mb_substr(preg_replace('/[\\\\\/\?\*\[\]:]/', ' ', $this->title), 0, 31) ?: 'Отчёт';
}
}