Copy collection; Stimulus controller for vocabs (incomplete)

This commit is contained in:
2024-11-08 17:32:45 +01:00
parent 239240360e
commit dce0e1b693
10 changed files with 197 additions and 139 deletions

View File

@@ -12,6 +12,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use DateTimeImmutable;
class BibliographyController extends AbstractController
{
@@ -92,7 +93,7 @@ class BibliographyController extends AbstractController
}
/**
* @todo Permissions! Return JSON with 403 when AJAX
* @todo Move clone logic to __clone() in Entity or Repository
*/
#[Route('/bibliography/copy/{id<\d+>}', name: 'app_bibliography_copy')]
public function copy(Bibliography $bibliography, EntityManagerInterface $em): Response
@@ -108,24 +109,26 @@ class BibliographyController extends AbstractController
$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->findAllByBibliography($bibliography->getId())
);
$repo = $em->getRepository(Collector::class);
$copy->setCollectors(
$repo->findAllByBibliography($bibliography->getId())
$repo->findAllByBibliography($bibliography->getId())
);
$copy->setCitation("{$bibliography->getCitation()} - Copy");
$copy->setModifiedAt(new DateTimeImmutable());
$em->persist($copy);
$em->flush();
$this->addFlash('notice', 'Record copied successfully');
return $this->redirectToRoute('app_bibliography', ['id' => $copy->getId()]);
}
}