<?php
namespace App\Controller\Front\Channel;
use App\Entity\Channel\Channel;
use App\Service\Scholar\TrainingTransformerService;
use Nellapp\Bundle\SDKBundle\Permission\ChannelUserPermissionService;
use Nellapp\Bundle\SDKBundle\Permission\Enum\ChannelUserPermissionEnum;
use Nellapp\Bundle\SDKBundle\Routing\Utils\ChannelMainDomainUtils;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Repository\Scholar\TrainingRepository;
use App\Service\Advice\AdviceManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
class ShowController extends AbstractController
{
public function __construct(
private TrainingRepository $trainingRepository,
private AdviceManager $adviceManager,
private ChannelUserPermissionService $channelUserPermissionService,
private ChannelMainDomainUtils $channelMainDomainUtils,
private RouterInterface $router,
private TrainingTransformerService $trainingTransformerService,
)
{
}
#[Route(path: '/channel/{channelId}', name: 'front_channel_show')]
#[ParamConverter('channel', options: ['id' => 'channelId'])]
public function __invoke(Request $request, Channel $channel): Response
{
$requestChannel = $this->channelMainDomainUtils->getChannelFromRequest();
if ($requestChannel !== null && $requestChannel !== $channel || $requestChannel === null && $channel->getWhiteLabel() !== null) {
$domain = $this->channelMainDomainUtils->getMainDomainForChannelWhiteLabel($channel->getWhiteLabel());
$this->channelMainDomainUtils->applyChannelDomainToContext($this->router, $domain);
return $this->redirectToRoute('front_channel_show', [
'channelId' => $channel->getId(),
]);
}
$lastFourTrainings = $this->trainingRepository->findByOwnerChannelOrderByAvgMarkDesc($channel, 4, true);
$lastFourTrainingsDTOs = $this->trainingTransformerService->toDTOs($lastFourTrainings);
$countTrainings = $this->trainingRepository->countByOwnerChannel($channel);
$teachers = $this->channelUserPermissionService->getAllUserForGivenPermissions($channel, ChannelUserPermissionEnum::CHANNEL_USER_PERM_TRAINING_MANAGE_COMMENT);
$advices = $this->adviceManager->getAllAdvicesOfTrainingsByChannel($channel);
return $this->render('Front/Channel/show.html.twig', [
'channel' => $channel,
'last_four_trainings' => $lastFourTrainingsDTOs,
'count_trainings' => $countTrainings,
'teachers' => $teachers,
'advices' => $advices,
'disable_header_search' => true,
]);
}
}