<?php
namespace App\Controller;
use App\Repository\InventoryObjectRepository;
use App\Repository\UserRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[IsGranted('ROLE_USER')]
class IndexController extends AbstractController
{
#[Route('/', name: 'app_index')]
public function index(Request $request, InventoryObjectRepository $inventoryObjectRepository): Response
{
$form = $this->createFormBuilder();
$form = $this->createFormBuilder()
->add('search', TextType::class)
->add('submit', SubmitType::class, [
'label' => 'SUCHEN'
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$searchID = $form["search"]->getData();
$object = $inventoryObjectRepository->find($searchID);
return $this->redirectToRoute('app_inventory_object_show', [
'id' => $object->getId(),
]);
}
return $this->render('index/index.html.twig', [
'controller_name' => 'IndexController',
'form' => $form->createView(),
]);
}
#[Route('/statistic', name: 'statistic')]
public function statistic(Request $request, UserRepository $userRepository): Response
{
return $this->render('index/statistic.html.twig', [
'controller_name' => 'InventoryController',
'users' => $userRepository->findAll(),
]);
}
}