src/Controller/CareerPathController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\CareerPath;
  4. use App\Repository\CareerPathRepository;
  5. use App\Repository\CareerPathCategoryRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Doctrine\Common\Collections\Criteria;
  11. /**
  12. * @Route("/career-paths")
  13. */
  14. class CareerPathController extends AbstractController {
  15.     /**
  16.      * CareerPath List.
  17.      * @Route(
  18.      *      "/list/{page}/{sort}/{dir}",
  19.      *      name="client_career_path_list",
  20.      *      methods={"GET","POST"},
  21.      *      requirements={"page"="\d+","sort"="[0-9a-zA-Z\.]+","dir"="asc|desc"},
  22.      *      defaults={"page"=1,"sort"="createdAt","dir"="desc"}
  23.      *  )
  24.      *
  25.      * @return string
  26.      */
  27.     public function list(
  28.         Request $request$page$sort$dir,
  29.         \App\Service\SeoHelper $seoHelper,
  30.         CareerPathRepository $careerPathRepository
  31.     ): Response {
  32.         $limit $request->query->getInt('limit'20);
  33.         $seoHelper->setInternalSeo('CareerPaths''client_career_path_list');
  34.         $criteria Criteria::create();
  35.         $criteria->andWhere(Criteria::expr()->eq('isEnabled'true));
  36.         $criteria->orderBy([$sort => $dir]);
  37.         //$totalCriteria->andWhere(Criteria::expr()->eq('isDeceased', false));
  38.         $entries $careerPathRepository->matching($criteria);
  39.         $entries $entries->slice(($page-1)*$limit$limit);
  40.         $total $careerPathRepository->countAll();
  41.         $pages ceil($total/$limit);
  42.         return $this->render('client/career-paths/list.html.twig', [
  43.             'title' => 'Career Paths',
  44.             'listParams' => [],
  45.             'entries' => $entries,
  46.             'ordering' => [
  47.                 'sort' => $sort,
  48.                 'dir' => $dir
  49.             ],
  50.             'meta' => [
  51.                 'title' => 'CareerPaths',
  52.                 'type' => 'website',
  53.             ],
  54.             'page' => [
  55.                 'icon' => 'list',
  56.                 'title' => 'CareerPaths',
  57.                 'subtitle' => 'View the list with the CareerPaths',
  58.                 'header' => 'Training Manager - CareerPaths List'
  59.             ],
  60.             'pagination' => [
  61.                 'listURL' => 'client_career_path_list',
  62.                 'totalSearch' => $total,
  63.                 'total' => $total,
  64.                 'limit' => $limit,
  65.                 'totalPages' => $pages,
  66.                 'page' => $page,
  67.             ],
  68.         ]);
  69.     }
  70.     /**
  71.      * CareerPath Category List.
  72.      * @Route(
  73.      *      "/category/{slug}/{page}/{sort}/{dir}",
  74.      *      name="client_career_path_category_list",
  75.      *      methods={"GET","POST"},
  76.      *      requirements={"page"="\d+","sort"="[0-9a-zA-Z\.]+","dir"="asc|desc"},
  77.      *      defaults={"page"=1,"sort"="createdAt","dir"="desc"}
  78.      *  )
  79.      *
  80.      * @return string
  81.      */
  82.     public function category(
  83.         Request $request$page$sort$dir$slug,
  84.         \App\Service\SeoHelper $seoHelper,
  85.         CareerPathCategoryRepository $careerPathCategoryRepository
  86.     ): Response {
  87.         $limit $request->query->getInt('limit'20);
  88.         $category $careerPathCategoryRepository->findOneBy(["slug" => $slug"isEnabled" => true], ["createdAt" => "Desc"]);
  89.         if (!$category) throw $this->createNotFoundException('The career path category does not exist');
  90.         $seoHelper->setCareerPathCategorySeo($category);
  91.         $entries $category->getCareerPathOrdering();
  92.         $total $entries->count();
  93.         $entries $entries->slice(($page-1)*$limit$limit);
  94.         $pages ceil($total/$limit);
  95.         return $this->render('client/career-paths/category.html.twig', [
  96.             'title' => $category->getTitle(),
  97.             'listParams' => [],
  98.             'entries' => $entries,
  99.             'ordering' => [
  100.                 'sort' => $sort,
  101.                 'dir' => $dir
  102.             ],
  103.             'page' => [
  104.                 'icon' => 'list',
  105.                 'title' => 'Career Paths',
  106.                 'subtitle' => 'View the list with the Career Paths',
  107.                 'header' => 'Training Manager - Career Paths List',
  108.             ],
  109.             'meta' => [
  110.                 'title' => $category->getTitle(),
  111.                 'type' => 'website',
  112.                 'description' => $category->getMetaDescription(),
  113.                 'keywords' => $category->getMetaKeywords()
  114.             ],
  115.             'pagination' => [
  116.                 'listURL' => 'client_career_path_list',
  117.                 'totalSearch' => $total,
  118.                 'total' => $total,
  119.                 'limit' => $limit,
  120.                 'totalPages' => $pages,
  121.                 'page' => $page,
  122.             ],
  123.         ]);
  124.     }
  125.     /**
  126.      * @Route("assignCareerPath", name="client_assign_career_path", methods={"POST"})
  127.      */
  128.     public function assignCareerPath(
  129.         Request $request,
  130.         \App\Repository\CareerPathRepository $careerPathRepository,
  131.         \Symfony\Contracts\Translation\TranslatorInterface $translator,
  132.         \Doctrine\Persistence\ManagerRegistry $managerRegistry
  133.     ): Response {
  134.         $returnURL null;
  135.         $careerPath $careerPathRepository->find($request->request->get('careerPath'));
  136.         if ($careerPath && $this->isCsrfTokenValid('addcareerpath'$request->request->get('_csrf_token'))) {
  137.             $entityManager $managerRegistry->getManager();
  138.             $userCareerPath = new \App\Entity\UserCareerPath();
  139.             $userCareerPath->setUser($this->getUser());
  140.             $userCareerPath->setCareerPath($careerPath);
  141.             $entityManager->persist($userCareerPath);
  142.             $entityManager->flush();
  143.             $this->addFlash(
  144.                 'success',
  145.                 $translator->trans('Career Path was added to your Paths successfully!')
  146.             );
  147.         } else {
  148.             $this->addFlash(
  149.                 'danger',
  150.                 $translator->trans('Invalid Token!')
  151.             );
  152.         }
  153.         return $this->redirectToRoute('client_career_path_view', ['slug' => $careerPath->getSlug()]);
  154.     }
  155.     /**
  156.      * @Route("/view/{slug}", name="client_career_path_view", methods={"GET"})
  157.      */
  158.     public function show(
  159.         CareerPathRepository $careerPathRepository,
  160.         \App\Repository\UserCareerPathRepository $userCareerPathRepository,
  161.         \App\Service\SeoHelper $seoHelper,
  162.         $slug
  163.     ): Response {
  164.         $careerPath $careerPathRepository->findOneBy(['slug' => $slug'isEnabled' => true]);
  165.         if (!$careerPath) throw $this->createNotFoundException('The career path not exist');
  166.         $courses $careerPath->getCoursesOrdering();
  167.         $userActive $userCareerPathRepository->findOneBy(['user' => $this->getUser(), 'careerPath' => $careerPath]);
  168.         $seoHelper->setCareerPathSeo($careerPath);
  169.         return $this->render('client/career-paths/show.html.twig', [
  170.             'title' => $careerPath->getTitle(),
  171.             'page' => [
  172.                 'icon' => 'star',
  173.                 'title' => $careerPath->getTitle()
  174.             ],
  175.             'userActive' => $userActive?true:false,
  176.             'entry' => $careerPath,
  177.             'courses' => $courses
  178.         ]);
  179.     }
  180. }