Add collection and new vocab + mess with repository
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Bibliography;
|
||||
use App\Form\BibliographyType;
|
||||
//use App\Security\Voter\VocabVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -23,10 +24,18 @@ class BibliographyController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/bibliography', name: 'app_bibliography_landing')]
|
||||
public function landing(): Response
|
||||
public function landing(EntityManagerInterface $em): Response
|
||||
{
|
||||
$repo = $em->getRepository(Bibliography::class);
|
||||
$records = $repo->findBy([], ['modifiedAt' => 'DESC']);
|
||||
$count = count($records);
|
||||
|
||||
$records = array_slice($records, 0, 15);
|
||||
|
||||
return $this->render('bibliography/landing.html.twig', [
|
||||
'controller_name' => 'BibliographyController',
|
||||
'records' => $records,
|
||||
'count' => $count,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -38,11 +47,30 @@ class BibliographyController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/bibliography/add', name: 'app_bibliography_add')]
|
||||
/**
|
||||
* @todo Permissions with voter
|
||||
*/
|
||||
#[Route('/bibliography/add', name: 'app_bibliography_create')]
|
||||
public function add(): Response
|
||||
{
|
||||
return $this->render('bibliography/add.html.twig', [
|
||||
$form = $this->createForm(BibliographyType::class);
|
||||
|
||||
return $this->render('bibliography/create.html.twig', [
|
||||
'controller_name' => 'BibliographyController',
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* @todo Permissions!
|
||||
*/
|
||||
#[Route('/bibliography/delete/{id<\d+>}', name: 'app_bibliography_del')]
|
||||
public function delete(Bibliography $bibliography, EntityManagerInterface $em): Response
|
||||
{
|
||||
$em->remove($bibliography);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('notice', 'Term deleted successfully');
|
||||
|
||||
return $this->redirectToRoute('app_bibliography_landing');
|
||||
}
|
||||
}
|
||||
|
||||
26
src/Controller/CollectionController.php
Normal file
26
src/Controller/CollectionController.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Collection;
|
||||
use App\Entity\Bibliography;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class CollectionController extends AbstractController
|
||||
{
|
||||
#[Route('/collection/{id<\d+>}', name: 'app_collection')]
|
||||
public function index(Collection $collection, EntityManagerInterface $em): Response
|
||||
{
|
||||
$bibliographies = $em->getRepository(Bibliography::class)->findAllCollection($collection->getId());
|
||||
|
||||
$collection->setBibliographies($bibliographies);
|
||||
|
||||
return $this->render('collection/index.html.twig', [
|
||||
'controller_name' => 'CollectionController',
|
||||
'record' => $collection,
|
||||
]);
|
||||
}
|
||||
}
|
||||
34
src/Controller/VocabObjectTypeController.php
Normal file
34
src/Controller/VocabObjectTypeController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use App\Entity\VocabObjectType;
|
||||
|
||||
/**
|
||||
* @todo Pagination
|
||||
*/
|
||||
class VocabObjectTypeController extends AbstractController
|
||||
{
|
||||
#[Route('/vocabs/object_type', name: 'app_vocab_object_type')]
|
||||
public function index(EntityManagerInterface $em): Response
|
||||
{
|
||||
$roles = $this->getUser()->getRoles();
|
||||
|
||||
if (in_array('ROLE_READER', $roles)) {
|
||||
$this->addFlash('warning', 'Only editors, revisors and administrators can view vocabularies');
|
||||
return $this->redirectToRoute('app_home');
|
||||
}
|
||||
|
||||
$terms = $em->getRepository(VocabObjectType::class)
|
||||
->findBy([], ['term' => 'ASC']);
|
||||
|
||||
return $this->render('vocab_object_type/index.html.twig', [
|
||||
'controller_name' => 'VocabObjectTypeController',
|
||||
'terms' => $terms
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
//use App\Repository\UserRepository;
|
||||
|
||||
use App\Repository\BibliographyRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\RecordStatus;
|
||||
use Doctrine\Common\Collections\Collection as DoctrineCollection;
|
||||
|
||||
#[ORM\Entity()]
|
||||
#[ORM\Entity(repositoryClass: BibliographyRepository::class)]
|
||||
#[ORM\Table(name: 'bibliography')]
|
||||
class Bibliography
|
||||
{
|
||||
@@ -42,6 +42,20 @@ class Bibliography
|
||||
#[ORM\Column(length: 100, name: 'creator')]
|
||||
private ?string $creator = null;
|
||||
|
||||
#[ORM\JoinTable(name: 'rel_riferimento_collezione')]
|
||||
#[ORM\JoinColumn(name: 'Bibliografia_id_bib', referencedColumnName: 'id')]
|
||||
#[ORM\InverseJoinColumn(name: 'Collezione_id_coll', referencedColumnName: 'id')]
|
||||
#[ORM\ManyToMany(targetEntity: Collection::class)]
|
||||
private DoctrineCollection $collections;
|
||||
|
||||
private DoctrineCollection $documents;
|
||||
|
||||
private DoctrineCollection $objects;
|
||||
|
||||
private DoctrineCollection $persons;
|
||||
|
||||
private DoctrineCollection $sites;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -143,4 +157,16 @@ class Bibliography
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCollections(): ?DoctrineCollection
|
||||
{
|
||||
return $this->collections;
|
||||
}
|
||||
|
||||
public function setCollections(DoctrineCollection $collections): static
|
||||
{
|
||||
$this->collections = $collections;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
295
src/Entity/Collection.php
Normal file
295
src/Entity/Collection.php
Normal file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
//use App\Repository\UserRepository;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\RecordStatus;
|
||||
use Doctrine\Common\Collections\Collection as DoctrineCollection;
|
||||
|
||||
#[ORM\Entity()]
|
||||
#[ORM\Table(name: 'collection')]
|
||||
class Collection
|
||||
{
|
||||
#[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: 'tit_coll', type: Types::TEXT)]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(name: 'data_coll', type: Types::TEXT)]
|
||||
private ?string $chronology = null;
|
||||
|
||||
#[ORM\Column(name: 'inizio_coll', type: Types::SMALLINT)]
|
||||
private ?int $startDate = null;
|
||||
|
||||
#[ORM\Column(name: 'fine_coll', type: Types::SMALLINT)]
|
||||
private ?int $endDate = null;
|
||||
|
||||
#[ORM\Column(name: 'desc_coll', type: Types::TEXT)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(name: 'desc_br_coll', type: Types::TEXT)]
|
||||
private ?string $shortDescription = null;
|
||||
|
||||
#[ORM\Column(name: 'id_est_coll', type: Types::TEXT)]
|
||||
private ?string $externalIdentifier = null;
|
||||
|
||||
#[ORM\Column(name: 'link_coll', type: Types::TEXT)]
|
||||
private ?string $link = null;
|
||||
|
||||
#[ORM\Column(name: 'sogg_coll', type: Types::TEXT)]
|
||||
private ?string $subjectHeadings = null;
|
||||
|
||||
#[ORM\Column(name: 'uri_coll', type: Types::TEXT)]
|
||||
private ?string $uri = null;
|
||||
|
||||
#[ORM\Column(name: 'resp', length: 100)]
|
||||
private ?string $owner = null;
|
||||
|
||||
#[ORM\Column(name: 'note_coll', type: Types::TEXT)]
|
||||
private ?string $notes = null;
|
||||
|
||||
#[ORM\Column(length: 100, name: 'editor')]
|
||||
private ?string $editor = null;
|
||||
|
||||
#[ORM\Column(length: 100, name: 'creator')]
|
||||
private ?string $creator = null;
|
||||
|
||||
// TODO: These are references to vocabs
|
||||
#[ORM\Column(name: 'dir_aut_coll')]
|
||||
private ?int $authorRights = null;
|
||||
|
||||
#[ORM\Column(name: 'dir_acc_coll')]
|
||||
private ?int $accessRights = null;
|
||||
|
||||
#[ORM\Column(name: 'lic_coll')]
|
||||
private ?int $license = null;
|
||||
|
||||
#[ORM\JoinTable(name: 'rel_riferimento_collezione')]
|
||||
#[ORM\JoinColumn(name: 'Collezione_id_coll', referencedColumnName: 'id')]
|
||||
#[ORM\InverseJoinColumn(name: 'Bibliografia_id_bib', referencedColumnName: 'id')]
|
||||
#[ORM\ManyToMany(targetEntity: Bibliography::class)]
|
||||
private DoctrineCollection $bibliographies;
|
||||
|
||||
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 getCreator(): ?string
|
||||
{
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
public function setCreator(string $creator): static
|
||||
{
|
||||
$this->creator = $creator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(string $title): static
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getChronology(): ?string
|
||||
{
|
||||
return $this->chronology;
|
||||
}
|
||||
|
||||
public function setChronology(string $chronology): static
|
||||
{
|
||||
$this->chronology = $chronology;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStartDate(): ?int
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
public function setStartDate(int $startDate): static
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEndDate(): ?int
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
public function setEndDate(int $endDate): static
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getShortDescription(): ?string
|
||||
{
|
||||
return $this->shortDescription;
|
||||
}
|
||||
|
||||
public function setShortDescription(string $shortDescription): static
|
||||
{
|
||||
$this->shortDescription = $shortDescription;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getExternalIdentifier(): ?string
|
||||
{
|
||||
return $this->externalIdentifier;
|
||||
}
|
||||
|
||||
public function setExternalIdentifier(string $externalIdentifier): static
|
||||
{
|
||||
$this->externalIdentifier = $externalIdentifier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLink(): ?string
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
public function setLink(string $link): static
|
||||
{
|
||||
$this->link = $link;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubjectHeadings(): ?string
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
public function setSubjectHeadings(string $subjectHeadings): static
|
||||
{
|
||||
$this->subjectHeadings = $subjectHeadings;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUri(): ?string
|
||||
{
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function setUri(string $uri): static
|
||||
{
|
||||
$this->uri = $uri;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNotes(): ?string
|
||||
{
|
||||
return $this->notes;
|
||||
}
|
||||
|
||||
public function setNotes(string $notes): static
|
||||
{
|
||||
$this->notes = $notes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBibliographies(): ?DoctrineCollection
|
||||
{
|
||||
return $this->bibliographies;
|
||||
}
|
||||
|
||||
public function setBibliographies(DoctrineCollection $bibliographies): static
|
||||
{
|
||||
$this->bibliographies = $bibliographies;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
37
src/Entity/VocabObjectType.php
Normal file
37
src/Entity/VocabObjectType.php
Normal 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_tipologia_oggetto')]
|
||||
class VocabObjectType implements \App\VocabInterface
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(name: 'id_lis_tip_ogg')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 80, name: 'lis_tip_ogg')]
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
51
src/Form/BibliographyType.php
Normal file
51
src/Form/BibliographyType.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Bibliography;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BibliographyType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @todo Create status choices from enum
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('status', ChoiceType::class, [
|
||||
'choices' => [
|
||||
'-- Select status --' => '',
|
||||
'Draft' => 1,
|
||||
'Complete' => 2,
|
||||
'Unindexed' => 3,
|
||||
'Published' => 4,
|
||||
],
|
||||
'label' => 'Status (*)'
|
||||
])
|
||||
->add(
|
||||
'editor',
|
||||
TextType::class,
|
||||
[
|
||||
'label' => 'Editor(s) (*)'
|
||||
]
|
||||
)
|
||||
->add('citation', TextType::class, ['label' => 'Citation (*)'])
|
||||
->add('reference', TextareaType::class, ['label' => 'Reference (*)'])
|
||||
->add('notes', TextareaType::class, ['label' => 'Editorial notes', 'required' => false])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Bibliography::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Repository;
|
||||
use App\Entity\Bibliography;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Bibliography>
|
||||
@@ -15,5 +17,24 @@ class BibliographyRepository extends ServiceEntityRepository
|
||||
{
|
||||
parent::__construct($registry, Bibliography::class);
|
||||
}
|
||||
|
||||
public function findAllCollection(int $collectionId): ?ArrayCollection
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addRootEntityFromClassMetadata('App\Entity\Bibliography', 'b');
|
||||
|
||||
$query = $this->getEntityManager()->createNativeQuery(
|
||||
"SELECT id, stato, editor, cit_bib, rif_bib FROM bibliography b
|
||||
JOIN rel_riferimento_collezione
|
||||
ON Bibliografia_id_bib = id
|
||||
WHERE Collezione_id_coll = :collId",
|
||||
$rsm
|
||||
);
|
||||
$query->setParameter('collId', $collectionId);
|
||||
|
||||
$bibliographies = new ArrayCollection($query->getResult());
|
||||
|
||||
return $bibliographies;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
20
src/Repository/CollectionRepository.php
Normal file
20
src/Repository/CollectionRepository.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Collection;
|
||||
use App\Repository\BibliographyRepository;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Collection>
|
||||
*/
|
||||
class CollectionRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Collection::class);
|
||||
}
|
||||
}
|
||||
|
||||
18
src/Repository/VocabObjectTypeRepository.php
Normal file
18
src/Repository/VocabObjectTypeRepository.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\VocabObjectType;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<VocabFuncContext>
|
||||
*/
|
||||
class VocabObjectTypeRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, VocabObjectType::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user