2024-06-30 23:36:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Actions;
|
|
|
|
|
|
|
|
use App\Form\Models\Form;
|
|
|
|
use App\Group;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class ExportSyncAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
|
|
|
public Form $form;
|
|
|
|
|
2024-07-01 12:08:59 +02:00
|
|
|
public function handle(Form $form): void
|
2024-06-30 23:36:44 +02:00
|
|
|
{
|
|
|
|
if (!$form->export->root) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage = $form->export->root->getStorage();
|
|
|
|
|
2024-07-15 23:49:28 +02:00
|
|
|
$storage->put($form->export->root->resource . '/Anmeldungen ' . $form->name . '.xlsx', CreateExcelDocumentAction::run($form, $form->participants));
|
2024-06-30 23:36:44 +02:00
|
|
|
|
|
|
|
if ($form->export->toGroupField) {
|
|
|
|
foreach ($form->participants->groupBy(fn ($participant) => $participant->data[$form->export->toGroupField]) as $groupId => $participants) {
|
|
|
|
$group = Group::find($groupId);
|
|
|
|
if (!$group?->fileshare) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-07-15 23:49:28 +02:00
|
|
|
$group->fileshare->getStorage()->put($group->fileshare->resource . '/Anmeldungen ' . $form->name . '.xlsx', CreateExcelDocumentAction::run($form, $participants));
|
2024-06-30 23:36:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function asJob(int $formId): void
|
|
|
|
{
|
|
|
|
$this->handle(Form::find($formId));
|
|
|
|
}
|
|
|
|
}
|