Brutal vocabulary interaction (draft)

This commit is contained in:
2024-10-30 10:26:25 +01:00
parent 96904693ca
commit c20ec66f22
5 changed files with 205 additions and 1 deletions

View 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');
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Entity;
//use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity()]
#[ORM\Table(name: 'lis_contesto_funz')]
class VocabFuncContext
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name: 'id_lis_contesto')]
private ?int $id = null;
#[ORM\Column(length: 80, name: 'lis_contesto')]
private ?string $term = null;
public function getId(): ?int
{
return $this->id;
}
public function getTerm(): ?string
{
return $this->term;
}
public function setTerm(string $term): static
{
$this->term = $term;
return $this;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Repository;
use App\Entity\VocabFuncContext;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<VocabFuncContext>
*/
class VocabFuncContextRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, VocabFuncContext::class);
}
}