Brutal vocabulary interaction (draft)
This commit is contained in:
54
src/Controller/VocabFuncContextController.php
Normal file
54
src/Controller/VocabFuncContextController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\VocabFuncContext;
|
||||
use App\Repository\VocabFuncContextRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class VocabFuncContextController extends AbstractController
|
||||
{
|
||||
#[Route('/vocabs/functional_context', name: 'app_vocab_func_context')]
|
||||
public function index(EntityManagerInterface $em): Response
|
||||
{
|
||||
$terms = $em->getRepository(VocabFuncContext::class)->findBy([], ['term' => 'ASC']);
|
||||
|
||||
return $this->render('vocab_func_context/index.html.twig', [
|
||||
'controller_name' => 'VocabFuncContextController',
|
||||
'terms' => $terms,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/vocabs/functional_context/add', name: 'app_vocab_func_context_add')]
|
||||
public function addTerm(Request $request, EntityManagerInterface $em): Response
|
||||
{
|
||||
$term = $request->getPayload()->get('_term');
|
||||
|
||||
$vocab = new VocabFuncContext;
|
||||
$vocab->setTerm($term);
|
||||
$em->persist($vocab);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('notice', 'Term added successfully');
|
||||
|
||||
return $this->redirectToRoute('app_vocab_func_context');
|
||||
}
|
||||
|
||||
#[Route('/vocabs/functional_context/del', name: 'app_vocab_func_context_del')]
|
||||
public function deleteTerm(Request $request, EntityManagerInterface $em): Response
|
||||
{
|
||||
$id = $request->getPayload()->get('_id');
|
||||
$repo = $em->getRepository(VocabFuncContext::class);
|
||||
$term = $repo->find($id);
|
||||
$em->remove($term);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('notice', 'Term deleted successfully');
|
||||
|
||||
return $this->redirectToRoute('app_vocab_func_context');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user