PHP code example of adt / exporter

1. Go to this page and download the library: Download adt/exporter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

adt / exporter example snippets


// jednoducha tabulka (grid):
$export = $this->exporter->export(new ExportRequest(
    identifier: 'smart-cards',
    sections: new ExportSection('items', $queryObject, ['number' => 'Cislo', ...]),
    generator: $excelGenerator,       // vs. $csvGenerator = volba formatu
    email: $user->getEmail(),
));

// vicesheetovy report (ruzne zdroje, vcetne agregatu bez entit):
$export = $this->exporter->export(new ExportRequest(
    identifier: 'order-payments',
    sections: [
        new ExportSection('Items', $orderItemsQb, $itemColumns),
        new ExportSection('Payments', $paymentsQb, $paymentColumns),
        new ExportSection('Summary', $summaryRows, $summaryColumns), // pole poli = snapshot primo v auditu
    ],
    generator: $excelGenerator,
    email: $user->getEmail(),
));

if (!$export->isInBackground()) {
    $this->sendResponse(new FileResponse($this->exporter->getFilePath($export), $export->getFileName()));
}
// jinak flash "export prijde e-mailem"

final readonly class MyGenerator implements BatchedExportFileGenerator
{
    public function generateBatched(array $sections, string $identifier): string
    {
        foreach ($sections['items']['batches'] as $batch) {
            foreach ($batch as $entity) {
                // ...zapsat radek do souboru...
            }
        }
        return $path;
    }
}

public function getActor(): ?ExportActor
{
    if (!$this->securityUser->isLoggedIn()) {
        return null;    // cron, konzument fronty, CLI
    }
    $identity = $this->securityUser->getIdentity();
    return new ExportActor(
        id: $identity->getId(),
        label: $identity->getName() ?: $identity->getEmail(),
        data: ['name' => $identity->getName(), 'email' => $identity->getEmail()],
    );
}

public function actionExport(int $id): void
{
    $export = $this->exportQueryFactory->create()->byId($id)->fetchOneOrNull();
    if (!$export || !$export->getFile()) {
        $this->error();
    }
    // stahnout smi jen autor exportu (pripadne rozsirit o admin ACL)
    if ($export->getCreatedBy()?->getId() !== $this->securityUser->getId()) {
        $this->error('', \Nette\Http\IResponse::S403_Forbidden);
    }
    $this->exporter->logDownload($export);   // az po overeni, pred vydanim
    $this->sendResponse(new FileResponse($export->getFile()->getPath(), $export->getFileName()));
}