Copy record for bibliography
This commit is contained in:
@@ -18,7 +18,6 @@ class BibliographyController extends AbstractController
|
||||
#[Route('/bibliography/{id<\d+>}', name: 'app_bibliography')]
|
||||
public function index(Bibliography $bibliography, EntityManagerInterface $em): Response
|
||||
{
|
||||
|
||||
$repo = $em->getRepository(Collection::class);
|
||||
$collections = $repo->findAllByBibliography($bibliography->getId());
|
||||
$repo = $em->getRepository(Collector::class);
|
||||
@@ -37,7 +36,7 @@ class BibliographyController extends AbstractController
|
||||
public function landing(EntityManagerInterface $em): Response
|
||||
{
|
||||
$repo = $em->getRepository(Bibliography::class);
|
||||
$records = $repo->findBy([], ['modifiedAt' => 'DESC']);
|
||||
$records = $repo->findBy([], ['id' => 'DESC']);
|
||||
$count = count($records);
|
||||
|
||||
$records = array_slice($records, 0, 15);
|
||||
@@ -91,4 +90,42 @@ class BibliographyController extends AbstractController
|
||||
|
||||
return $this->redirectToRoute('app_bibliography_landing');
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Permissions! Return JSON with 403 when AJAX
|
||||
*/
|
||||
#[Route('/bibliography/copy/{id<\d+>}', name: 'app_bibliography_copy')]
|
||||
public function copy(Bibliography $bibliography, EntityManagerInterface $em): Response
|
||||
{
|
||||
try {
|
||||
$this->denyAccessUnlessGranted(RecordVoter::EDIT, $bibliography);
|
||||
}
|
||||
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()}";
|
||||
|
||||
// TODO Move clone logic to __clone() in Entity or Repository
|
||||
$copy = clone $bibliography;
|
||||
$copy->setEditor($editor);
|
||||
$copy->setOwner($editor);
|
||||
$copy->setCreator($user->getUsername());
|
||||
$repo = $em->getRepository(Collection::class);
|
||||
$copy->setCollections(
|
||||
$repo->findAllByBibliography($bibliography->getId())
|
||||
);
|
||||
$repo = $em->getRepository(Collector::class);
|
||||
$copy->setCollectors(
|
||||
$repo->findAllByBibliography($bibliography->getId())
|
||||
);
|
||||
$copy->setCitation("{$bibliography->getCitation()} - Copy");
|
||||
|
||||
$em->persist($copy);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('app_bibliography', ['id' => $copy->getId()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user