Draft record view (bibliography)

This commit is contained in:
2024-10-31 10:24:28 +01:00
parent a5b7069679
commit 6b0fbce7ee
8 changed files with 287 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Controller;
use App\Entity\Bibliography;
//use App\Security\Voter\VocabVoter;
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;
//use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class BibliographyController extends AbstractController
{
#[Route('/bibliography/{id}', name: 'app_bibliography')]
public function index(Bibliography $bibliography, EntityManagerInterface $em): Response
{
return $this->render('bibliography/index.html.twig', [
'controller_name' => 'BibliographyController',
'record' => $bibliography,
]);
}
}

View File

@@ -10,8 +10,10 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Http\Attribute\IsGranted;
/**
* @todo Make edit endpoints JSON?
*/
class VocabFuncContextController extends AbstractController
{
#[Route('/vocabs/functional_context', name: 'app_vocab_func_context')]
@@ -57,6 +59,14 @@ class VocabFuncContextController extends AbstractController
#[Route('/vocabs/functional_context/update', name: 'app_vocab_func_context_upd')]
public function updateTerm(Request $request, EntityManagerInterface $em): Response
{
$vocab = new VocabFuncContext;
try {
$this->denyAccessUnlessGranted(VocabVoter::EDIT, $vocab);
}
catch (AccessDeniedException) {
$this->addFlash('warning', 'Only revisors and administrators can edit vocabularies');
return $this->redirectToRoute('app_home');
}
$id = $request->getPayload()->get('_id');
$newTerm = $request->getPayload()->get('_new_term');
@@ -74,6 +84,15 @@ class VocabFuncContextController extends AbstractController
#[Route('/vocabs/functional_context/del', name: 'app_vocab_func_context_del')]
public function deleteTerm(Request $request, EntityManagerInterface $em): Response
{
$vocab = new VocabFuncContext;
try {
$this->denyAccessUnlessGranted(VocabVoter::EDIT, $vocab);
}
catch (AccessDeniedException) {
$this->addFlash('warning', 'Only revisors and administrators can delete vocabularies');
return $this->redirectToRoute('app_home');
}
$id = $request->getPayload()->get('_id');
$repo = $em->getRepository(VocabFuncContext::class);
$term = $repo->find($id);

134
src/Entity/Bibliography.php Normal file
View File

@@ -0,0 +1,134 @@
<?php
namespace App\Entity;
//use App\Repository\UserRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use App\RecordStatus;
#[ORM\Entity()]
#[ORM\Table(name: 'bibliography')]
class Bibliography
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name: 'id')]
private ?int $id = null;
#[ORM\Column(name: 'stato')]
private ?int $status = null;
#[ORM\Column(name: 'modif')]
private ?DateTimeImmutable $modifiedAt = null;
#[ORM\Column(name: 'cit_bib', type: Types::TEXT)]
private ?string $citation = null;
#[ORM\Column(name: 'rif_bib', type: Types::TEXT)]
private ?string $reference = null;
#[ORM\Column(name: 'resp', length: 100)]
private ?string $owner = null;
#[ORM\Column(name: 'note_bib', type: Types::TEXT)]
private ?string $notes = null;
#[ORM\Column(length: 100)]
private ?string $editor = null;
#[ORM\Column(length: 100)]
private ?string $creator = null;
public function getId(): ?int
{
return $this->id;
}
public function getStatus(): ?string
{
$status = RecordStatus::tryFrom($this->status);
return $status->toString();
}
public function setStatus(int $status): static
{
$this->status = $status;
return $this;
}
public function getModifiedAt(): ?DateTimeImmutable
{
return $this->modifiedAt;
}
public function setModifiedAt(DateTimeImmutable $modifiedAt): static
{
$this->modifiedAt = $modifiedAt;
return $this;
}
public function getOwner(): ?string
{
return $this->owner;
}
public function setOwner(string $owner): static
{
$this->owner = $owner;
return $this;
}
public function getEditor(): ?string
{
return $this->editor;
}
public function setEditor(string $editor): static
{
$this->editor = $editor;
return $this;
}
public function getCitation(): ?string
{
return $this->citation;
}
public function setCitation(string $citation): static
{
$this->citation = $citation;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): static
{
$this->reference = $reference;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(string $notes): static
{
$this->notes = $notes;
return $this;
}
}

25
src/RecordStatus.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace App;
enum RecordStatus: int
{
case Draft = 1;
case Complete = 2;
case Excluded = 3;
case Unindexed = 4;
case Published = 5;
public function toString(): string
{
return match ($this) {
$this::Draft => 'Draft',
$this::Complete => 'Complete',
$this::Excluded => 'Excluded',
$this::Unindexed => 'Unindexed',
$this::Published => 'Published',
default => 'Draft'
};
}
}

View File

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