src/Controller/AuthcompController.php line 23

Open in your IDE?
  1. <?php namespace App\Controller;
  2. use App\Entity\Authcomp;
  3. use App\Repository\AuthcompRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. /**
  8. * Author, Composer, Arranger controller
  9. */
  10. class AuthcompController extends AbstractController
  11. {
  12. private ManagerRegistry $doctrine;
  13. public function __construct(ManagerRegistry $doctrine) {
  14. $this->doctrine = $doctrine;
  15. }
  16. /**
  17. * @Symfony\Component\Routing\Annotation\Route("/authcomp/{type}/{id}", name="authcomp")
  18. */
  19. public function index(string $type, int $id): Response
  20. {
  21. $em = $this->doctrine->getManager();
  22. $repo = $em->getRepository(Authcomp::class);
  23. /** @var Authcomp $authcomp */
  24. $authcomp = $repo->findBy(['id' => $id], ['fullname' => 'ASC'])[0];
  25. $authHymns = $authcomp->getAuthHymns();
  26. $compHymns = $authcomp->getCompHymns();
  27. $arrHymns = $authcomp->getArrHymns();
  28. return $this->render('authcomp/index.html.twig', [
  29. 'authcomp' => $authcomp,
  30. 'type' => $type,
  31. 'authHymns' => $authHymns,
  32. 'compHymns' => $compHymns,
  33. 'arrHymns' => $arrHymns,
  34. ]);
  35. }
  36. /**
  37. * @Symfony\Component\Routing\Annotation\Route("/authors", name="authors")
  38. */
  39. public function auth(): Response
  40. {
  41. $authors = $this->getAuthCompByType(1);
  42. return $this->render('authcomp/authors.html.twig', [
  43. 'authors' => $authors,
  44. ]);
  45. }
  46. /**
  47. * @Symfony\Component\Routing\Annotation\Route("/composers", name="composers")
  48. */
  49. public function comp(): Response
  50. {
  51. $composers = $this->getAuthCompByType(2);
  52. return $this->render('authcomp/composers.html.twig', [
  53. 'composers' => $composers,
  54. ]);
  55. }
  56. /**
  57. * @Symfony\Component\Routing\Annotation\Route("/arrangers", name="arrangers")
  58. */
  59. public function arrn(): Response
  60. {
  61. $arrangers = $this->getAuthCompByType(3);
  62. return $this->render('authcomp/arrangers.html.twig', [
  63. 'arrangers' => $arrangers,
  64. ]);
  65. }
  66. /**
  67. * @param int $typeId
  68. * @return array
  69. */
  70. protected function getAuthCompByType(int $typeId): array
  71. {
  72. /** @var AuthcompRepository $repo */
  73. $repo = $this->doctrine->getRepository(Authcomp::class);
  74. return $repo->findAllByAuthCompId($typeId);
  75. }
  76. }