src/Controller/Website/HomeController.php line 458

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