<?php namespace App\Controller;
use App\Entity\Authcomp;
use App\Repository\AuthcompRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
/**
* Author, Composer, Arranger controller
*/
class AuthcompController extends AbstractController
{
private ManagerRegistry $doctrine;
public function __construct(ManagerRegistry $doctrine) {
$this->doctrine = $doctrine;
}
/**
* @Symfony\Component\Routing\Annotation\Route("/authcomp/{type}/{id}", name="authcomp")
*/
public function index(string $type, int $id): Response
{
$em = $this->doctrine->getManager();
$repo = $em->getRepository(Authcomp::class);
/** @var Authcomp $authcomp */
$authcomp = $repo->findBy(['id' => $id], ['fullname' => 'ASC'])[0];
$authHymns = $authcomp->getAuthHymns();
$compHymns = $authcomp->getCompHymns();
$arrHymns = $authcomp->getArrHymns();
return $this->render('authcomp/index.html.twig', [
'authcomp' => $authcomp,
'type' => $type,
'authHymns' => $authHymns,
'compHymns' => $compHymns,
'arrHymns' => $arrHymns,
]);
}
/**
* @Symfony\Component\Routing\Annotation\Route("/authors", name="authors")
*/
public function auth(): Response
{
$authors = $this->getAuthCompByType(1);
return $this->render('authcomp/authors.html.twig', [
'authors' => $authors,
]);
}
/**
* @Symfony\Component\Routing\Annotation\Route("/composers", name="composers")
*/
public function comp(): Response
{
$composers = $this->getAuthCompByType(2);
return $this->render('authcomp/composers.html.twig', [
'composers' => $composers,
]);
}
/**
* @Symfony\Component\Routing\Annotation\Route("/arrangers", name="arrangers")
*/
public function arrn(): Response
{
$arrangers = $this->getAuthCompByType(3);
return $this->render('authcomp/arrangers.html.twig', [
'arrangers' => $arrangers,
]);
}
/**
* @param int $typeId
* @return array
*/
protected function getAuthCompByType(int $typeId): array
{
/** @var AuthcompRepository $repo */
$repo = $this->doctrine->getRepository(Authcomp::class);
return $repo->findAllByAuthCompId($typeId);
}
}