src/Controller/DefaultController.php line 98

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  8. use Symfony\Component\Mailer\MailerInterface;
  9. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  10. use Symfony\Component\Mime\Email;
  11. use Symfony\Component\Mime\Address;
  12. use OlaSoft\Common;
  13. use App\Entity\Subscribers;
  14. use App\Entity\Services;
  15. use App\Entity\ServicesCategories;
  16. use App\Entity\Opportunities;
  17. use App\Entity\OpportunitiesCategories;
  18. use App\Entity\Articles;
  19. use App\Entity\ArticlesCategories;
  20. use App\Entity\Structures;
  21. use App\Entity\StructuresCategories;
  22. use App\Entity\FAQ;
  23. use App\Entity\FAQCategories;
  24. use App\Entity\Projects;
  25. use App\Entity\Resources;
  26. use App\Entity\ResourcesCategories;
  27. use App\Entity\Pages;
  28. use App\Entity\Partners;
  29. use App\Entity\Banners;
  30. use App\Entity\Videos;
  31. use App\Entity\VideosCategories;
  32. use App\Entity\Messages;
  33. use App\Entity\Members;
  34. use App\Entity\Events;
  35. use App\Form\MessagesType;
  36. use App\Form\SubscribersType;
  37. use Doctrine\Persistence\ManagerRegistry;
  38. class DefaultController extends AbstractController
  39. {
  40.     public function __construct(ManagerRegistry $doctrine){
  41.         $this->doctrine =  $doctrine;
  42.     }
  43.     private $doctrine;
  44.     public function getDoctrine()
  45.     {
  46.         return $this->doctrine;
  47.     }
  48.     /**
  49.      * @Route("/", name="home")
  50.      */
  51.     public function index()
  52.     {
  53.         $em $this->getDoctrine()->getManager();
  54.         $role1 $em->getRepository(Pages::class)->findOneBy(['id'=>2],[]);
  55.         $role2 $em->getRepository(Pages::class)->findOneBy(['id'=>3],[]);
  56.         $role3 $em->getRepository(Pages::class)->findOneBy(['id'=>4],[]);
  57.         $banners $em->getRepository(Banners::class)->findBy(['isEnabled'=>1], ['id'=>'desc'],2);
  58.         $projects $em->getRepository(Projects::class)->findBy(['isEnabled'=>1], ['id'=>'desc'],3);
  59.         $articles $em->getRepository(Articles::class)->findBy(['isEnabled'=>1], ['date'=>'desc'], 3);
  60.         $services $em->getRepository(Services::class)->findBy(['isEnabled'=>1], ['id'=>'asc'], 3);
  61.         $events $em->getRepository(Events::class)->findBy(['isEnabled'=>1], ['startDate'=>'desc'], 3);
  62.         $emplois =  $em->getRepository(Opportunities::class)->createQueryBuilder('o')
  63.             ->leftjoin('o.category','c')
  64.             ->where('o.isEnabled = 1 and c.id = 1')
  65.             ->select('o')->addSelect('c')->setMaxResults(3)
  66.             ->getQuery()->getResult();
  67.         $avis =  $em->getRepository(Opportunities::class)->createQueryBuilder('o')
  68.             ->leftjoin('o.category','c')
  69.             ->where('o.isEnabled = 1 and c.id = 2')
  70.             ->select('o')->addSelect('c')->setMaxResults(3)
  71.             ->getQuery()->getResult();
  72.         return $this->render('Default/index.html.twig',[
  73.             'role1' => $role1,
  74.             'role2' => $role2,
  75.             'role3' => $role3,
  76.             'banners' => $banners,
  77.             'projects' => $projects,
  78.             'articles' => $articles,
  79.             'services' => $services,
  80.             'emplois' => $emplois,
  81.             'avis' => $avis,
  82.             'events' => $events,
  83.         ]);
  84.     }
  85.     /**
  86.      * @Route("/sitemap.xml", name="sitemap", defaults={"xml"=true, "_format"="xml"})
  87.      */
  88.     public function menu($activeMenu null$isFooter false$xml false)
  89.     {
  90.         $em $this->getDoctrine()->getManager();
  91.         $articlesCats $em->getRepository(ArticlesCategories::class)->findBy(['isEnabled'=>1]);
  92.         $opportunitiesCats $em->getRepository(OpportunitiesCategories::class)->findBy(['isEnabled'=>1]);
  93.         $resourcesCats $em->getRepository(ResourcesCategories::class)->findAll();
  94.         $videosCats $em->getRepository(VideosCategories::class)->findBy(['isEnabled'=>1]);
  95.         return $this->render($xml 'Default/sitemap.xml.twig' : ($isFooter 'Default/footer.html.twig' 'Default/menu.html.twig'),[
  96.             'articlesCats'=>$articlesCats,
  97.             'opportunitiesCats'=>$opportunitiesCats,
  98.             'resourcesCats'=>$resourcesCats,
  99.             'videosCats'=>$videosCats,
  100.             'activeMenu'=>$activeMenu,
  101.         ]);
  102.     }
  103.     /**
  104.      * @Route("/opportunites/", name="opportunities")
  105.      * @Route("/opportunites/{cat}/", name="opportunities-cat")
  106.      */
  107.     public function opportunites(Request $request$offset 1$cat null)
  108.     {
  109.         $offset $request->get('offset') ?? 1;
  110.         $keyword $request->get('q');
  111.         $offset--;
  112.         $limit 60;
  113.         $params = [];
  114.         $of $offset*$limit;
  115.         $em $this->getDoctrine()->getManager();
  116.         $cat $cat $em->getRepository(OpportunitiesCategories::class)->findOneBySlug($cat) : null;
  117.         $query =  $em->getRepository(Opportunities::class)->createQueryBuilder('o')
  118.             ->leftjoin('o.category','c')
  119.             ->where('o.isEnabled = 1');
  120.         if($cat) {
  121.             $query $query->andWhere('c.id = '.$cat->getId());
  122.             $params['cat'] = $cat->getSlug();
  123.         }
  124.         if($keyword$query $query->andWhere('(o.title like :k or o.description like :k)')
  125.             ->setParameter('k','%'.$keyword.'%');
  126.         $count $query->select('count(o.id)')->getQuery()->getResult()[0][1];
  127.         $list $query->select('o')->addSelect('c')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
  128.         return $this->render('Default/opportunities.html.twig',[
  129.             'list'=>$list,
  130.             'count'=>$count,
  131.             'cat'=>$cat,
  132.             'params'=>$params,
  133.             'table_limit'=>$limit,
  134.             'offset'=>$offset,
  135.             'keyword'=>$keyword,
  136.         ]);
  137.     }
  138.     /**
  139.      * @Route("/opportunite/{id}/{slug}/", name="opportunity")
  140.      */
  141.     public function opportunite(Opportunities $item$slug null)
  142.     {
  143.         $em $this->getDoctrine()->getManager();
  144.         $list $em->getRepository(Opportunities::class)->createQueryBuilder('o')
  145.             ->select('o')->where('o.isEnabled = 1')
  146.             ->getQuery()->getResult();
  147.         return $this->render('Default/opportunity.html.twig',[
  148.             'item'=>$item,
  149.             'list'=>$list,
  150.         ]);
  151.     }
  152.     /**
  153.      * @Route("/services/", name="services")
  154.      * @Route("/services/{cat}/", name="services-cat")
  155.      */
  156.     public function services(Request $request$cat null)
  157.     {
  158.         $em $this->getDoctrine()->getManager();
  159.         $cat $cat $em->getRepository(ServicesCategories::class)->findOneBySlug($cat) : null;
  160.         $groups $em->getRepository(ServicesCategories::class)->findBy(['isEnabled'=>1], ['id'=>'asc']);
  161.         $offset $request->get('offset') ?? 1;
  162.         $keyword $request->get('q');
  163.         $offset--;
  164.         $limit 50;
  165.         $params = [];
  166.         $of $offset*$limit;
  167.         $list $em->getRepository(Services::class)->findBy(['isEnabled'=>1],[],$limit,$of);
  168.         $count $em->getRepository(Services::class)->count(['isEnabled'=>1]);
  169.         $query =  $em->getRepository(Services::class)->createQueryBuilder('s')
  170.             ->leftjoin('s.category','c')
  171.             ->where('s.isEnabled = 1');
  172.         if($cat) {
  173.             $query $query->andWhere('c.id = '.$cat->getId());
  174.             $params['cat'] = $cat->getSlug();
  175.         }
  176.         if($keyword$query $query->andWhere('(s.title like :k or s.description like :k or s.content like :k or s.cost like :k or s.time like :k or s.department like :k)')
  177.             ->setParameter('k','%'.$keyword.'%');
  178.         $count $query->select('count(s.id)')->getQuery()->getResult()[0][1];
  179.         $list $query->select('s')->addSelect('c')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
  180.         return $this->render('Default/services.html.twig',[
  181.             'list'=>$list,
  182.             'groups'=>$groups,
  183.             'cat'=>$cat,
  184.             'params'=>$params,
  185.             'count'=>$count,
  186.             'table_limit'=>$limit,
  187.             'offset'=>$offset,
  188.             'keyword'=>$keyword,
  189.         ]);
  190.     }
  191.     /**
  192.      * @Route("/service/{id}/{slug}/", name="service", requirements={"id": "\d+"})
  193.      * @Route("/service/{id}/", requirements={"id": "\d+"})
  194.      */
  195.     public function service(Services $service$slug null)
  196.     {
  197.         // if(!$service->getIsEnabled() && !$this->isGranted('ROLE_USER'))
  198.             // return $this->redirectToRoute('services');
  199.         $em $this->getDoctrine()->getManager();
  200.         $list $em->getRepository(Services::class)->createQueryBuilder('s')
  201.             ->leftjoin('s.category','c')
  202.             ->andWhere('s.id <> '.$service->getId())
  203.             ->andWhere('c.id = '.$service->getCategory()->getId())
  204.             ->andWhere('s.isEnabled = 1')
  205.             ->getQuery()->getResult();
  206.         return $this->render('Default/service.html.twig',[
  207.             'service'=>$service,
  208.             'list'=>$list,
  209.         ]);
  210.     }
  211.     
  212.     
  213.     /**
  214.      * @Route("/projets/", name="projects")
  215.      */
  216.     public function projects(Request $request)
  217.     {
  218.         $offset $request->get('offset') ?? 1;
  219.         $keyword $request->get('q');
  220.         $offset--;
  221.         $limit 50;
  222.         $of $offset*$limit;
  223.         $em $this->getDoctrine()->getManager();
  224.         $list $em->getRepository(Projects::class)->findBy(['isEnabled'=>1],[],$limit,$of);
  225.         $count $em->getRepository(Projects::class)->count(['isEnabled'=>1]);
  226.         $query =  $em->getRepository(Projects::class)->createQueryBuilder('p')
  227.             ->where('p.isEnabled = 1');
  228.         if($keyword$query $query->andWhere('(p.name like :k or p.description like :k or p.details like :k)')
  229.             ->setParameter('k','%'.$keyword.'%');
  230.         $count $query->select('count(p.id)')->getQuery()->getResult()[0][1];
  231.         $list $query->select('p')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
  232.         return $this->render('Default/projects.html.twig',[
  233.             'list'=>$list,
  234.             'count'=>$count,
  235.             'table_limit'=>$limit,
  236.             'offset'=>$offset,
  237.             'keyword'=>$keyword,
  238.         ]);
  239.     }
  240.     /**
  241.      * @Route("/projet/{id}/{slug}/", name="project")
  242.      */
  243.     public function project(Projects $project)
  244.     {
  245.         $em $this->getDoctrine()->getManager();
  246.         $list $em->getRepository(Projects::class)->createQueryBuilder('p')
  247.             // ->leftjoin('a.sector','s')
  248.             ->leftjoin('p.album','aa')
  249.             ->orderBy('p.name','ASC')
  250.             ->andWhere('p.id <> '.$project->getId())
  251.             ->andWhere('p.isEnabled = 1')
  252.             ->setMaxResults(4)
  253.             ->getQuery()
  254.             ->getResult();
  255.         return $this->render('Default/project.html.twig',[
  256.             'project'=>$project,
  257.             'list'=>$list,
  258.         ]);
  259.     }
  260.     /**
  261.      * @Route("/articles/", name="articles")
  262.      * @Route("/articles/{offset}/", name="articles-page", requirements={"offset": "\d+"})
  263.      * @Route("/articles/{cat}/", name="articles-cat")
  264.      * @Route("/articles/{cat}/{offset}/", name="articles-cat-page", requirements={"offset": "\d+"})
  265.      */
  266.     public function articles($offset 1$cat null)
  267.     {
  268.         $offset--;
  269.         $limit 30;
  270.         $of $offset*$limit;
  271.         $params = [];
  272.         $em $this->getDoctrine()->getManager();
  273.         $cat $cat $em->getRepository(ArticlesCategories::class)->findOneBySlug($cat) : null;
  274.         $list $em->getRepository(Articles::class)->createQueryBuilder('a')
  275.             ->leftjoin('a.banner','b')
  276.             ->leftjoin('a.category','c')
  277.             ->leftjoin('a.type','t')
  278.             ->leftjoin('a.album','aa')
  279.             ->leftjoin('a.biblio','ab')
  280.             ->orderBy('a.date','DESC')
  281.             ->andWhere("a.date <= '".(new \DateTime())->format('Y-m-d H:i:s')."'")
  282.             ->andWhere('a.isEnabled = 1')
  283.         ;
  284.         if($cat) {
  285.             $list $list->andWhere('c.id = '.$cat->getId());
  286.             $params['cat'] = $cat->getSlug();
  287.         }
  288.         $count $list->select('count(distinct(a.id))')->getQuery()->getResult()[0][1];
  289.         $list $list->select('a')
  290.             ->setMaxResults($limit)
  291.             ->setFirstResult($of)
  292.             ->getQuery()->getResult();
  293.         return $this->render('Default/articles.html.twig',[
  294.             'list'=>$list,
  295.             'cat'=>$cat,
  296.             'count'=>$count,
  297.             'table_limit'=>$limit,
  298.             'offset'=>$offset,
  299.             'params'=>$params
  300.         ]);
  301.     }
  302.     /**
  303.      * @Route("/article/{id}/{slug}/", name="article", requirements={"id": "\d+"})
  304.      * @Route("/article/{id}/", requirements={"id": "\d+"})
  305.      */
  306.     public function article(Articles $article$slug null)
  307.     {
  308.         if(!$article->getIsEnabled() && !$this->isGranted('ROLE_USER'))
  309.             return $this->redirectToRoute('articles');
  310.         if($article->getURL())
  311.             return $this->redirect($article->getURL());
  312.         $em $this->getDoctrine()->getManager();
  313.         $list $em->getRepository(Articles::class)->createQueryBuilder('a')
  314.             ->leftjoin('a.banner','b')
  315.             ->leftjoin('a.category','c')
  316.             ->leftjoin('a.type','t')
  317.             ->leftjoin('a.album','aa')
  318.             ->leftjoin('a.biblio','ab')
  319.             ->orderBy('a.date','DESC')
  320.             // ->andWhere('a.id <> '.$article->getId())
  321.             ->andWhere("a.date <= '".(new \DateTime())->format('Y-m-d H:i:s')."'")
  322.             ->andWhere('a.isEnabled = 1')
  323.             ->setMaxResults(6)
  324.             ->getQuery()
  325.             ->getResult();
  326.         return $this->render('Default/article.html.twig',[
  327.             'article'=>$article,
  328.             'list'=>$list,
  329.         ]);
  330.     }
  331.     /**
  332.      * @Route("/evenements/", name="events")
  333.      */
  334.     public function events(Request $request)
  335.     {
  336.         $offset $request->get('offset') ?? 1;
  337.         $keyword $request->get('q');
  338.         $offset--;
  339.         $limit 50;
  340.         $of $offset*$limit;
  341.         $em $this->getDoctrine()->getManager();
  342.         $query =  $em->getRepository(Events::class)->createQueryBuilder('e')
  343.             ->where('e.isEnabled = 1')
  344.             ->orderBy('e.startDate','desc');
  345.         if($keyword$query $query->andWhere('(e.name like :k or e.startDate like :k or e.endDate like :k or e.place like :k)')
  346.             ->setParameter('k','%'.$keyword.'%');
  347.         $count $query->select('count(e.id)')->getQuery()->getResult()[0][1];
  348.         $list $query->select('e')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
  349.         return $this->render('Default/events.html.twig',[
  350.             'list'=>$list,
  351.             'count'=>$count,
  352.             'table_limit'=>$limit,
  353.             'offset'=>$offset,
  354.             'keyword'=>$keyword,
  355.         ]);
  356.     }
  357.     /**
  358.      * @Route("/videos/", name="videos")
  359.      * @Route("/videos/{cat}/", name="videos-cat")
  360.      */
  361.     public function videos($cat null)
  362.     {
  363.         $em $this->getDoctrine()->getManager();
  364.         $videos $em->getRepository(Videos::class)->findBy(['isEnabled'=>1], ['id'=>'desc']);
  365.         return $this->render('Default/videos.html.twig',[
  366.             'list'=>$videos
  367.         ]);
  368.     }
  369.     /**
  370.      * @Route("/video/{id}/", name="video", requirements={"id": "\d+"})
  371.      */
  372.     public function video(Videos $video)
  373.     {
  374.         return $this->render('Default/video.html.twig',[
  375.             'video'=>$video
  376.         ]);
  377.     }
  378.     /**
  379.      * @Route("/structures/", name="structures")
  380.      * @Route("/structures/{slug}/", name="structures-cat")
  381.      */
  382.     public function structures(StructuresCategories $cat null)
  383.     {
  384.         $em $this->getDoctrine()->getManager();
  385.         $filter = ['isEnabled' => 1];
  386.         if($cat$filter['category'] = $cat->getId();
  387.         $list $em->getRepository(Structures::class)->findBy($filter, ['position'=>'DESC']);
  388.         // $groups = $cat ? null : $em->getRepository(StructuresCategories::class)->findBy(['isEnabled'=>1], ['id'=>'asc']);
  389.         $groups $em->getRepository(StructuresCategories::class)->findBy(['isEnabled'=>1], ['id'=>'asc']);
  390.         return $this->render('Default/structures.html.twig',[
  391.             'list'=>$list,
  392.             'groups'=>$groups,
  393.             'cat'=>$cat,
  394.         ]);
  395.     }
  396.     /**
  397.      * @Route("/structure/{id}/{slug}/", name="structure")
  398.      */
  399.     public function structure(Structures $struct)
  400.     {
  401.         return $this->render('Default/structure.html.twig',[
  402.             'struct'=>$struct,
  403.         ]);
  404.     }
  405.     /**
  406.      * @Route("/plateformes-services/", name="plateformes-services")
  407.      */
  408.     public function partners(Request $request)
  409.     {
  410.         $offset $request->get('offset') ?? 1;
  411.         $keyword $request->get('q');
  412.         $offset--;
  413.         $limit 50;
  414.         $of $offset*$limit;
  415.         $em $this->getDoctrine()->getManager();
  416.         $list $em->getRepository(Partners::class)->findBy(['isEnabled'=>1],[],$limit,$of);
  417.         $count $em->getRepository(Partners::class)->count(['isEnabled'=>1]);
  418.         $query =  $em->getRepository(Partners::class)->createQueryBuilder('p')
  419.             ->where('p.isEnabled = 1');
  420.         if($keyword$query $query->andWhere('(p.name like :k or p.description like :k or p.website like :k)')
  421.             ->setParameter('k','%'.$keyword.'%');
  422.         $count $query->select('count(p.id)')->getQuery()->getResult()[0][1];
  423.         $list $query->select('p')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
  424.         return $this->render('Default/partners.html.twig',[
  425.             'list'=>$list,
  426.             'count'=>$count,
  427.             'table_limit'=>$limit,
  428.             'offset'=>$offset,
  429.             'keyword'=>$keyword,
  430.         ]);
  431.     }
  432.     /**
  433.      * @Route("/documents/", name="resources")
  434.      * @Route("/documents/{slug}/", name="resources-cat")
  435.      */
  436.     public function resources(Request $requestResourcesCategories $cat null)
  437.     {
  438.         $keyword $request->get('q');
  439.         $offset $request->get('offset') ?? 1;
  440.         $offset--;
  441.         $limit 50;
  442.         $of $offset*$limit;
  443.         $em $this->getDoctrine()->getManager();
  444.         $query =  $em->getRepository(Resources::class)->createQueryBuilder('r')
  445.             ->leftjoin('r.category','c')
  446.             ->where('r.isEnabled = 1')
  447.             ->orderBy('r.date','desc');
  448.         if($cat$query $query->andWhere('c.id = '.$cat->getId())->addOrderBy('r.isImportant','desc');
  449.         if($keyword)
  450.             $query $query->andWhere('(r.title like :k or r.description like :k or c.label like :k )')
  451.             ->setParameter('k','%'.$keyword.'%');
  452.         $count $query->select('count(r.id)')->getQuery()->getResult()[0][1];
  453.         $list $query->select('r')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
  454.         return $this->render('Default/resources.html.twig',[
  455.             'cat'=>$cat,
  456.             'list'=>$list,
  457.             'count'=>$count,
  458.             'table_limit'=>$limit,
  459.             'offset'=>$offset,
  460.             'keyword'=>$keyword
  461.         ]);
  462.     }
  463. }