src/Controller/Website/HomeController.php line 473

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['searchSection'] = (object)[
  191.             "isCenterTitle" => true,
  192.             "showSubtitle" => true,
  193.             "background" => $applyBkg('searchSection'),
  194.         ];
  195.         $this->data['faqSection'] = (object)[
  196.             "isCenterTitle" => true,
  197.             "showSubtitle" => true,
  198.             "background" => $applyBkg('faqSection'),
  199.         ];
  200.         $this->data['testimonialSection'] = (object)[
  201.             "isCenterTitle" => true,
  202.             "showSubtitle" => true,
  203.             "background" => $applyBkg('testimonialSection'),
  204.         ];
  205.         $this->data['newsSection'] = (object)[
  206.             "isCenterTitle" => true,
  207.             "showSubtitle" => true,
  208.             "background" => $applyBkg('newsSection'),
  209.         ];
  210.         $this->data['stampsSection'] = (object)[
  211.             "background" => $applyBkg('stampsSection'),
  212.         ];
  213.         $this->data['productCategorySection'] = (object)[
  214.             "background" => $applyBkg('productCategorySection'),
  215.         ];
  216.         $this->data['socialSection'] = (object)[
  217.             "background" => $applyBkg('socialSection'),
  218.         ];
  219.         $this->data['institutionalSection'] = (object)[
  220.             "background" => $applyBkg('institutionalSection'),
  221.         ];
  222.         $this->data['schoolNumberSection'] = (object)[
  223.             "background" => $applyBkg('schoolNumberSection'),
  224.         ];
  225.         $this->data['teacherSection'] = (object)[
  226.             "title" => $this->configuration->getLanguage('featured_teachers''home'),
  227.             "subtitle" => $this->configuration->getLanguage('learn_from_the_best''home'),
  228.             "teachers" => $teachers,
  229.             "isCenterTitle" => true,
  230.             "showSubtitle" => true,
  231.             "background" => $applyBkg('teacherSection'),
  232.             "showBtnToAll" => !empty($teachers) ? true false,
  233.         ];
  234.         $sectionKeys array_keys($homeLayoutSections);
  235.         $searchAfterBanner = (
  236.             $applyBkg('searchSection') == false &&
  237.             array_search('searchSection'$sectionKeys) == array_search('bannerSection'$sectionKeys)
  238.         );
  239.         $this->data['homeLayoutSections'] = $homeLayoutSections;
  240.         $this->data['searchAfterBanner'] = $searchAfterBanner;
  241.         $this->data['keyCaptcha'] = $this->createCaptchaKey($request);
  242.     
  243.         return $this->renderEAD('home/home.html.twig');
  244.     }
  245.     /**
  246.      * @Route(
  247.      *      path          = "/mencached",
  248.      *      name          = "testRoute",
  249.      *      methods       = {"GET"}
  250.      * )
  251.      */
  252.     public function testRoute(Request $request) {
  253.         print_r(date('Y-m-d H:i:s'));exit;
  254.         $memcacheService $this->generalService->getService('MemcacheService');
  255.         
  256.         $memcacheService->saveData('testRoute''teqrwaesfsdfsdf');
  257.         $data $memcacheService->getData('testRoute');
  258.         return $this->eadResponse($data);
  259.     }
  260.     /**
  261.      * @Route(
  262.      *      path          = "/front/helper",
  263.      *      name          = "frontHelperRoute",
  264.      *      methods       = {"GET"}
  265.      * )
  266.      */
  267.     public function frontHelperRoute(Request $request) {
  268.         $this->checkUserSession($request);
  269.         if($this->user->getId() != 1){
  270.             return $this->redirectToRoute('notFound');
  271.         }
  272.         $images = [
  273.             "add2home.svg",
  274.             "bloco.png",
  275.             "camera.svg",
  276.             "carrinho_vazio.png",
  277.             "conclusion_fail_2.png",
  278.             "conclusion_fail_3.png",
  279.             "conclusion_fail.png",
  280.             "conclusion_success.png",
  281.             "conclusion_wait.png",
  282.             "conclusion_warning.png",
  283.             "cover_default.jpg",
  284.             "emoji_crying.png",
  285.             "favion.png",
  286.             "logo-ead.png",
  287.             "logo-ead.svg",
  288.             "logo-footer.jpg",
  289.             "logotipo-ead-plataforma.svg",
  290.             "medalha.svg",
  291.             "paper.svg",
  292.             "payment1.jpg",
  293.             "payment2.jpg",
  294.             "payment3.jpg",
  295.             "payment4.jpg",
  296.             "payment5.jpg",
  297.             "payment6.jpg",
  298.             "payment7.jpg",
  299.             "payment8.jpg",
  300.             "pb-eadplataforma.png",
  301.             "share.svg",
  302.             "stamp1.jpg",
  303.             "stamp2.jpg",
  304.             "stamp3.jpg",
  305.             "teste_cover_default.jpg",
  306.             "trofeu.svg",
  307.             "user.svg",
  308.             "without-about-icon.svg",
  309.             "without-comment-icon.svg",
  310.             "without-files-icon.svg",
  311.             "without-notes-icon.svg",
  312.         ];
  313.         $cdn "{$this->generalService->getContainer()->getParameter('ead-cdn')}assets/img/";
  314.         foreach ($images as $key => $image) {
  315.             $images[$key] = $cdn $image;
  316.         }
  317.         $this->data['images'] = $images;
  318.         return $this->renderEAD('includes/front.helper.html.twig');
  319.     }
  320.     /**
  321.      * @Route(
  322.      *      path          = "/adm",
  323.      *      name          = "adminEad",
  324.      *      methods       = {"GET"}
  325.      * )
  326.      */
  327.     public function adminEAD(Request $request) {
  328.         $this->checkUserSession($request);
  329.         if(!$this->userPermissionUtil->canAccessAdm()){
  330.             return $this->redirectToRoute('notFound');
  331.         }
  332.         return $this->renderEAD('admin.html.twig''admin');
  333.     }
  334.     /**
  335.      * @Route(
  336.      *      path          = "/cancelar",
  337.      *      name          = "cancelarPlan",
  338.      *      methods       = {"GET"}
  339.      * )
  340.      * 
  341.      * @Route(
  342.      *      path          = "/cancel",
  343.      *      name          = "cancelPlan",
  344.      *      methods       = {"GET"}
  345.      * )
  346.      */
  347.     public function cancelPlan(Request $request) {
  348.         $this->checkUserSession($request);
  349.         if(!$this->userPermissionUtil->canAccessAdm()){
  350.             return $this->redirectToRoute('notFound');
  351.         }
  352.         return $this->redirect("/adm/cancelar"301);
  353.     }
  354.     /**
  355.      * @Route(
  356.      *      path          = "/gratis",
  357.      *      name          = "gratisPlan",
  358.      *      methods       = {"GET"}
  359.      * )
  360.      * 
  361.      * @Route(
  362.      *      path          = "/free",
  363.      *      name          = "freePlan",
  364.      *      methods       = {"GET"}
  365.      * )
  366.      */
  367.     public function freePlan(Request $request) {
  368.         $this->checkUserSession($request);
  369.         if(!$this->userPermissionUtil->canAccessAdm()){
  370.             return $this->redirectToRoute('notFound');
  371.         }
  372.         return $this->redirect("/adm/gratis"301);
  373.     }
  374.     /**
  375.      * @Route(
  376.      *      path          = "/adm/{path}",
  377.      *      requirements  = {"path"=".+"}, 
  378.      *      defaults      = {"path": null},
  379.      *      name          = "adminEadPath",
  380.      *      methods       = {"GET"}
  381.      * )
  382.      */
  383.     public function adminEADPath(Request $request) {
  384.         $this->checkUserSession($request);
  385.         if(!$this->userPermissionUtil->canAccessAdm()){
  386.             return $this->redirectToRoute('notFound');
  387.         }
  388.         return $this->renderEAD('admin.html.twig''admin');
  389.     }
  390.     /**
  391.      * @Route(
  392.      *      path          = "/not-found",
  393.      *      name          = "notFound",
  394.      *      methods       = {"GET"}
  395.      * )
  396.      */
  397.     public function notFoundPage(Request $request) {
  398.         return $this->renderEAD('status/error-page.html.twig');
  399.     }
  400.     /**
  401.      * @Route(
  402.      *      path          = "/manifest.json",
  403.      *      name          = "manifest",
  404.      *      methods       = {"GET"}
  405.      * )
  406.      */
  407.     public function getManifest(Request $request){
  408.         $domain = ($request $request->getHost() : $this->client->getDomainPrimary());
  409.         $upPath AbstractEnum::PATH_UPLOAD;
  410.         $othersPath AbstractEnum::PATH_OTHERS;
  411.         $favicon $this->configuration->get("favicon");
  412.         $favicon = (!empty($favicon) ? "//{$domain}{$upPath}{$othersPath}/{$favicon}null);
  413.         $cdn "{$this->generalService->getContainer()->getParameter('ead-cdn')}assets/img/";
  414.         $favicon192 = (!empty($favicon) ? "{$favicon}?option=manifest-1" "{$cdn}favicon192x192.png");
  415.         $favicon512 = (!empty($favicon) ? "{$favicon}?option=manifest-2" "{$cdn}favicon512x512.png");
  416.         $icons = [];
  417.         $icons[] = (object)[
  418.             "src" => $favicon192,
  419.             "type" => "image/png",
  420.             "sizes" => "192x192",
  421.         ];
  422.         $icons[] = (object)[
  423.             "src" => $favicon512,
  424.             "type" => "image/png",
  425.             "sizes" => "512x512",
  426.         ];
  427.         $primaryColor $this->configuration->get("primary_color");
  428.         $secondColor $this->configuration->get("second_color");
  429.         $data = (object)[
  430.             "short_name" => $this->client->getBrand(),
  431.             "name" => $this->client->getBrand(),
  432.             "description" => $this->client->getDescription(),
  433.             "id" => "./?utm_source=pwa",
  434.             "icons" => $icons,
  435.             "start_url" => "./?utm_source=pwa",
  436.             "background_color" => (!empty($primaryColor) ? $primaryColor '#CCCCCC'),
  437.             "display" => "standalone",
  438.             "scope" => "/",
  439.             "theme_color" => (!empty($secondColor) ? $secondColor '#BBBBBB'),
  440.             "gcm_sender_id" => "975354790337",
  441.         ];
  442.         $json json_encode($data);
  443.         return new JsonResponse($json200, [ 
  444.             'Content-Type' => 'application/json; charset=utf-8'
  445.         ], true); 
  446.     }
  447.     /**
  448.      * @Route(
  449.      *      path          = "/sitemap.xml",
  450.      *      name          = "sitemap",
  451.      *      methods       = {"GET"}
  452.      * )
  453.      */
  454.     public function getSitemap(){
  455.         $xml $this->generalService->getService('SiteMapService')->generateSiteMap();
  456.     
  457.         return new Response($xml200, [ 
  458.             'Content-Type' => 'text/xml; charset=utf-8'
  459.         ], true); 
  460.     }
  461. }