src/Controller/Website/HomeController.php line 487

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use EADPlataforma\Entity\Faq;
  9. use EADPlataforma\Entity\Forum;
  10. use EADPlataforma\Entity\Banner;
  11. use EADPlataforma\Entity\User;
  12. use EADPlataforma\Entity\Enrollment;
  13. use EADPlataforma\Entity\Course;
  14. use EADPlataforma\Entity\CourseCertificate;
  15. use EADPlataforma\Entity\CourseTestimonial;
  16. use EADPlataforma\Entity\Product;
  17. use EADPlataforma\Entity\ProductOffer;
  18. use EADPlataforma\Entity\Whishlist;
  19. use EADPlataforma\Entity\Category;
  20. use EADPlataforma\Entity\Client;
  21. use EADPlataforma\Entity\PageSection;
  22. use EADPlataforma\Enum\AbstractEnum;
  23. use EADPlataforma\Enum\FaqEnum;
  24. use EADPlataforma\Enum\ClientEnum;
  25. use EADPlataforma\Enum\UserEnum;
  26. use EADPlataforma\Enum\ForumEnum;
  27. use EADPlataforma\Enum\BannerEnum;
  28. use EADPlataforma\Enum\CourseEnum;
  29. use EADPlataforma\Enum\ProductEnum;
  30. use EADPlataforma\Enum\CourseCertificateEnum;
  31. use EADPlataforma\Enum\CourseTestimonialEnum;
  32. use EADPlataforma\Enum\WhishlistEnum;
  33. use EADPlataforma\Enum\EnrollmentEnum;
  34. use EADPlataforma\Enum\PageSectionEnum;
  35. use EADPlataforma\Util\StringUtil;
  36. use \setasign\FpdiProtection\FpdiProtection;
  37. use \setasign\Fpdi\Fpdi;
  38. /**
  39.  * @Route(
  40.  *      schemes         = {"http|https"}
  41.  * )
  42.  * @Cache(
  43.  *      maxage          = "0",
  44.  *      smaxage         = "0",
  45.  *      expires         = "now",
  46.  *      public          = false
  47.  * )
  48.  */
  49. class HomeController extends AbstractWebsiteController {
  50.     /**
  51.      * @Route(
  52.      *      path          = "/",
  53.      *      name          = "home",
  54.      *      methods       = {"GET"}
  55.      * )
  56.      */
  57.     public function homePage(Request $request) {
  58.         if(!$this->isPlatformActive()){
  59.             $this->data['platformStatus'] = $this->clientConfig->getPlatformStatus();
  60.           
  61.             return $this->renderEAD('home/restricted.html.twig');
  62.         }
  63.         $productOfferRepository $this->em->getRepository(ProductOffer::class);
  64.         $platformType $this->client->getPlatformType();
  65.         if($platformType == ClientEnum::PLATFORM_TYPE_RESTRICTED){
  66.             $numberOffer $productOfferRepository->countPublicProductOffers();
  67.             if(!$this->user || empty($numberOffer)){
  68.                 return $this->redirectToRoute('resume');
  69.             }
  70.         }
  71.         $banners null;
  72.         if($this->configuration->isModuleActive("banner_module")){
  73.             $bannerRepository $this->em->getRepository(Banner::class);
  74.             $banners $bannerRepository->findItems(true);
  75.         }
  76.         $faqs null;
  77.         if($this->configuration->isModuleActive("faq_module")){
  78.             $faqRepository $this->em->getRepository(Faq::class);
  79.             $faqs $faqRepository->findByEAD([
  80.                 "type" => FaqEnum::GENERAL,
  81.                 "deleted" => FaqEnum::ITEM_NO_DELETED,
  82.             ], [ "order" => "ASC" ]);
  83.         }
  84.         $courseTestimonialRepository $this->em->getRepository(CourseTestimonial::class);
  85.         $courseTestimonials $courseTestimonialRepository->getTestimonialApprovedRandom();
  86.         foreach ($courseTestimonials as $key => $value) {
  87.             $value['testimonial'] = StringUtil::encodeStringStatic($value['testimonial']);
  88.             $value['userName'] = StringUtil::encodeStringStatic($value['userName']);
  89.             $courseTestimonials[$key] = $value;
  90.         }
  91.         $categoryRepository $this->em->getRepository(Category::class);
  92.         $productCategories $categoryRepository->getCategories();
  93.         $userRepository $this->em->getRepository(User::class);
  94.         $teachers $userRepository->getUserTeacherSpotlightRandom(6);
  95.         $foumNumber $this->em->getRepository(Forum::class)->countEAD([
  96.             "forum" => null,
  97.             "deleted" => ForumEnum::ITEM_NO_DELETED,
  98.         ]);
  99.         $userNumber $userRepository->countAllUsers(UserEnum::ACTIVE);
  100.         $courseNumber $this->em->getRepository(Course::class)->countEAD([
  101.             "status" => CourseEnum::PUBLISHED,
  102.             "deleted" => CourseEnum::ITEM_NO_DELETED,
  103.         ]);
  104.         $courseCertificateRepository $this->em->getRepository(CourseCertificate::class);
  105.         $courseCertificateNumber $courseCertificateRepository->countEAD([
  106.             "deleted" => CourseCertificateEnum::ITEM_NO_DELETED,
  107.         ]);
  108.         $courseTestimonialNumber $courseTestimonialRepository->countEAD([
  109.             "status" => CourseTestimonialEnum::APPROVED,
  110.             "deleted" => CourseTestimonialEnum::ITEM_NO_DELETED,
  111.         ]);
  112.         $this->data['banners'] = $banners;
  113.         $this->data['faqs'] = $faqs;
  114.         $this->data['courseTestimonials'] = $courseTestimonials;
  115.         $this->data['productCategories'] = $productCategories;
  116.         $this->data['foumNumber'] = $foumNumber;
  117.         $this->data['userNumber'] = $userNumber;
  118.         $this->data['courseNumber'] = $courseNumber;
  119.         $this->data['courseCertificateNumber'] = $courseCertificateNumber;
  120.         $this->data['courseTestimonialNumber'] = $courseTestimonialNumber;
  121.         $sectionConfigHome json_decode($this->configuration->get('section_config_home'));
  122.         $pageSectionRepository $this->em->getRepository(PageSection::class);
  123.         $pageSections $pageSectionRepository->findBy([
  124.             "status" => PageSectionEnum::PUBLISHED,
  125.             "deleted" => PageSectionEnum::ITEM_NO_DELETED
  126.         ], [ "order" => "ASC"]);
  127.         $sections = [
  128.             "home_banner" => "bannerSection",
  129.             "search_bar" => "searchSection",
  130.         ];
  131.         foreach ($pageSections as $key => $pageSection) {
  132.             $idx "page-section-{$pageSection->getId()}";
  133.             $sections[$idx] = $pageSection;
  134.             if(!isset($sectionConfigHome->{$idx})){
  135.                 $sectionConfigHome->{$idx} = (object)[
  136.                     "active" => $pageSection->getStatus(),
  137.                     "background" => $pageSection->getBackground(),
  138.                     "order" => ($key 1),
  139.                 ];
  140.             }
  141.         }
  142.         $sectionConfigHome = (array)$sectionConfigHome;
  143.         uksort($sectionConfigHome, function($a$b) use($sectionConfigHome){
  144.             return $sectionConfigHome[$a]->order $sectionConfigHome[$b]->order;
  145.         });
  146.         $sections["home_categories"] = "productCategorySection";
  147.         $sections["home_teachers"] = "teacherSection";
  148.         $sections["home_numbers"] = "schoolNumberSection";
  149.         $sections["home_faq"] = "faqSection";
  150.         $sections["home_testimonial"] = "testimonialSection";
  151.         $sections["home_newsletter"] = "newsSection";
  152.         $sections["home_social"] = "socialSection";
  153.         $sections["home_institutional"] = "institutionalSection";
  154.         $sections["stamps_section"] = "stampsSection";
  155.         $homeLayoutSections = [];
  156.         foreach ($sectionConfigHome as $key => $value) {
  157.             if(isset($sections[$key])){
  158.                 if($sections[$key] instanceof PageSection){
  159.                     $homeLayoutSections[$key] = $sections[$key];
  160.                 }else{
  161.                     $homeLayoutSections[$sections[$key]] = $value;
  162.                 }
  163.             }
  164.         }
  165.         /*foreach ($sections as $key => $value) {
  166.             if(isset($sectionConfigHome->{$key})){
  167.                 if($value instanceof PageSection){
  168.                     $homeLayoutSections[$key] = $sections[$key];
  169.                 }else{
  170.                     $homeLayoutSections[$value] = $sectionConfigHome->{$key};
  171.                 }
  172.             }else if($value instanceof PageSection){
  173.                 $homeLayoutSections[$key] = $sections[$key];
  174.             }
  175.         }*/
  176.         $applyBkg = function(string $sectionName) use ($homeLayoutSections) {
  177.             if(isset($homeLayoutSections[$sectionName])){
  178.                 if(isset($homeLayoutSections[$sectionName]->background)){
  179.                     return $homeLayoutSections[$sectionName]->background == ClientEnum::YES;
  180.                 }
  181.             }
  182.             return false;
  183.         };
  184.         $this->data['bannerSection'] = (object)[
  185.             "isCenterTitle" => true,
  186.             "showSubtitle" => true,
  187.             "background" => $applyBkg('bannerSection'),
  188.         ];
  189.         $this->data['faqSection'] = (object)[
  190.             "isCenterTitle" => true,
  191.             "showSubtitle" => true,
  192.             "background" => $applyBkg('faqSection'),
  193.         ];
  194.         $this->data['testimonialSection'] = (object)[
  195.             "isCenterTitle" => true,
  196.             "showSubtitle" => true,
  197.             "background" => $applyBkg('testimonialSection'),
  198.         ];
  199.         $this->data['newsSection'] = (object)[
  200.             "isCenterTitle" => true,
  201.             "showSubtitle" => true,
  202.             "background" => $applyBkg('newsSection'),
  203.         ];
  204.         $this->data['stampsSection'] = (object)[
  205.             "background" => $applyBkg('stampsSection'),
  206.         ];
  207.         $this->data['productCategorySection'] = (object)[
  208.             "background" => $applyBkg('productCategorySection'),
  209.         ];
  210.         $this->data['socialSection'] = (object)[
  211.             "background" => $applyBkg('socialSection'),
  212.         ];
  213.         $this->data['institutionalSection'] = (object)[
  214.             "background" => $applyBkg('institutionalSection'),
  215.         ];
  216.         $this->data['schoolNumberSection'] = (object)[
  217.             "background" => $applyBkg('schoolNumberSection'),
  218.         ];
  219.         $this->data['teacherSection'] = (object)[
  220.             "title" => $this->configuration->getLanguage('featured_teachers''home'),
  221.             "subtitle" => $this->configuration->getLanguage('learn_from_the_best''home'),
  222.             "teachers" => $teachers,
  223.             "isCenterTitle" => true,
  224.             "showSubtitle" => true,
  225.             "background" => $applyBkg('teacherSection'),
  226.             "showBtnToAll" => !empty($teachers) ? true false,
  227.         ];
  228.         $this->data['homeLayoutSections'] = $homeLayoutSections;
  229.     
  230.         return $this->renderEAD('home/home.html.twig');
  231.     }
  232.     /**
  233.      * @Route(
  234.      *      path          = "/update",
  235.      *      name          = "update",
  236.      *      methods       = {"GET"}
  237.      * )
  238.      */
  239.     public function update(Request $request) {
  240.         $this->checkUserSession($request);
  241.         if($this->user->getId() != 1){
  242.             return $this->redirectToRoute('notFound');
  243.         }
  244.         $response $this->configuration->autoUpdate();
  245.         return $this->eadResponse([ "message" => $response ]);
  246.     }
  247.     /**
  248.      * @Route(
  249.      *      path          = "/mencached",
  250.      *      name          = "testRoute",
  251.      *      methods       = {"GET"}
  252.      * )
  253.      */
  254.     public function testRoute(Request $request) {
  255.         print_r(date('Y-m-d H:i:s'));exit;
  256.         $memcacheService $this->generalService->getService('MemcacheService');
  257.         
  258.         $memcacheService->saveData('testRoute''teqrwaesfsdfsdf');
  259.         $data $memcacheService->getData('testRoute');
  260.         return $this->eadResponse($data);
  261.     }
  262.     /**
  263.      * @Route(
  264.      *      path          = "/front/helper",
  265.      *      name          = "frontHelperRoute",
  266.      *      methods       = {"GET"}
  267.      * )
  268.      */
  269.     public function frontHelperRoute(Request $request) {
  270.         $this->checkUserSession($request);
  271.         if($this->user->getId() != 1){
  272.             return $this->redirectToRoute('notFound');
  273.         }
  274.         $images = [
  275.             "add2home.svg",
  276.             "bloco.png",
  277.             "camera.svg",
  278.             "carrinho_vazio.png",
  279.             "conclusion_fail_2.png",
  280.             "conclusion_fail_3.png",
  281.             "conclusion_fail.png",
  282.             "conclusion_success.png",
  283.             "conclusion_wait.png",
  284.             "conclusion_warning.png",
  285.             "cover_default.jpg",
  286.             "emoji_crying.png",
  287.             "favion.png",
  288.             "logo-ead.png",
  289.             "logo-ead.svg",
  290.             "logo-footer.jpg",
  291.             "logotipo-ead-plataforma.svg",
  292.             "medalha.svg",
  293.             "paper.svg",
  294.             "payment1.jpg",
  295.             "payment2.jpg",
  296.             "payment3.jpg",
  297.             "payment4.jpg",
  298.             "payment5.jpg",
  299.             "payment6.jpg",
  300.             "payment7.jpg",
  301.             "payment8.jpg",
  302.             "pb-eadplataforma.png",
  303.             "share.svg",
  304.             "stamp1.jpg",
  305.             "stamp2.jpg",
  306.             "stamp3.jpg",
  307.             "teste_cover_default.jpg",
  308.             "trofeu.svg",
  309.             "user.svg",
  310.             "without-about-icon.svg",
  311.             "without-comment-icon.svg",
  312.             "without-files-icon.svg",
  313.             "without-notes-icon.svg",
  314.         ];
  315.         $cdn "{$this->generalService->getContainer()->getParameter('ead-cdn')}assets/img/";
  316.         foreach ($images as $key => $image) {
  317.             $images[$key] = $cdn $image;
  318.         }
  319.         $this->data['images'] = $images;
  320.         return $this->renderEAD('includes/front.helper.html.twig');
  321.     }
  322.     /**
  323.      * @Route(
  324.      *      path          = "/adm",
  325.      *      name          = "adminEad",
  326.      *      methods       = {"GET"}
  327.      * )
  328.      */
  329.     public function adminEAD(Request $request) {
  330.         $this->checkUserSession($request);
  331.         if(!$this->userPermissionUtil->canAccessAdm()){
  332.             return $this->redirectToRoute('notFound');
  333.         }
  334.         return $this->renderEAD('admin.html.twig''admin');
  335.     }
  336.     /**
  337.      * @Route(
  338.      *      path          = "/cancelar",
  339.      *      name          = "cancelarPlan",
  340.      *      methods       = {"GET"}
  341.      * )
  342.      * 
  343.      * @Route(
  344.      *      path          = "/cancel",
  345.      *      name          = "cancelPlan",
  346.      *      methods       = {"GET"}
  347.      * )
  348.      */
  349.     public function cancelPlan(Request $request) {
  350.         $this->checkUserSession($request);
  351.         if(!$this->userPermissionUtil->canAccessAdm()){
  352.             return $this->redirectToRoute('notFound');
  353.         }
  354.         return $this->redirect("/adm/cancelar"301);
  355.     }
  356.     /**
  357.      * @Route(
  358.      *      path          = "/gratis",
  359.      *      name          = "gratisPlan",
  360.      *      methods       = {"GET"}
  361.      * )
  362.      * 
  363.      * @Route(
  364.      *      path          = "/free",
  365.      *      name          = "freePlan",
  366.      *      methods       = {"GET"}
  367.      * )
  368.      */
  369.     public function freePlan(Request $request) {
  370.         $this->checkUserSession($request);
  371.         if(!$this->userPermissionUtil->canAccessAdm()){
  372.             return $this->redirectToRoute('notFound');
  373.         }
  374.         return $this->redirect("/adm/gratis"301);
  375.     }
  376.     /**
  377.      * @Route(
  378.      *      path          = "/adm/{path}",
  379.      *      requirements  = {"path"=".+"}, 
  380.      *      defaults      = {"path": null},
  381.      *      name          = "adminEadPath",
  382.      *      methods       = {"GET"}
  383.      * )
  384.      */
  385.     public function adminEADPath(Request $request) {
  386.         $this->checkUserSession($request);
  387.         if(!$this->userPermissionUtil->canAccessAdm()){
  388.             return $this->redirectToRoute('notFound');
  389.         }
  390.         return $this->renderEAD('admin.html.twig''admin');
  391.     }
  392.     /**
  393.      * @Route(
  394.      *      path          = "/not-found",
  395.      *      name          = "notFound",
  396.      *      methods       = {"GET"}
  397.      * )
  398.      */
  399.     public function notFoundPage(Request $request) {
  400.         return $this->renderEAD('status/error-page.html.twig');
  401.     }
  402.     /**
  403.      * @Route(
  404.      *      path          = "/manifest.json",
  405.      *      name          = "manifest",
  406.      *      methods       = {"GET"}
  407.      * )
  408.      */
  409.     public function getManifest(Request $request){
  410.         $domain = ($request $request->getHost() : $this->client->getDomainPrimary());
  411.         $upPath AbstractEnum::PATH_UPLOAD;
  412.         $othersPath AbstractEnum::PATH_OTHERS;
  413.         $favicon $this->configuration->get("favicon");
  414.         $favicon = (!empty($favicon) ? "//{$domain}{$upPath}{$othersPath}/{$favicon}null);
  415.         $cdn "{$this->generalService->getContainer()->getParameter('ead-cdn')}assets/img/";
  416.         $favicon192 = (!empty($favicon) ? "{$favicon}?option=manifest-1" "{$cdn}favicon192x192.png");
  417.         $favicon512 = (!empty($favicon) ? "{$favicon}?option=manifest-2" "{$cdn}favicon512x512.png");
  418.         $icons = [];
  419.         $icons[] = (object)[
  420.             "src" => $favicon192,
  421.             "type" => "image/png",
  422.             "sizes" => "192x192",
  423.         ];
  424.         $icons[] = (object)[
  425.             "src" => $favicon512,
  426.             "type" => "image/png",
  427.             "sizes" => "512x512",
  428.         ];
  429.         $primaryColor $this->configuration->get("primary_color");
  430.         $secondColor $this->configuration->get("second_color");
  431.         $data = (object)[
  432.             "short_name" => $this->client->getBrand(),
  433.             "name" => $this->client->getBrand(),
  434.             "description" => $this->client->getDescription(),
  435.             "id" => "./?utm_source=pwa",
  436.             "icons" => $icons,
  437.             "start_url" => "./?utm_source=pwa",
  438.             "background_color" => (!empty($primaryColor) ? $primaryColor '#CCCCCC'),
  439.             "display" => "standalone",
  440.             "scope" => "/",
  441.             "theme_color" => (!empty($secondColor) ? $secondColor '#BBBBBB'),
  442.         ];
  443.         $json json_encode($data);
  444.         return new JsonResponse($json200, [ 
  445.             'Content-Type' => 'application/json; charset=utf-8'
  446.         ], true); 
  447.     }
  448.     /**
  449.      * @Route(
  450.      *      path          = "/sitemap.xml",
  451.      *      name          = "sitemap",
  452.      *      methods       = {"GET"}
  453.      * )
  454.      */
  455.     public function getSitemap(){
  456.         $xml $this->generalService->getService('SiteMapService')->generateSiteMap();
  457.     
  458.         return new Response($xml200, [ 
  459.             'Content-Type' => 'text/xml; charset=utf-8'
  460.         ], true); 
  461.     }
  462. }