more code fixes

This commit is contained in:
Dennis Eichhorn 2024-03-15 21:57:48 +00:00
parent 92efabd600
commit c0b8123a00
4 changed files with 69 additions and 12 deletions

View File

@ -12,10 +12,19 @@
*/
declare(strict_types=1);
use Modules\Exchange\Models\NullReport;
/** @var \phpOMS\Views\View $this */
/** @var array $data */
$report = $this->data['report'] ?? [];
$headlines = \array_keys(\reset($report->data));
/** @var \Modules\Exchange\Models\Report $report */
$report = $this->data['report'] ?? new NullReport();
$first = \reset($report->data);
if ($first === false) {
$first = [];
}
$headlines = \array_keys($first);
$out = \fopen('php://output', 'w');
if ($out !== false) {

View File

@ -12,24 +12,34 @@
*/
declare(strict_types=1);
use Modules\Exchange\Models\NullReport;
use Modules\Media\Models\NullCollection;
use PhpOffice\PhpSpreadsheet\IOFactory;
use phpOMS\Utils\StringUtils;
/** @var \phpOMS\Views\View $this */
/** @var array<array> $data */
$report = $this->data['report'] ?? [];
/** @var \Modules\Exchange\Models\Report $report */
$report = $this->data['report'] ?? new NullReport();
include $this->data['defaultTemplates']->findFile('.xls.php')->getAbsolutePath();
/** @var \Modules\Media\Models\Collection $collection */
$collection = $this->data['defaultTemplates'] ?? new NullCollection();
include $collection->findFile('.xls.php')->getAbsolutePath();
$spreadsheet = new DefaultExcel();
$headlines = \array_keys(\reset($report->data));
$first = \reset($report->data);
if ($first === false) {
$first = [];
}
$headlines = \array_keys($first);
foreach ($headlines as $j => $headline) {
$spreadsheet->getActiveSheet()->setCellValue(StringUtils::intToAlphabet($j + 1) . 1, $headline);
}
foreach ($data as $i => $row) {
foreach ($report->data as $i => $row) {
foreach ($row as $j => $cell) {
$spreadsheet->getActiveSheet()->setCellValue(StringUtils::intToAlphabet($j + 1) . ($i + 2), $cell);
}

View File

@ -12,12 +12,18 @@
*/
declare(strict_types=1);
use Modules\Exchange\Models\NullReport;
use Modules\Media\Models\NullCollection;
/** @var \phpOMS\Views\View $this */
/** @var array<array> $data */
$report = $this->data['report'] ?? [];
/** @var \Modules\Exchange\Models\Report $report */
$report = $this->data['report'] ?? new NullReport();
require_once $this->data['defaultTemplates']->findFile('.pdf.php')->getAbsolutePath();
/** @var \Modules\Media\Models\Collection $collection */
$collection = $this->data['defaultTemplates'] ?? new NullCollection();
require_once $collection->findFile('.pdf.php')->getAbsolutePath();
/** @phpstan-import-type DefaultPdf from ../../../../Admin/Install/Media/PdfDefaultTemplate/pdfTemplate.pdf.php */
$pdf = new DefaultPdf();
@ -27,7 +33,12 @@ $topPos = $pdf->getY();
$tbl = '<table border="1" cellpadding="0" cellspacing="0">';
// headline
$headlines = \array_keys(\reset($report->data));
$first = \reset($report->data);
if ($first === false) {
$first = [];
}
$headlines = \array_keys($first);
$tbl .= '<thead><tr>';
foreach ($headlines as $headline) {
$tbl .= '<th>' . $headline . '</th>';

27
Models/NullReport.php Normal file
View File

@ -0,0 +1,27 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Exchange\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Exchange\Models;
/**
* Null model.
*
* @package Modules\Exchange\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullReport extends Report
{
}