adrema/app/Mailman/Actions/SettingIndexAction.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2022-10-18 15:04:47 +02:00
<?php
namespace App\Mailman\Actions;
use App\Mailman\MailmanSettings;
2022-10-20 03:22:50 +02:00
use App\Mailman\Support\MailmanService;
2022-10-18 15:04:47 +02:00
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
2022-10-20 11:11:52 +02:00
* @return array<string, string|bool|null>
2022-10-18 15:04:47 +02:00
*/
public function handle(MailmanSettings $settings): array
{
return [
2022-10-20 03:22:50 +02:00
'is_active' => $settings->is_active,
2022-10-18 15:04:47 +02:00
'base_url' => $settings->base_url,
'username' => $settings->username,
2022-10-20 12:01:57 +02:00
'all_list' => $settings->all_list,
'all_parents_list' => $settings->all_parents_list,
'active_leaders_list' => $settings->active_leaders_list,
'passive_leaders_list' => $settings->passive_leaders_list,
2022-10-18 15:04:47 +02:00
'password' => '',
];
}
public function asController(MailmanSettings $settings): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Mailman-Einstellungen');
2022-10-20 12:01:57 +02:00
if ($settings->is_active) {
$state = app(MailmanService::class)->fromSettings($settings)->check();
$lists = app(MailmanService::class)->fromSettings($settings)->getLists();
} else {
$state = null;
$lists = [];
}
2022-10-20 03:22:50 +02:00
2022-10-20 02:15:28 +02:00
return Inertia::render('setting/Mailman', [
2022-10-18 15:04:47 +02:00
'data' => $this->handle($settings),
2022-10-20 03:22:50 +02:00
'state' => $state,
2022-10-20 12:01:57 +02:00
'lists' => $lists,
2022-10-18 15:04:47 +02:00
]);
}
}