src/Controller/BuildingReportingController.php line 21

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Building;
  4. use App\Entity\BuildingReportingHistory;
  5. use App\Form\BuildingReportingFormType;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class BuildingReportingController extends AbstractController
  11. {
  12.     #[Route(path: [
  13.         "fr" => "/building/reporting/{id}",
  14.         "en" => "/en/building/reporting/{id}",
  15.     ], name'building_reporting')]
  16.     public function add(Building $buildingRequest $requestEntityManagerInterface $entityManager)
  17.     {
  18.         $buildingReporting = new BuildingReportingHistory();
  19.         $form $this->createForm(BuildingReportingFormType::class, $buildingReporting);
  20.         $form->handleRequest($request);
  21.         if ($form->isSubmitted() && $form->isValid()) {
  22.             $buildingReporting->setBuilding($building);
  23.             $buildingReporting->setUser($this->getUser());
  24.             $buildingReporting->setCity($building->getCityEntity());
  25.             $buildingReporting->setCountry($building->getCityEntity()->getCountry());
  26.             $buildingReporting->setNumberId($building->getNumberId());
  27.             $buildingReporting->setPostalCode($building->getPostalCode());
  28.             $buildingReporting->setStreet($building->getStreet());
  29.             $buildingReporting->setNumberStreet($building->getStreetNumber());
  30.             $buildingReporting->setCreatedAt(new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris')));
  31.             $entityManager->persist($buildingReporting);
  32.             $entityManager->flush();
  33.             return $this->redirectToRoute('detail_building', ['id' => $building->getId()]);
  34.         }
  35.         return $this->render('building_reporting/index.html.twig', [
  36.             'form' => $form->createView(),
  37.             'building' => $building
  38.         ]);
  39.     }
  40. }