61 lines
1.7 KiB
PHP
Executable File
61 lines
1.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\SystemConfig\Controllers;
|
|
|
|
use App\Controllers\BaseAdminController;
|
|
use Modules\SystemConfig\Models\SystemConfig;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class SystemConfigController extends BaseAdminController
|
|
{
|
|
public function index(Request $request): Response
|
|
{
|
|
$user = $this->getCurrentUser();
|
|
|
|
if (!$user || !$user->isSuperAdmin()) {
|
|
return new Response('Access Denied', 403);
|
|
}
|
|
|
|
$configs = SystemConfig::all();
|
|
|
|
return $this->renderAdminView('systemconfig/views/admin/index.twig', [
|
|
'configs' => $configs,
|
|
'title' => 'Configurações do Sistema'
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request): Response
|
|
{
|
|
$user = $this->getCurrentUser();
|
|
|
|
if (!$user || !$user->isSuperAdmin()) {
|
|
return new Response('Access Denied', 403);
|
|
}
|
|
|
|
$data = $request->request->all();
|
|
|
|
foreach ($data as $key => $value) {
|
|
if ($key === 'csrf_token') {
|
|
continue;
|
|
}
|
|
|
|
$config = SystemConfig::where('system_config_key', $key)->first();
|
|
|
|
if ($config) {
|
|
$config->system_config_value = $value;
|
|
$config->system_config_updated_by = $user->users_id;
|
|
$config->save();
|
|
} else {
|
|
SystemConfig::create([
|
|
'system_config_key' => $key,
|
|
'system_config_value' => $value,
|
|
'system_config_updated_by' => $user->users_id
|
|
]);
|
|
}
|
|
}
|
|
|
|
return new Response('', 302, ['Location' => url('admin/systemconfig')]);
|
|
}
|
|
}
|