Skip to content

Commit

Permalink
Merge pull request #9 from calien666/export-event
Browse files Browse the repository at this point in the history
[TASK] Add export query event
  • Loading branch information
torben-fr authored Jun 24, 2024
2 parents f4e04f5 + c8ef7bd commit 400995f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Classes/Controller/XlsExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Calien\Xlsexport\Controller;

use Calien\Xlsexport\Export\Event\AlternateCheckQueryEvent;
use Calien\Xlsexport\Export\Event\AlternateExportQueryEvent;
use Calien\Xlsexport\Traits\ExportWithTsSettingsTrait;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception;
Expand Down Expand Up @@ -89,6 +90,10 @@ public function exportAction(int $id, string $config): ResponseInterface

$settings = $this->selfSettings['exports.'][$config . '.'];

$event = $this->eventDispatcher->dispatch(new AlternateExportQueryEvent($settings, $config));

$settings = $event->getManipulatedSettings();

$file = $this->doExport($settings, $this->pageId);

//ins Archiv verschieben
Expand Down
62 changes: 62 additions & 0 deletions Classes/Export/Event/AlternateExportQueryEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Calien\Xlsexport\Export\Event;

use Psr\EventDispatcher\StoppableEventInterface;

final class AlternateExportQueryEvent implements StoppableEventInterface
{
protected string $exportKey = '';

/**
* @var array <string, mixed>
*/
protected array $exportConfiguration = [];

/**
* @param array $settings
* @param string $config
*/
public function __construct(array $settings, string $config)
{
$this->exportKey = $config;
$this->exportConfiguration = $settings;
}

/**
* checkExportConfigExists
*
* Event listener should call this method to check if access is needed
*
* @param string $exportKey
* @return bool
*/
public function checkExportConfigExists(string $exportKey): bool
{
return $exportKey === $this->exportKey;
}

public function alternateExportQuery(string $export): void
{
if ($this->exportConfiguration['export'] && !$this->exportConfiguration['manipulated']) {
$this->exportConfiguration['export'] = $export;
$this->exportConfiguration['manipulated'] = true;
}
}

public function isPropagationStopped(): bool
{
$allManipulated = true;
if (!array_key_exists('manipulated', $this->exportConfiguration) || !$this->exportConfiguration['manipulated']) {
$allManipulated = false;
}
return $allManipulated;
}

public function getManipulatedSettings(): array
{
return $this->exportConfiguration;
}
}

0 comments on commit 400995f

Please sign in to comment.