src/Controller/Front/Channel/ShowController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front\Channel;
  3. use App\Entity\Channel\Channel;
  4. use App\Service\Scholar\TrainingTransformerService;
  5. use Nellapp\Bundle\SDKBundle\Permission\ChannelUserPermissionService;
  6. use Nellapp\Bundle\SDKBundle\Permission\Enum\ChannelUserPermissionEnum;
  7. use Nellapp\Bundle\SDKBundle\Routing\Utils\ChannelMainDomainUtils;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use App\Repository\Scholar\TrainingRepository;
  11. use App\Service\Advice\AdviceManager;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\Routing\RouterInterface;
  16. class ShowController extends AbstractController
  17. {
  18. public function __construct(
  19. private TrainingRepository $trainingRepository,
  20. private AdviceManager $adviceManager,
  21. private ChannelUserPermissionService $channelUserPermissionService,
  22. private ChannelMainDomainUtils $channelMainDomainUtils,
  23. private RouterInterface $router,
  24. private TrainingTransformerService $trainingTransformerService,
  25. ) {}
  26. #[Route(path: '/channel/{channelId}', name: 'front_channel_show')]
  27. #[ParamConverter('channel', options: ['id' => 'channelId'])]
  28. public function __invoke(Request $request, Channel $channel): Response
  29. {
  30. $requestChannel = $this->channelMainDomainUtils->getChannelFromRequest();
  31. if ($requestChannel !== null && $requestChannel !== $channel || $requestChannel === null && $channel->getWhiteLabel() !== null) {
  32. $domain = $this->channelMainDomainUtils->getMainDomainForChannelWhiteLabel($channel->getWhiteLabel());
  33. $this->channelMainDomainUtils->applyChannelDomainToContext($this->router, $domain);
  34. return $this->redirectToRoute('front_channel_show', [
  35. 'channelId' => $channel->getId(),
  36. ]);
  37. }
  38. $lastFourTrainings = $this->trainingRepository->findByOwnerChannelOrderByAvgMarkDesc($channel, 4, true);
  39. $lastFourTrainingsDTOs = $this->trainingTransformerService->toDTOs($lastFourTrainings);
  40. $countTrainings = $this->trainingRepository->countByOwnerChannel($channel);
  41. $teachers = $this->channelUserPermissionService->getAllUserForGivenPermissions($channel, ChannelUserPermissionEnum::CHANNEL_USER_PERM_TRAINING_MANAGE_COMMENT);
  42. $advices = $this->adviceManager->getAllAdvicesOfTrainingsByChannel($channel);
  43. return $this->render('Front/Channel/show.html.twig', [
  44. 'channel' => $channel,
  45. 'last_four_trainings' => $lastFourTrainingsDTOs,
  46. 'count_trainings' => $countTrainings,
  47. 'teachers' => $teachers,
  48. 'advices' => $advices,
  49. 'disable_header_search' => true,
  50. ]);
  51. }
  52. }