Add Collector entity

This commit is contained in:
Nicolò P. 2024-11-06 11:12:16 +01:00
parent f7efe03340
commit 47bed0bacc
9 changed files with 584 additions and 2 deletions

View File

@ -39,6 +39,7 @@ security:
- { path: ^/profile, roles: ROLE_USER }
- { path: ^/bibliography, roles: ROLE_USER }
- { path: ^/collection, roles: ROLE_USER }
- { path: ^/collector, roles: ROLE_USER }
- { path: ^/object, roles: ROLE_USER }
- { path: ^/site, roles: ROLE_USER }

View File

@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Bibliography;
use App\Entity\Collection;
use App\Entity\Collector;
use App\Form\BibliographyType;
//use App\Security\Voter\VocabVoter;
use Doctrine\ORM\EntityManagerInterface;
@ -20,8 +21,11 @@ class BibliographyController extends AbstractController
{
$repo = $em->getRepository(Collection::class);
$collections = $repo->findAllByBibliography($bibliography->getId());
$repo = $em->getRepository(Collector::class);
$collectors = $repo->findAllByBibliography($bibliography->getId());
$bibliography->setCollections($collections);
$bibliography->setCollectors($collectors);
return $this->render('bibliography/index.html.twig', [
'controller_name' => 'BibliographyController',

View File

@ -0,0 +1,45 @@
<?php
namespace App\Controller;
use App\Entity\Collector;
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 CollectorController extends AbstractController
{
#[Route('/collector/{id<\d+>}', name: 'app_collector')]
public function index(Collector $collector, EntityManagerInterface $em): Response
{
$repo = $em->getRepository(Bibliography::class);
/*
$bibliographies = $repo->findAllByCollection($collector->getId());
$collector->setBibliographies($bibliographies);
*/
return $this->render('collector/index.html.twig', [
'controller_name' => 'CollectorController',
'record' => $collector,
]);
}
#[Route('/collection', name: 'app_collection_landing')]
public function landing(EntityManagerInterface $em): Response
{
$repo = $em->getRepository(Collector::class);
$records = $repo->findBy([], ['modifiedAt' => 'DESC']);
$count = count($records);
$records = array_slice($records, 0, 15);
return $this->render('collector/landing.html.twig', [
'controller_name' => 'CollectorController',
'records' => $records,
'count' => $count,
]);
}
}

View File

@ -52,7 +52,11 @@ class Bibliography
private DoctrineCollection $objects;
private DoctrineCollection $persons;
#[ORM\JoinTable(name: 'rel_riferimento_personaggio')]
#[ORM\JoinColumn(name: 'Bibliografia_id_bib', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'Personaggio_id_pers', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: Collector::class, inversedBy: 'bibliography')]
private DoctrineCollection $collectors;
private DoctrineCollection $sites;
@ -169,4 +173,16 @@ class Bibliography
return $this;
}
public function getCollectors(): ?DoctrineCollection
{
return $this->collectors;
}
public function setCollectors(DoctrineCollection $collectors): static
{
$this->collectors = $collectors;
return $this;
}
}

View File

@ -246,7 +246,7 @@ class Collection
public function getSubjectHeadings(): ?string
{
return $this->link;
return $this->subjectHeadings;
}
public function setSubjectHeadings(string $subjectHeadings): static

294
src/Entity/Collector.php Normal file
View File

@ -0,0 +1,294 @@
<?php
namespace App\Entity;
use App\Repository\CollectorRepository;
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(repositoryClass: CollectorRepository::class)]
#[ORM\Table(name: 'collector')]
class Collector
{
#[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: 'nome_pers', type: Types::TEXT)]
private ?string $name = null;
#[ORM\Column(name: 'nasc_pers', type: Types::TEXT)]
private ?string $birthDate = null;
#[ORM\Column(name: 'dec_pers', type: Types::TEXT)]
private ?string $deathDate = null;
#[ORM\Column(name: 'luoghi_att_pers', type: Types::TEXT)]
private ?string $places = null;
#[ORM\Column(name: 'desc_pers', type: Types::TEXT)]
private ?string $description = null;
#[ORM\Column(name: 'desc_br_pers', type: Types::TEXT)]
private ?string $shortDescription = null;
#[ORM\Column(name: 'id_est_pers', type: Types::TEXT)]
private ?string $externalIdentifier = null;
#[ORM\Column(name: 'link_pers', type: Types::TEXT)]
private ?string $link = null;
#[ORM\Column(name: 'sogg_pers', type: Types::TEXT)]
private ?string $subjectHeadings = null;
#[ORM\Column(name: 'uri_pers', type: Types::TEXT)]
private ?string $uri = null;
#[ORM\Column(name: 'resp', length: 100)]
private ?string $owner = null;
#[ORM\Column(name: 'note_pers', 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_pers')]
private ?int $authorRights = null;
#[ORM\Column(name: 'dir_acc_pers')]
private ?int $accessRights = null;
#[ORM\Column(name: 'lic_pers')]
private ?int $license = null;
#[ORM\JoinTable(name: 'rel_riferimento_personaggio')]
#[ORM\JoinColumn(name: 'Personaggio_id_pers', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'Bibliografia_id_bib', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: Bibliography::class, inversedBy: 'collector')]
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 getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getBirthDate(): ?string
{
return $this->birthDate;
}
public function setBirthDate(string $birthDate): static
{
$this->birthDate = $birthDate;
return $this;
}
public function getDeathDate(): ?string
{
return $this->deathDate;
}
public function setDeathDate(string $deathDate): static
{
$this->deathDate = $deathDate;
return $this;
}
public function getPlaces(): ?string
{
return $this->places;
}
public function setPlaces(string $places): static
{
$this->places = $places;
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->subjectHeadings;
}
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;
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Repository;
use App\Entity\Collector;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
/**
* @extends ServiceEntityRepository<Collector>
*/
class CollectorRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Collector::class);
}
public function findAllByBibliography(int $biblioId): ?ArrayCollection
{
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
$rsm->addRootEntityFromClassMetadata('App\Entity\Collector', 'c');
$query = $this->getEntityManager()->createNativeQuery(
"SELECT
id,
stato,
editor,
nome_pers,
luoghi_att_pers
FROM collector c
JOIN rel_riferimento_personaggio
ON Personaggio_id_pers = id
WHERE Bibliografia_id_bib = :biblioId",
$rsm
);
$query->setParameter('biblioId', $biblioId);
$collectors = new ArrayCollection($query->getResult());
return $collectors;
}
}

View File

@ -0,0 +1,89 @@
{% extends 'data_entry.html.twig' %}
{% block title %}Collector - {{ record.name }} | ArCOA{% endblock %}
{% block rightpanel %}
<div class="container" style="max-width: 60vw">
<h1 class="is-size-1 mt-0 has-text-centered">Collector</h1>
<h2 class="is-size-3 mt-3 has-text-centered">{{ record.name }}</h2>
<article class="message is-info mt-3">
<div class="message-body">
<p>
<strong>Last modified:</strong> {{ record.modifiedAt.format('Y-m-d') }}
at {{ record.modifiedAt.format('H:i:s') }}
</p>
<p><strong>Editor:</strong> {{ record.editor }}</p>
</div>
</article>
<div class="card p-5">
{% if is_granted('ROLE_ADMIN') or is_granted('ROLE_REVISOR') %}
<div class="columns">
<div class="column is-half"></div>
<div class="column has-text-right">
<button class="button is-link">
Edit
<span class="icon ml-2">
<i class="fa fa-edit"></i>
</span>
</button>
<button class="button is-link">
Copy
<span class="icon ml-2">
<i class="fa fa-copy"></i>
</span>
</button>
<button class="button is-danger">
Delete
<span class="icon ml-2">
<i class="fa fa-trash"></i>
</span>
</button>
</div>
</div>
{% endif %}
<div class="tabs is-boxed is-fullwidth">
<ul>
<li class="is-active">Record</li>
<li>Relations</li>
</ul>
</div>
<div class="data-tabs" id="record">
<table class="table is-fullwidth pt-4 record">
<tr><th>Record ID</th><td>{{ record.id }}</td></tr>
<tr><th>Status</th><td>{{ record.getStatus() }}</td></tr>
<tr><th>Editor(s)</th><td>{{ record.editor }}</td></tr>
<tr><th>Name</th><td>{{ record.name }}</td></tr>
<tr><th>Date of birth</th><td>{{ record.birthDate }}</td></tr>
<tr><th>Date of death</th><td>{{ record.deathDate }}</td></tr>
<tr><th>Places / areas of activity</th><td>{{ record.places }}</td></tr>
<tr><th>Description</th><td>{{ record.description }}</td></tr>
<tr><th>Short description</th><td>{{ record.shortDescription }}</td></tr>
<tr><th>External identifier(s)</th><td>{{ record.externalIdentifier }}</td></tr>
<tr><th>External link(s)</th><td>{{ record.link }}</td></tr>
<tr><th>Subject headings</th><td>{{ record.subjectHeadings }}</td></tr>
<tr><th>ArCOA URI</th><td>{{ record.uri }}</td></tr>
<tr><th>Editorial notes</th><td>{{ record.notes }}</td></tr>
</table>
</div>
<div class="data-tabs is-hidden" id="relations">
{% if record.bibliographies %}
<p class="p-4 has-text-bold">Bibliographies</p>
<table class="table is-fullwidth is-hoverable has-text-centered">
<tr><th>ID</th><th>Status</th><th>Citation</th><th>Editor</th><th>Reference</th></tr>
{% for biblio in record.bibliographies %}
<tr>
<td><a href="{{ path('app_bibliography', {'id' : biblio.id}) }}">{{ biblio.id }}</a></td>
<td><a href="{{ path('app_bibliography', {'id' : biblio.id}) }}">{{ biblio.citation }}</a></td>
<td>{{ biblio.status }}</td>
<td>{{ biblio.editor }}</td>
<td>{{ biblio.reference }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
</div>
</div>
<script type="text/javascript" defer></script>
{% endblock %}

View File

@ -0,0 +1,88 @@
{% extends 'data_entry.html.twig' %}
{% block title %}Collection | ArCOA{% endblock %}
{% block rightpanel %}
<div class="container" style="max-width: 60vw">
<h1 class="is-size-1 mt-0 has-text-centered">Collection</h1>
<h2 class="is-size-3 mt-3 has-text-centered">Choose action</h2>
{% for message in app.flashes('notice') %}
<div class=" mt-4 notification is-success">
<button class="delete"></button>
{{ message }}
</div>
{% endfor %}
<div class="card p-5 mt-6 pt-6 pb-6">
<div class="columns">
<div class="column is-half has-text-centered">
<button class="button is-medium">
Search
<span class="icon ml-2">
<i class="fa fa-search"></i>
</span>
</button>
</div>
{% if is_granted('ROLE_ADMIN') or is_granted('ROLE_REVISOR') or is_granted('ROLE_EDITOR') %}
<div class="column has-text-centered">
<a href="" class="button is-link is-medium">
Add new
<span class="icon ml-2">
<i class="fa fa-plus"></i>
</span>
</a>
</div>
{% endif %}
</div>
</div>
<h3 class="has-text-centered is-size-4 mt-6">Records</h3>
<p class="pt-4 pb-4"><strong>{{ count }} result(s) found</strong></p>
<table class="table is-hoverable is-fullwidth mt-5 has-text-centered results">
<tr>
<th>ID</th>
<th>Title</th>
<th>Status</th>
<th>Editor</th>
<th>Chronology</th>
<th>Last modified</th>
<th>Actions</th>
</tr>
{% for record in records %}
<tr>
<td><a href="{{ path('app_collection', {'id' : record.id}) }}">{{ record.id }}</a></td>
<td><a href="{{ path('app_collection', {'id' : record.id}) }}">{{ record.title }}</a></td>
<td>{{ record.status }}</td>
<td>{{ record.owner }}</td>
<td style="max-width: 350px;">{{ record.chronology }}</td>
<td>
{{ record.modifiedAt.format('Y-m-d') }}<br>
{{ record.editor }} at {{ record.modifiedAt.format('H:i:s') }}
</td>
<td style="min-width: 120px;">
<div class="buttons">
<button class="button is-small is-link" title="Edit record">
<span class="icon">
<i class="fa fa-edit"></i>
</span>
</button>
<button class="button is-small is-danger" title="Delete record">
<span class="icon">
<i class="fa fa-trash"></i>
</span>
</button>
</div>
</td>
</tr>
{% endfor %}
</table>
</div>
<script type="text/javascript" defer>
const delBtns = document.querySelectorAll('.delete');
for (let btn of delBtns) {
btn.addEventListener('click', function () {
this.parentElement.classList.add('is-hidden');
})
}
</script>
{% endblock %}