diff --git a/src/Twig/UserExtension.php b/src/Twig/UserExtension.php index 3cf76e63..81ff0857 100644 --- a/src/Twig/UserExtension.php +++ b/src/Twig/UserExtension.php @@ -43,11 +43,7 @@ namespace App\Twig; use Twig\Attribute\AsTwigFilter; use Twig\Attribute\AsTwigFunction; -use App\Entity\Base\AbstractDBElement; use App\Entity\UserSystem\User; -use App\Entity\LogSystem\AbstractLogEntry; -use App\Repository\LogEntryRepository; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken; @@ -58,28 +54,11 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException; */ final readonly class UserExtension { - private LogEntryRepository $repo; - public function __construct(EntityManagerInterface $em, + public function __construct( private Security $security, private UrlGeneratorInterface $urlGenerator) { - $this->repo = $em->getRepository(AbstractLogEntry::class); - } - - /** - * Returns the user which has edited the given entity the last time. - */ - #[AsTwigFunction('last_editing_user')] - public function lastEditingUser(AbstractDBElement $element): ?User - { - return $this->repo->getLastEditingUser($element); - } - - #[AsTwigFunction('creating_user')] - public function creatingUser(AbstractDBElement $element): ?User - { - return $this->repo->getCreatingUser($element); } /** diff --git a/src/Twig/UserRepoExtension.php b/src/Twig/UserRepoExtension.php new file mode 100644 index 00000000..51ac113c --- /dev/null +++ b/src/Twig/UserRepoExtension.php @@ -0,0 +1,56 @@ +. + */ + +declare(strict_types=1); + + +namespace App\Twig; + +use App\Entity\Base\AbstractDBElement; +use App\Entity\UserSystem\User; +use App\Repository\LogEntryRepository; +use Doctrine\ORM\EntityManagerInterface; +use Twig\Attribute\AsTwigFunction; + +final readonly class UserRepoExtension +{ + + public function __construct(private EntityManagerInterface $entityManager) + { + } + + /** + * Returns the user which has edited the given entity the last time. + */ + #[AsTwigFunction('creating_user')] + public function creatingUser(AbstractDBElement $element): ?User + { + return $this->entityManager->getRepository(LogEntryRepository::class)->getCreatingUser($element); + } + + /** + * Returns the user which has edited the given entity the last time. + */ + #[AsTwigFunction('last_editing_user')] + public function lastEditingUser(AbstractDBElement $element): ?User + { + return $this->entityManager->getRepository(LogEntryRepository::class)->getLastEditingUser($element); + } +}