2022-10-07 16:04:34 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Entity\Gpu;
|
2022-10-14 11:16:53 -04:00
|
|
|
use App\Enum\SlotKeyEnum;
|
2022-10-07 16:04:34 -04:00
|
|
|
use App\Form\GpuType;
|
|
|
|
use App\Traits\FormControllerTrait;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\HttpFoundation\{Request, Response};
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
|
|
|
#[Route('/gpu')]
|
|
|
|
class GpuController extends AbstractController
|
|
|
|
{
|
|
|
|
use FormControllerTrait;
|
|
|
|
|
|
|
|
protected const ENTITY = Gpu::class;
|
|
|
|
protected const TEMPLATE_PATH = 'gpu/';
|
|
|
|
protected const ROUTE_PREFIX = 'gpu_';
|
|
|
|
protected const FORM = GpuType::class;
|
|
|
|
|
|
|
|
public function __construct(private readonly EntityManagerInterface $entityManager)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/', name: 'gpu_index', methods: ['GET'])]
|
|
|
|
public function index(): Response
|
|
|
|
{
|
2022-10-14 11:16:53 -04:00
|
|
|
$items = $this->entityManager->getRepository(self::ENTITY)->findAll();
|
|
|
|
$acquiredItems = array_filter($items, fn (Gpu $item) => $item->isAcquired());
|
|
|
|
$newItems = array_filter($items, fn ($item) => !$item->isAcquired());
|
|
|
|
|
|
|
|
$filter = fn (array $itemTypes) => array_filter($acquiredItems, fn (Gpu $item) => in_array($item->getCardKey(), $itemTypes));
|
|
|
|
|
|
|
|
$cardTypes = SlotKeyEnum::getGroups();
|
|
|
|
$pcieCardTypes = $cardTypes['PCI Express'];
|
|
|
|
$agpCardTypes = $cardTypes['AGP'];
|
|
|
|
$pciCardTypes = array_merge($cardTypes['PCI 32-bit'], $cardTypes['PCI 64-bit']);
|
|
|
|
$isaCardTypes = $cardTypes['ISA'];
|
2022-10-07 22:00:14 -04:00
|
|
|
|
|
|
|
return $this->render('gpu/index.html.twig', [
|
2022-10-14 11:16:53 -04:00
|
|
|
'gpus' => [
|
|
|
|
'not_acquired' => $newItems,
|
|
|
|
'acquired' => $acquiredItems,
|
|
|
|
'pcie' => $filter($pcieCardTypes),
|
|
|
|
'agp' => $filter($agpCardTypes),
|
|
|
|
'pci' => $filter($pciCardTypes),
|
|
|
|
'isa' => $filter($isaCardTypes),
|
|
|
|
]
|
2022-10-07 22:00:14 -04:00
|
|
|
]);
|
2022-10-07 16:04:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/new', name: 'gpu_new', methods: ['GET', 'POST'])]
|
|
|
|
public function new(Request $request): Response
|
|
|
|
{
|
|
|
|
return $this->itemCreate($request, 'gpu');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/{id}', name: 'gpu_show', methods: ['GET'])]
|
|
|
|
public function show(Gpu $gpu): Response
|
|
|
|
{
|
|
|
|
return $this->itemView($gpu, 'gpu');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/{id}/edit', name: 'gpu_edit', methods: ['GET', 'POST'])]
|
|
|
|
public function edit(Request $request, Gpu $gpu): Response
|
|
|
|
{
|
|
|
|
return $this->itemUpdate($request, $gpu, 'gpu');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Route('/{id}', name: 'gpu_delete', methods: ['POST'])]
|
|
|
|
public function delete(Request $request, Gpu $gpu): Response
|
|
|
|
{
|
|
|
|
return $this->deleteCSRF($request, $gpu);
|
|
|
|
}
|
|
|
|
}
|