<?php
namespace App\Controller;
use App\Entity\Refrence;
use App\Form\RefrenceType;
use App\Repository\RefrenceRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/refrence")
*/
class RefrenceController extends AbstractController
{
/**
* @Route("/list", name="app_refrence_list", methods={"GET"})
*/
public function list(RefrenceRepository $refrenceRepository): Response
{
return $this->render('refrence/list.html.twig', [
'refrences' => $refrenceRepository->findByRefLetter('Please upload'),
]);
}
/**
* @Route("/new", name="app_refrence_new", methods={"GET", "POST"})
*/
public function new(Request $request, RefrenceRepository $refrenceRepository): Response
{
$refrence = new Refrence();
$form = $this->createForm(RefrenceType::class, $refrence);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//get Ref Letter File name
$appFile = $form->get('refLet')->getData();
print $appFile;
if ($appFile){
$newAFilename = md5(uniqid()).'.'.$appFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$appFile->move(
$this->getParameter('brochures_directory'),
$newAFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$refrence->setRefLetter($newAFilename);
$refrenceRepository->add($refrence, true);
return $this->redirectToRoute('app_refrence_sucess', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('refrence/new.html.twig', [
'refrence' => $refrence,
'form' => $form,
]);
}
/**
* @Route("/sucess", name="app_refrence_sucess", methods={"GET"})
*/
public function showsucess(): Response
{
return $this->render('refrence/success.html.twig');
}
/**
* @Route("/{id}", name="app_refrence_show", methods={"GET"})
*/
public function show(Refrence $refrence): Response
{
return $this->render('refrence/show.html.twig', [
'refrence' => $refrence,
]);
}
/**
* @Route("/{id}/edit", name="app_refrence_edit", methods={"GET", "POST"})
*/
public function edit(Request $request, Refrence $refrence, RefrenceRepository $refrenceRepository): Response
{
$form = $this->createForm(RefrenceType::class, $refrence);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//get Ref Letter File name
$appFile = $form->get('RefLet')->getData();
print $appFile;
if ($appFile){
$newAFilename = md5(uniqid()).'.'.$appFile->guessClientExtension();
// Move the file to the directory where brochures are stored
try {
$appFile->move(
$this->getParameter('brochures_directory'),
$newAFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
$refrence->setRefLetter($newAFilename);
$refrenceRepository->add($refrence, true);
return $this->redirectToRoute('app_refrence_sucess', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('refrence/edit.html.twig', [
'refrence' => $refrence,
'form' => $form,
]);
}
/**
* @Route("/{id}", name="app_refrence_delete", methods={"POST"})
*/
/* public function delete(Request $request, Refrence $refrence, RefrenceRepository $refrenceRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$refrence->getId(), $request->request->get('_token'))) {
$refrenceRepository->remove($refrence, true);
}
return $this->redirectToRoute('app_refrence_list', [], Response::HTTP_SEE_OTHER);
}*/
}