src/Controller/Website/HomeController.php line 459

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