src/Controller/VehicleDocsController.php line 54
<?php
namespace App\Controller;
use App\Entity\VehicleDocTypes;
use App\Entity\VehicleDocs;
use App\Entity\VehicleRtsActivitiesEstimateVal;
use App\Entity\VehicleSecurityNotices;
use App\Entity\Vehicles;
use App\Entity\VehicleClients;
use App\Form\VehicleHasDocsType;
use App\Service\VehicleDocsService;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Doctrine\Persistence\ManagerRegistry;
/**
* Class VehicleDocsController
* @package App\Controller
*
*/
#[Route('vehicleDocs')]
#[IsGranted(new Expression("is_granted('ROLE_ADMIN') or is_granted('ROLE_BENEFICIARY_REP')"))]
class VehicleDocsController extends AbstractController
{
/**
* Lists all vehicleDoc entities.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
#[Route('/', name: 'vehicledocs_index', methods:["GET"])]
public function indexAction(ManagerRegistry $doctrine)
{
$em = $doctrine->getManager();
$vehicleDocs = $em->getRepository(VehicleDocs::class)->findAll();
return $this->render('vehicledocs/index.html.twig', array(
'vehicleDocs' => $vehicleDocs,
));
}
/**
* Built tab 3 components given the vehicle Id
*
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Doctrine\ORM\NonUniqueResultException
*/
#[Route('/{vehicleId}/edit', name: 'vehicledocs_edit', methods:["GET"])]
public function editAction(Request $request, Vehicles $vehicle, $vehicleId,VehicleDocsService $vehicleDocsService)
{
$editVehicleDocs = $vehicleDocsService->edit($vehicle,$vehicleId);
return $this->render('vehicledocs/edit.html.twig',$editVehicleDocs);
}
/**
* Update an existing vehicle and its docs entities
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
#[Route('/{vehicleId}/edit', name: 'vehicledocs_update', methods:["POST"])]
public function updateAction(Request $request, Vehicles $vehicle, $vehicleId, VehicleDocsService $vehicleDocsService) {
$updateVehicleDocs = $vehicleDocsService->update($vehicle,$vehicleId);
if($updateVehicleDocs['result']=='success'){
return $this->redirectToRoute('vehicledocs_edit', array('vehicleId' => $vehicle->getVehicleId() ));
}else{
return $this->render('vehicledocs/edit.html.twig', $updateVehicleDocs['param']);
}
}
/**
* Deletes a vehicleDoc entity.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
#[Route('/{docId}', name: 'vehicledocs_delete', methods:["DELETE"])]
public function deleteAction(Request $request, VehicleDocs $vehicleDoc, ManagerRegistry $doctrine)
{
$form = $this->createDeleteForm($vehicleDoc);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $doctrine->getManager();
$em->remove($vehicleDoc);
$em->flush();
}
return $this->redirectToRoute('vehicledocs_index');
}
/**
* Creates a form to delete a vehicleDoc entity.
*
* @param VehicleDocs $vehicleDoc The vehicleDoc entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(VehicleDocs $vehicleDoc)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('vehicledocs_delete', array('docId' => $vehicleDoc->getDocid())))
->setMethod('DELETE')
->getForm()
;
}
}