adrema/app/Initialize/Actions/InitializeAction.php

84 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2022-08-31 00:33:36 +02:00
<?php
namespace App\Initialize\Actions;
2023-02-13 15:56:20 +01:00
use App\Initialize\InitializeActivities;
use App\Initialize\InitializeConfessions;
use App\Initialize\InitializeCountries;
use App\Initialize\InitializeCourses;
use App\Initialize\InitializeFees;
use App\Initialize\InitializeGenders;
use App\Initialize\InitializeGroups;
use App\Initialize\InitializeMembers;
use App\Initialize\InitializeNationalities;
use App\Initialize\InitializeRegions;
2022-08-31 00:33:36 +02:00
use App\Setting\NamiSettings;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class InitializeAction
{
use AsAction;
2023-02-13 15:56:20 +01:00
/**
* @var array<int, class-string>
*/
public array $initializers = [
InitializeGroups::class,
InitializeNationalities::class,
InitializeFees::class,
InitializeActivities::class,
InitializeConfessions::class,
InitializeCountries::class,
InitializeGenders::class,
InitializeRegions::class,
InitializeCourses::class,
InitializeMembers::class,
];
2023-05-05 12:02:58 +02:00
public function handle(): void
2022-08-31 00:33:36 +02:00
{
2023-05-05 12:22:28 +02:00
$api = app(NamiSettings::class)->login();
2023-02-13 15:56:20 +01:00
foreach ($this->initializers as $initializer) {
2023-05-05 12:22:28 +02:00
app($initializer)->handle($api);
2023-02-13 15:56:20 +01:00
}
2022-08-31 00:33:36 +02:00
}
2022-09-01 23:56:34 +02:00
/**
* @return array<string, string>
*/
2022-08-31 00:33:36 +02:00
public function rules(): array
{
return [
'mglnr' => 'required|numeric',
'password' => 'required|string',
'group_id' => 'required|numeric',
2023-05-08 15:11:16 +02:00
'params' => 'required|array',
2022-08-31 00:33:36 +02:00
];
}
2022-09-01 23:56:34 +02:00
/**
* @return array<string, string>
*/
public function getValidationAttributes(): array
{
return [
'group_id' => 'Gruppierungsnr',
];
}
2023-05-08 15:11:16 +02:00
public function asController(ActionRequest $request, NamiSettings $settings): RedirectResponse
2022-08-31 00:33:36 +02:00
{
2023-05-08 15:11:16 +02:00
$settings->mglnr = (int) $request->input('mglnr');
$settings->password = $request->input('password');
$settings->default_group_id = (int) $request->input('group_id');
$settings->search_params = $request->input('params');
$settings->save();
2023-05-05 12:22:28 +02:00
self::dispatch();
2023-05-05 12:02:58 +02:00
2023-05-08 15:11:16 +02:00
return redirect()->route('home');
2023-02-07 01:38:27 +01:00
}
2022-08-31 00:33:36 +02:00
}