+
+ + Last modified: {{ record.modifiedAt.format('Y-m-d') }} + at {{ record.modifiedAt.format('H:i:s') }} +
+Editor: {{ record.editor }}
+diff --git a/src/Controller/ConservationPlaceController.php b/src/Controller/ConservationPlaceController.php new file mode 100644 index 0000000..3ea8a3e --- /dev/null +++ b/src/Controller/ConservationPlaceController.php @@ -0,0 +1,104 @@ +}', name: 'app_conservation_place')] + public function index(ConservationPlace $conservationPlace, EntityManagerInterface $em): Response + { + return $this->render('conservation_place/index.html.twig', [ + 'controller_name' => 'ConservationPlaceController', + 'record' => $conservationPlace, + ]); + } + + #[Route('/conservation_place', name: 'app_conservation_place_landing')] + public function landing(EntityManagerInterface $em): Response + { + $repo = $em->getRepository(ConservationPlace::class); + $records = $repo->findBy([], ['id' => 'DESC']); + $count = count($records); + + $records = array_slice($records, 0, 15); + + return $this->render('conservation_place/landing.html.twig', [ + 'controller_name' => 'ConservationPlaceController', + 'records' => $records, + 'count' => $count, + ]); + } + + #[Route('/conservation_place/delete/{id<\d+>}', name: 'app_conservation_place_del')] + public function delete(ConservationPlace $conservationPlace, EntityManagerInterface $em): Response + { + try { + $this->denyAccessUnlessGranted(RecordVoter::DELETE, $conservationPlace); + } + catch (AccessDeniedException) { + $this->addFlash('warning', 'You are not authorized to delete this record'); + return $this->redirectToRoute('app_home'); + } + + if ($conservationPlace) { + $em->remove($conservationPlace); + $em->flush(); + } + + $this->addFlash('notice', 'Record deleted successfully'); + + return $this->redirectToRoute('app_conservation_place_landing'); + } + /** + * @todo Move clone logic to __clone() in Entity or Repository + */ + #[Route('/conservation_place/copy/{id<\d+>}', name: 'app_conservation_place_copy')] + public function copy(ConservationPlace $conservationPlace, EntityManagerInterface $em): Response + { + try { + $this->denyAccessUnlessGranted(RecordVoter::EDIT, $conservationPlace); + } + catch (AccessDeniedException) { + $this->addFlash('warning', 'You are not authorized to copy this record'); + return $this->redirectToRoute('app_home'); + } + + $user = $this->getUser(); + $editor = "{$user->getFirstname()} {$user->getLastName()}"; + + $copy = clone $conservationPlace; + $copy->setEditor($editor); + $copy->setOwner($editor); + $copy->setCreator($user->getUsername()); + $repo = $em->getRepository(Collection::class); + $copy->setCollections( + $repo->findAllByConservationPlace($conservationPlace->getId()) + ); + /* + $repo = $em->getRepository(Collector::class); + $copy->setCollectors( + $repo->findAllByBibliography($bibliography->getId()) + ); + */ + $copy->setPlace("{$conservationPlace->getPlace()} - Copy"); + $copy->setModifiedAt(new \DateTimeImmutable()); + $copy->setStatus(RecordStatus::Draft->value); + + $em->persist($copy); + $em->flush(); + + $this->addFlash('notice', 'Record copied successfully'); + + return $this->redirectToRoute('app_conservation_place', ['id' => $copy->getId()]); + } +} diff --git a/src/Entity/ConservationPlace.php b/src/Entity/ConservationPlace.php index ed45aed..c7d5ed4 100644 --- a/src/Entity/ConservationPlace.php +++ b/src/Entity/ConservationPlace.php @@ -3,15 +3,15 @@ namespace App\Entity; use App\RecordInterface; -use App\Repository\ConservationRepository; +use App\Repository\ConservationPlaceRepository; 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: ConservationRepository::class)] -#[ORM\Table(name: 'collection')] +#[ORM\Entity(repositoryClass: ConservationPlaceRepository::class)] +#[ORM\Table(name: 'conservation_place')] class ConservationPlace implements RecordInterface { #[ORM\Id] @@ -35,10 +35,10 @@ class ConservationPlace implements RecordInterface private ?string $region = null; #[ORM\Column(name: 'prov_cons', type: Types::TEXT)] - private ?int $province = null; + private ?string $province = null; #[ORM\Column(name: 'com_cons', type: Types::TEXT)] - private ?int $municipality = null; + private ?string $municipality = null; #[ORM\Column(name: 'desc_cons', type: Types::TEXT)] private ?string $description = null; @@ -291,7 +291,7 @@ class ConservationPlace implements RecordInterface return $this->collections; } - public function setBibliographies(DoctrineCollection $collections): static + public function setCollections(DoctrineCollection $collections): static { $this->collections = $collections; diff --git a/src/Repository/CollectionRepository.php b/src/Repository/CollectionRepository.php index 58bdefe..d55d431 100644 --- a/src/Repository/CollectionRepository.php +++ b/src/Repository/CollectionRepository.php @@ -48,4 +48,29 @@ class CollectionRepository extends ServiceEntityRepository return $collections; } + + public function findAllByConservationPlace(int $placeId): ?ArrayCollection + { + $rsm = new ResultSetMappingBuilder($this->getEntityManager()); + $rsm->addRootEntityFromClassMetadata('App\Entity\Collection', 'c'); + + $query = $this->getEntityManager()->createNativeQuery( + "SELECT + id, + stato, + editor, + tit_coll, + data_coll + FROM collection c + JOIN rel_conservazione_collezione + ON Collezione_id_coll = id + WHERE Conservazione_id_cons = :placeId", + $rsm + ); + $query->setParameter('placeId', $placeId); + + $collections = new ArrayCollection($query->getResult()); + + return $collections; + } } diff --git a/src/Repository/ConservationPlaceRepository.php b/src/Repository/ConservationPlaceRepository.php new file mode 100644 index 0000000..6942416 --- /dev/null +++ b/src/Repository/ConservationPlaceRepository.php @@ -0,0 +1,78 @@ + + */ +class ConservationPlaceRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ConservationPlace::class); + } + + public function hasCreatorEditor(string $creator): bool + { + $em = $this->getEntityManager(); + $repo = $em->getRepository(User::class); + + $creator = $repo->findOneBy(['username' => $creator]); + + return in_array('ROLE_EDITOR', $creator->getRoles()); + } + + public function findAllByCollection(int $collectionId): ?ArrayCollection + { + $rsm = new ResultSetMappingBuilder($this->getEntityManager()); + $rsm->addRootEntityFromClassMetadata('App\Entity\ConservationPlace', 'c'); + + $query = $this->getEntityManager()->createNativeQuery( + "SELECT + id, + stato, + editor, + luogo_cons, + com_cons + FROM conservation_place c + JOIN rel_conservazione_collezione + ON Conservazione_id_cons = id + WHERE Collezione_id_coll = :collId", + $rsm + ); + $query->setParameter('collId', $collectionId); + + return new ArrayCollection($query->getResult()); + } + + public function findAllByObject(int $objectId): ?ArrayCollection + { + $rsm = new ResultSetMappingBuilder($this->getEntityManager()); + $rsm->addRootEntityFromClassMetadata('App\Entity\ConservationPlace', 'c'); + + $query = $this->getEntityManager()->createNativeQuery( + "SELECT + id, + stato, + editor, + luogo_cons, + com_cons + FROM conservation_place c + JOIN rel_conservazione_reperto + ON Conservazione_id_cons = id + WHERE Reperto_id_rep = :objectId", + $rsm + ); + $query->setParameter('objectId', $objectId); + + return new ArrayCollection($query->getResult()); + } +} diff --git a/templates/bibliography/index.html.twig b/templates/bibliography/index.html.twig index f744d18..039e6d7 100644 --- a/templates/bibliography/index.html.twig +++ b/templates/bibliography/index.html.twig @@ -4,6 +4,17 @@ {% block rightpanel %}
Record ID | {{ record.id }} |
---|---|
Status | {{ record.getStatus() }} |
Editor(s) | {{ record.editor }} |
Conservation place | {{ record.place }} |
Region | {{ record.region }} |
Province | {{ record.province }} |
Municipality | {{ record.municipality }} |
Description | {{ record.description }} |
Short description | {{ record.shortDescription }} |
External identifier(s) | {{ record.externalIdentifier }} |
External link(s) | {{ record.link }} |
Subject headings | {{ record.subjectHeadings }} |
ArCOA URI | arcoa.cnr.it/conservation_place/{{ record.id }} |
Editorial notes | {{ record.notes }} |
Delete record?
+ +{{ count }} result(s) found
+ID | +Place | +Status | +Editor | +Municipality | +Last modified | +Actions | +
---|---|---|---|---|---|---|
{{ record.id }} | ++ + {{ record.place }} + + | +{{ record.status }} | +{{ record.owner }} | +{{ record.municipality }} | +
+ {{ record.modifiedAt.format('Y-m-d') }} + {{ record.editor }} at {{ record.modifiedAt.format('H:i:s') }} + |
+ + | + +
Delete record?
+ +