src/Controller/BuildingReportingController.php line 21
<?php
namespace App\Controller;
use App\Entity\Building;
use App\Entity\BuildingReportingHistory;
use App\Form\BuildingReportingFormType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class BuildingReportingController extends AbstractController
{
#[Route(path: [
"fr" => "/building/reporting/{id}",
"en" => "/en/building/reporting/{id}",
], name: 'building_reporting')]
public function add(Building $building, Request $request, EntityManagerInterface $entityManager)
{
$buildingReporting = new BuildingReportingHistory();
$form = $this->createForm(BuildingReportingFormType::class, $buildingReporting);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$buildingReporting->setBuilding($building);
$buildingReporting->setUser($this->getUser());
$buildingReporting->setCity($building->getCityEntity());
$buildingReporting->setCountry($building->getCityEntity()->getCountry());
$buildingReporting->setNumberId($building->getNumberId());
$buildingReporting->setPostalCode($building->getPostalCode());
$buildingReporting->setStreet($building->getStreet());
$buildingReporting->setNumberStreet($building->getStreetNumber());
$buildingReporting->setCreatedAt(new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris')));
$entityManager->persist($buildingReporting);
$entityManager->flush();
return $this->redirectToRoute('detail_building', ['id' => $building->getId()]);
}
return $this->render('building_reporting/index.html.twig', [
'form' => $form->createView(),
'building' => $building
]);
}
}