src/Controller/Front/InstructionCatalogController.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\DTO\InstructionViewDTO;
  4. use App\DTO\InstructionWithProgressDTO;
  5. use App\Entity\Instruction;
  6. use App\Entity\InstructionCategory;
  7. use App\Entity\User;
  8. use App\Repository\InstructionCategoryRepository;
  9. use App\Repository\InstructionRepository;
  10. use App\Repository\ProgressCheckListElementRepository;
  11. use App\Repository\ProgressInstructionRepository;
  12. use App\Repository\ProgressInstructionStepRepository;
  13. use App\Service\ConfigService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. class InstructionCatalogController extends AbstractController
  20. {
  21.     use FrontTraitController;
  22.     private $em;
  23.     private $instructionRepository;
  24.     private $instructionCategoryRepository;
  25.     public function __construct(EntityManagerInterface $em,
  26.                                 InstructionRepository $instructionRepository,
  27.                                 InstructionCategoryRepository $instructionCategoryRepository)
  28.     {
  29.         $this->em $em;
  30.         $this->instructionRepository $instructionRepository;
  31.         $this->instructionCategoryRepository $instructionCategoryRepository;
  32.     }
  33.     /**
  34.      * @Route("/", name="homepage", methods={"GET"})
  35.      */
  36.     public function homepage(Request $requeststring $reactSiteBaseUrl)
  37.     {
  38.         return $this->redirect($reactSiteBaseUrl);
  39.     }
  40.     /**
  41.      * @Route("/catalog", name="app_catalog", methods={"GET"})
  42.      */
  43.     public function roots(Request $requestInstructionCategoryRepository $repository)
  44.     {
  45.         $locale $request->cookies->get('locale''en');
  46.         /** @var InstructionCategory $root */
  47.         $root $repository->findOneBy(['slug' => 'root-'.$locale]);
  48.         $subCategories $repository->getChildrenWithActiveInstructions($root);
  49.         return $this->render('catalog/roots.html.twig', [
  50.             'rows' => $subCategories,
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/catalog/{slug}", name="app_catalog_category", methods={"GET"})
  55.      */
  56.     public function category(InstructionCategory $instructionCategory,
  57.                              InstructionRepository $instructionRepository,
  58.                              InstructionCategoryRepository $repository)
  59.     {
  60.         $category $repository->getJoinedActiveInstructions($instructionCategory);
  61.         $subCategories $repository->getChildrenWithActiveInstructions($instructionCategory);
  62.         $instructions = [];
  63.         /** @var Instruction $instruction */
  64.         foreach ($instructionCategory->getInstructions() as $instruction) {
  65.             if ($instruction->visible()) {
  66.                 $instructions[] = $instruction;
  67.             }
  68.         }
  69.         return $this->render('catalog/category.html.twig', [
  70.             'category' => $instructionCategory,
  71.             'instructions' => $instructions,
  72.             'subCategories' => $subCategories,
  73.         ]);
  74.     }
  75.     /**
  76.      * @Route("/catalog/{categorySlug}/{instructionSlug}/view", name="app_catalog_instruction_view_readonly", methods={"GET"})
  77.      */
  78.     public function viewReadonly(InstructionRepository $instructionRepository,
  79.                                  InstructionCategoryRepository $instructionCategoryRepository,
  80.                                  string $categorySlugstring $instructionSlug)
  81.     {
  82.         /** @var User $user */
  83.         $user $this->getUser();
  84.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED') OR
  85.             $this->isGranted('IS_AUTHENTICATED_FULLY ')
  86.         ) {
  87.             return $this->redirectToRoute('app_catalog_instruction_view', [
  88.                 'categorySlug' => $categorySlug,
  89.                 'instructionSlug' => $instructionSlug,
  90.             ]);
  91.         }
  92.         $instructionCategory $instructionCategoryRepository->findOneBy(['slug' => $categorySlug]);
  93.         $instruction $instructionRepository->findOneBy(['slug' => $instructionSlug]);
  94.         if (!isset($instructionCategory$instruction)) {
  95.             throw new NotFoundHttpException();
  96.         }
  97.         return $this->render('catalog/instruction_readonly.html.twig', [
  98.             'category' => $instructionCategory,
  99.             'instruction' => $instruction,
  100.         ]);
  101.     }
  102.     /**
  103.      * @Route("/catalog/{categorySlug}/{instructionSlug}", name="app_catalog_instruction_view", methods={"GET"})
  104.      */
  105.     public function instruction(InstructionRepository $instructionRepository,
  106.                                 ConfigService $configService,
  107.                                 string $categorySlugstring $instructionSlug)
  108.     {
  109.         /** @var User $user */
  110.         $user $this->getUser();
  111.         $instructionCategoryRepository $this->em->getRepository(InstructionCategory::class);
  112.         $instructionCategory $instructionCategoryRepository->findOneBy(['slug' => $categorySlug]);
  113.         $instruction $instructionRepository->findOneBy(['slug' => $instructionSlug]);
  114.         if (!isset($instructionCategory$instruction)) {
  115.             throw new NotFoundHttpException();
  116.         }
  117.         $root $instructionCategoryRepository->findOneBy(['slug' => $instructionCategory->getSlug()]);
  118.         $arrayTree $instructionCategoryRepository->children($root);
  119.         $showPaidServices $configService->get('show-paid-services-on-website');
  120.         if ($user) {
  121.             $dto = new InstructionWithProgressDTO($instruction$user$this->em$showPaidServices);
  122.         } else {
  123.             $dto = new InstructionViewDTO($instruction$this->em);
  124.         }
  125.         return $this->render('catalog/instruction.html.twig', [
  126.             'category' => $instructionCategory,
  127.             'instruction' => $dto,
  128.             'rows' => $arrayTree,
  129.             'showPaidServices' => $showPaidServices,
  130.         ]);
  131.     }
  132. }