src/Controller/TenantController.php line 24
<?phpnamespace App\Controller;use App\Entity\Tenant;use App\Form\TenantType;use App\Repository\TenantRepository;use App\Service\TenantService;use Doctrine\Persistence\ManagerRegistry;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;class TenantController extends AbstractController{public function __construct(private ManagerRegistry $managerRegistry,private TenantService $tenantService,) {}#[Route('/tenant', name: 'tenant', methods: ['GET'])]public function index(): Response{/** @var TenantRepository $tenantRepository */$tenantRepository = $this->managerRegistry->getRepository(Tenant::class);$tenants = $tenantRepository->findAll();$tenant = new Tenant();$form = $this->createForm(TenantType::class, $tenant);return $this->render('tenant/index.html.twig', ['tenants' => $tenants,'tenant_form' => $form->createView(),]);}#[Route('/tenant', name: 'tenant_add', methods: ['POST'])]public function add(Request $request): Response{$form = $this->createForm(tenantType::class);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$data = $form->getData();$em = $this->managerRegistry->getManager();$em->persist($data);$em->flush();$this->addFlash('success','Mieter erstellt!');return $this->redirectToRoute('tenant');}$this->addFlash('warning','Etwas ist schief gelaufen!');return $this->redirectToRoute('tenant');}#[Route('/tenant/{tenant}', name: 'tenant_view', methods: ['GET'])]public function view(Tenant $tenant): Response{$form = $this->createForm(TenantType::class, $tenant);/** @var TenantRepository $tenantRepository */$tenantRepository = $this->managerRegistry->getRepository(Tenant::class);$tenant = $tenantRepository->findAll();return $this->render('tenant/view.html.twig', ['tenant_form' => $form->createView(),]);}#[Route('/tenant/{tenant}', name: 'tenant_patch', methods: ['POST'])]public function patch(Tenant $tenant, Request $request): Response{$form = $this->createForm(TenantType::class, $tenant);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$em = $this->managerRegistry->getManager();$data = $form->getData();$data = $this->tenantService->setStateTenantForRoom($tenant);$em->persist($data);$em->flush();$this->addFlash('success','Änderungen gespeichert!');return $this->redirectToRoute('tenant');}$this->addFlash('warning','Etwas ist schief gelaufen!');return $this->redirectToRoute('tenant');}#[Route('/tenant/{tenant}/delete', name: 'tenant_delete', methods: ['GET'])]public function delete(Tenant $tenant): Response{$em = $this->managerRegistry->getManager();$em->remove($tenant);$em->flush();$this->addFlash('success','Mieter gelöscht!');return $this->redirectToRoute('tenant');}}