From 50d76167d91aeec43fbd218b5acf91cc6147698d Mon Sep 17 00:00:00 2001 From: Levin Date: Fri, 29 Nov 2024 23:11:52 +0100 Subject: [PATCH] Add hook --- .../Exporters/Base/AbstractExporter.php | 11 +++++++++-- .../PersonalDataSelection/Exporters/Base/Exporter.php | 2 +- .../Exporters/Base/ModelExportable.php | 4 +++- .../Exporters/StatusExporter.php | 5 ++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Services/PersonalDataSelection/Exporters/Base/AbstractExporter.php b/app/Services/PersonalDataSelection/Exporters/Base/AbstractExporter.php index 27df75e11..4ed795f7b 100644 --- a/app/Services/PersonalDataSelection/Exporters/Base/AbstractExporter.php +++ b/app/Services/PersonalDataSelection/Exporters/Base/AbstractExporter.php @@ -5,7 +5,6 @@ namespace App\Services\PersonalDataSelection\Exporters\Base; use App\Models\User; -use Illuminate\Database\Eloquent\Collection; abstract class AbstractExporter { @@ -24,5 +23,13 @@ public function getFileName(): string { return $this->fileName; } - abstract protected function exportData(): array|string|Collection; + public function getData(): array|string { + $this->onExportValidation(); + + return $this->exportData(); + } + + abstract protected function exportData(): array|string; + + abstract protected function onExportValidation(): void; } diff --git a/app/Services/PersonalDataSelection/Exporters/Base/Exporter.php b/app/Services/PersonalDataSelection/Exporters/Base/Exporter.php index b052412cc..5c595f794 100644 --- a/app/Services/PersonalDataSelection/Exporters/Base/Exporter.php +++ b/app/Services/PersonalDataSelection/Exporters/Base/Exporter.php @@ -29,7 +29,7 @@ public function export(array $exporters): void { /** @var AbstractExporter $exporter */ foreach ($this->exporters as $exporter) { $exporter = new $exporter($this->user); - $this->personalDataSelection->add($exporter->getFileName(), $exporter->exportData()); + $this->personalDataSelection->add($exporter->getFileName(), $exporter->getData()); } } diff --git a/app/Services/PersonalDataSelection/Exporters/Base/ModelExportable.php b/app/Services/PersonalDataSelection/Exporters/Base/ModelExportable.php index 5dead18c8..d35bd5d8f 100644 --- a/app/Services/PersonalDataSelection/Exporters/Base/ModelExportable.php +++ b/app/Services/PersonalDataSelection/Exporters/Base/ModelExportable.php @@ -6,5 +6,7 @@ trait ModelExportable { - + protected function onExportValidation(): void { + // todo check for model + columns + } } diff --git a/app/Services/PersonalDataSelection/Exporters/StatusExporter.php b/app/Services/PersonalDataSelection/Exporters/StatusExporter.php index 27ad14cc0..8fda2a63c 100644 --- a/app/Services/PersonalDataSelection/Exporters/StatusExporter.php +++ b/app/Services/PersonalDataSelection/Exporters/StatusExporter.php @@ -5,12 +5,15 @@ namespace App\Services\PersonalDataSelection\Exporters; use App\Services\PersonalDataSelection\Exporters\Base\AbstractExporter; +use App\Services\PersonalDataSelection\Exporters\Base\ModelExportable; class StatusExporter extends AbstractExporter { + use ModelExportable; + protected string $fileName = 'statuses.json'; - public function exportData(): array|string { + protected function exportData(): array|string { return $this->user->statuses()->with('tags')->get()->toArray(); // todo: columns definieren } }