You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Document\Chart;
|
|
use App\Form\Type\ChartType;
|
|
use Doctrine\ODM\MongoDB\DocumentManager;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Redirect;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
class ChartController extends AbstractController
|
|
{
|
|
/*#[Route('/charts', name: 'list_charts')]
|
|
public function registerAction(): Response
|
|
{
|
|
//$form = $this->createForm(RegistrationType::class, new Registration());
|
|
|
|
return $this->render('.html.twig', []);
|
|
}*/
|
|
|
|
#[Route('/charts/{id}/edit', name: 'edit_chart', requirements: ['id' => '\d+'])]
|
|
public function editAction(DocumentManager $dm, Request $request, int $id)
|
|
{
|
|
$chart = ($id !== null) ? $this->findOrFail($dm, $id) : new Chart();
|
|
|
|
$form = $this->createForm(ChartType::class, $chart);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$chart = $form->getData();
|
|
|
|
$dm->persist($chart);
|
|
$dm->flush();
|
|
|
|
//return $this->redirect('/');
|
|
}
|
|
|
|
return $this->render('edit.html.twig', [
|
|
'form' => $form->createView()
|
|
]);
|
|
}
|
|
|
|
#[Route('/charts/{id}', name: 'display_chart', requirements: ['id' => '\d+'])]
|
|
public function displayAction(DocumentManager $dm, Request $request, int $id)
|
|
{
|
|
$chart = ($id !== null) ? $this->findOrFail($dm, $id) : new Chart();
|
|
|
|
return $this->render('chart.html.twig');
|
|
}
|
|
|
|
private function findOrFail(DocumentManager $dm, int $id): Chart
|
|
{
|
|
$chart = $dm->getRepository(Chart::class)->findOneBy(['code' => $id]);
|
|
//$chart = $dm->getRepository(Chart::class)->findAll();
|
|
if ($chart === null) {
|
|
throw $this->createNotFoundException();
|
|
}
|
|
|
|
return $chart;
|
|
}
|
|
}
|