configstuff

This commit is contained in:
lubiana 2025-06-14 20:21:36 +02:00
parent ca0e7d300d
commit c3411e5754
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
12 changed files with 243 additions and 121 deletions

View file

@ -1,121 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\DrinkType;
use App\Entity\InventoryRecord;
use App\Form\InventoryRecordForm;
use App\Repository\InventoryRecordRepository;
use App\Service\InventoryService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/inventory-record')]
final class InventoryRecordController extends AbstractController
{
#[Route(name: 'app_inventory_record_index', methods: ['GET'])]
public function index(InventoryRecordRepository $inventoryRecordRepository): Response
{
return $this->render('inventory_record/index.html.twig', [
'inventory_records' => $inventoryRecordRepository->findAll(),
]);
}
#[Route('/new/{drinkType}', name: 'app_inventory_record_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager, DrinkType $drinkType): Response
{
$inventoryRecord = new InventoryRecord();
$inventoryRecord->setDrinkType($drinkType);
$form = $this->createForm(InventoryRecordForm::class, $inventoryRecord);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($inventoryRecord);
$entityManager->flush();
// If it's an HTMX request, return a redirect that HTMX will follow
if ($request->headers->has('HX-Request')) {
$response = new Response('', Response::HTTP_SEE_OTHER);
$response->headers->set('HX-Redirect', $this->generateUrl('app_index'));
return $response;
}
return $this->redirectToRoute('app_index', [], Response::HTTP_SEE_OTHER);
}
// Check if it's an HTMX request
if ($request->headers->has('HX-Request')) {
return $this->render('inventory_record/_modal_form.html.twig', [
'inventory_record' => $inventoryRecord,
'form' => $form,
]);
}
return $this->render('inventory_record/new.html.twig', [
'inventory_record' => $inventoryRecord,
'form' => $form,
]);
}
#[Route('/modal/{drinkType}', name: 'app_inventory_record_modal', methods: ['GET'])]
public function modal(DrinkType $drinkType, InventoryService $inventoryService): Response
{
$inventoryRecord = new InventoryRecord();
$inventoryRecord->setDrinkType($drinkType);
$inventoryRecord->setQuantity(
$inventoryService->getLatestInventoryRecord($drinkType)->getQuantity() ?? 0
);
$form = $this->createForm(InventoryRecordForm::class, $inventoryRecord, [
'action' => $this->generateUrl('app_inventory_record_new', [
'drinkType' => $drinkType->getId(),
]),
]);
return $this->render('inventory_record/_modal_form.html.twig', [
'inventory_record' => $inventoryRecord,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_inventory_record_show', methods: ['GET'])]
public function show(InventoryRecord $inventoryRecord): Response
{
return $this->render('inventory_record/show.html.twig', [
'inventory_record' => $inventoryRecord,
]);
}
#[Route('/{id}/edit', name: 'app_inventory_record_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, InventoryRecord $inventoryRecord, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(InventoryRecordForm::class, $inventoryRecord);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_inventory_record_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('inventory_record/edit.html.twig', [
'inventory_record' => $inventoryRecord,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_inventory_record_delete', methods: ['POST'])]
public function delete(Request $request, InventoryRecord $inventoryRecord, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete' . $inventoryRecord->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($inventoryRecord);
$entityManager->flush();
}
return $this->redirectToRoute('app_inventory_record_index', [], Response::HTTP_SEE_OTHER);
}
}

View file

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\SystemConfig;
use App\Enum\SystemSettingKey;
use App\Form\SystemConfigForm;
use App\Repository\SystemConfigRepository;
use App\Service\ConfigurationService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/system-config')]
final class SystemConfigController extends AbstractController
{
#[Route(name: 'app_system_config_index', methods: ['GET'])]
public function index(SystemConfigRepository $systemConfigRepository): Response
{
$configs = [];
foreach (SystemSettingKey::cases() as $key) {
$configs[] = $systemConfigRepository->findByKey($key);
}
return $this->render('system_config/index.html.twig', [
'system_configs' => $configs,
]);
}
#[Route(path: '/{id}/edit', name: 'app_system_config_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, SystemConfig $systemConfig, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(SystemConfigForm::class, $systemConfig);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_system_config_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('system_config/edit.html.twig', [
'system_config' => $systemConfig,
'form' => $form,
]);
}
#[Route(path: '/{id}/reset', name: 'app_system_config_reset', methods: ['POST'])]
public function reset(Request $request, SystemConfig $systemConfig, ConfigurationService $configurationService): Response
{
if ($this->isCsrfTokenValid('reset' . $systemConfig->getId(), $request->getPayload()->getString('_token'))) {
$configurationService->reset($systemConfig->getKey());
}
return $this->redirectToRoute('app_system_config_index', [], Response::HTTP_SEE_OTHER);
}
}