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

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.     {
  27.     }
  28.     #[Route(path'/channel/{channelId}'name'front_channel_show')]
  29.     #[ParamConverter('channel'options: ['id' => 'channelId'])]
  30.     public function __invoke(Request $requestChannel $channel): Response
  31.     {
  32.         $requestChannel $this->channelMainDomainUtils->getChannelFromRequest();
  33.         if ($requestChannel !== null && $requestChannel !== $channel || $requestChannel === null && $channel->getWhiteLabel() !== null) {
  34.             $domain $this->channelMainDomainUtils->getMainDomainForChannelWhiteLabel($channel->getWhiteLabel());
  35.             $this->channelMainDomainUtils->applyChannelDomainToContext($this->router$domain);
  36.             return $this->redirectToRoute('front_channel_show', [
  37.                 'channelId' => $channel->getId(),
  38.             ]);
  39.         }
  40.         $lastFourTrainings $this->trainingRepository->findByOwnerChannelOrderByAvgMarkDesc($channel4true);
  41.         $lastFourTrainingsDTOs $this->trainingTransformerService->toDTOs($lastFourTrainings);
  42.         $countTrainings $this->trainingRepository->countByOwnerChannel($channel);
  43.         $teachers $this->channelUserPermissionService->getAllUserForGivenPermissions($channelChannelUserPermissionEnum::CHANNEL_USER_PERM_TRAINING_MANAGE_COMMENT);
  44.         $advices $this->adviceManager->getAllAdvicesOfTrainingsByChannel($channel);
  45.         return $this->render('Front/Channel/show.html.twig', [
  46.             'channel' => $channel,
  47.             'last_four_trainings' => $lastFourTrainingsDTOs,
  48.             'count_trainings' => $countTrainings,
  49.             'teachers' => $teachers,
  50.             'advices' => $advices,
  51.             'disable_header_search' => true,
  52.         ]);
  53.     }
  54. }