src/Controller/DefaultController.php line 98
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Address;
use OlaSoft\Common;
use App\Entity\Subscribers;
use App\Entity\Services;
use App\Entity\ServicesCategories;
use App\Entity\Opportunities;
use App\Entity\OpportunitiesCategories;
use App\Entity\Articles;
use App\Entity\ArticlesCategories;
use App\Entity\Structures;
use App\Entity\StructuresCategories;
use App\Entity\FAQ;
use App\Entity\FAQCategories;
use App\Entity\Projects;
use App\Entity\Resources;
use App\Entity\ResourcesCategories;
use App\Entity\Pages;
use App\Entity\Partners;
use App\Entity\Banners;
use App\Entity\Videos;
use App\Entity\VideosCategories;
use App\Entity\Messages;
use App\Entity\Members;
use App\Entity\Events;
use App\Form\MessagesType;
use App\Form\SubscribersType;
use Doctrine\Persistence\ManagerRegistry;
class DefaultController extends AbstractController
{
public function __construct(ManagerRegistry $doctrine){
$this->doctrine = $doctrine;
}
private $doctrine;
public function getDoctrine()
{
return $this->doctrine;
}
/**
* @Route("/", name="home")
*/
public function index()
{
$em = $this->getDoctrine()->getManager();
$role1 = $em->getRepository(Pages::class)->findOneBy(['id'=>2],[]);
$role2 = $em->getRepository(Pages::class)->findOneBy(['id'=>3],[]);
$role3 = $em->getRepository(Pages::class)->findOneBy(['id'=>4],[]);
$banners = $em->getRepository(Banners::class)->findBy(['isEnabled'=>1], ['id'=>'desc'],2);
$projects = $em->getRepository(Projects::class)->findBy(['isEnabled'=>1], ['id'=>'desc'],3);
$articles = $em->getRepository(Articles::class)->findBy(['isEnabled'=>1], ['date'=>'desc'], 3);
$services = $em->getRepository(Services::class)->findBy(['isEnabled'=>1], ['id'=>'asc'], 3);
$events = $em->getRepository(Events::class)->findBy(['isEnabled'=>1], ['startDate'=>'desc'], 3);
$emplois = $em->getRepository(Opportunities::class)->createQueryBuilder('o')
->leftjoin('o.category','c')
->where('o.isEnabled = 1 and c.id = 1')
->select('o')->addSelect('c')->setMaxResults(3)
->getQuery()->getResult();
$avis = $em->getRepository(Opportunities::class)->createQueryBuilder('o')
->leftjoin('o.category','c')
->where('o.isEnabled = 1 and c.id = 2')
->select('o')->addSelect('c')->setMaxResults(3)
->getQuery()->getResult();
return $this->render('Default/index.html.twig',[
'role1' => $role1,
'role2' => $role2,
'role3' => $role3,
'banners' => $banners,
'projects' => $projects,
'articles' => $articles,
'services' => $services,
'emplois' => $emplois,
'avis' => $avis,
'events' => $events,
]);
}
/**
* @Route("/sitemap.xml", name="sitemap", defaults={"xml"=true, "_format"="xml"})
*/
public function menu($activeMenu = null, $isFooter = false, $xml = false)
{
$em = $this->getDoctrine()->getManager();
$articlesCats = $em->getRepository(ArticlesCategories::class)->findBy(['isEnabled'=>1]);
$opportunitiesCats = $em->getRepository(OpportunitiesCategories::class)->findBy(['isEnabled'=>1]);
$resourcesCats = $em->getRepository(ResourcesCategories::class)->findAll();
$videosCats = $em->getRepository(VideosCategories::class)->findBy(['isEnabled'=>1]);
return $this->render($xml ? 'Default/sitemap.xml.twig' : ($isFooter ? 'Default/footer.html.twig' : 'Default/menu.html.twig'),[
'articlesCats'=>$articlesCats,
'opportunitiesCats'=>$opportunitiesCats,
'resourcesCats'=>$resourcesCats,
'videosCats'=>$videosCats,
'activeMenu'=>$activeMenu,
]);
}
/**
* @Route("/opportunites/", name="opportunities")
* @Route("/opportunites/{cat}/", name="opportunities-cat")
*/
public function opportunites(Request $request, $offset = 1, $cat = null)
{
$offset = $request->get('offset') ?? 1;
$keyword = $request->get('q');
$offset--;
$limit = 60;
$params = [];
$of = $offset*$limit;
$em = $this->getDoctrine()->getManager();
$cat = $cat ? $em->getRepository(OpportunitiesCategories::class)->findOneBySlug($cat) : null;
$query = $em->getRepository(Opportunities::class)->createQueryBuilder('o')
->leftjoin('o.category','c')
->where('o.isEnabled = 1');
if($cat) {
$query = $query->andWhere('c.id = '.$cat->getId());
$params['cat'] = $cat->getSlug();
}
if($keyword) $query = $query->andWhere('(o.title like :k or o.description like :k)')
->setParameter('k','%'.$keyword.'%');
$count = $query->select('count(o.id)')->getQuery()->getResult()[0][1];
$list = $query->select('o')->addSelect('c')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
return $this->render('Default/opportunities.html.twig',[
'list'=>$list,
'count'=>$count,
'cat'=>$cat,
'params'=>$params,
'table_limit'=>$limit,
'offset'=>$offset,
'keyword'=>$keyword,
]);
}
/**
* @Route("/opportunite/{id}/{slug}/", name="opportunity")
*/
public function opportunite(Opportunities $item, $slug = null)
{
$em = $this->getDoctrine()->getManager();
$list = $em->getRepository(Opportunities::class)->createQueryBuilder('o')
->select('o')->where('o.isEnabled = 1')
->getQuery()->getResult();
return $this->render('Default/opportunity.html.twig',[
'item'=>$item,
'list'=>$list,
]);
}
/**
* @Route("/services/", name="services")
* @Route("/services/{cat}/", name="services-cat")
*/
public function services(Request $request, $cat = null)
{
$em = $this->getDoctrine()->getManager();
$cat = $cat ? $em->getRepository(ServicesCategories::class)->findOneBySlug($cat) : null;
$groups = $em->getRepository(ServicesCategories::class)->findBy(['isEnabled'=>1], ['id'=>'asc']);
$offset = $request->get('offset') ?? 1;
$keyword = $request->get('q');
$offset--;
$limit = 50;
$params = [];
$of = $offset*$limit;
$list = $em->getRepository(Services::class)->findBy(['isEnabled'=>1],[],$limit,$of);
$count = $em->getRepository(Services::class)->count(['isEnabled'=>1]);
$query = $em->getRepository(Services::class)->createQueryBuilder('s')
->leftjoin('s.category','c')
->where('s.isEnabled = 1');
if($cat) {
$query = $query->andWhere('c.id = '.$cat->getId());
$params['cat'] = $cat->getSlug();
}
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)')
->setParameter('k','%'.$keyword.'%');
$count = $query->select('count(s.id)')->getQuery()->getResult()[0][1];
$list = $query->select('s')->addSelect('c')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
return $this->render('Default/services.html.twig',[
'list'=>$list,
'groups'=>$groups,
'cat'=>$cat,
'params'=>$params,
'count'=>$count,
'table_limit'=>$limit,
'offset'=>$offset,
'keyword'=>$keyword,
]);
}
/**
* @Route("/service/{id}/{slug}/", name="service", requirements={"id": "\d+"})
* @Route("/service/{id}/", requirements={"id": "\d+"})
*/
public function service(Services $service, $slug = null)
{
// if(!$service->getIsEnabled() && !$this->isGranted('ROLE_USER'))
// return $this->redirectToRoute('services');
$em = $this->getDoctrine()->getManager();
$list = $em->getRepository(Services::class)->createQueryBuilder('s')
->leftjoin('s.category','c')
->andWhere('s.id <> '.$service->getId())
->andWhere('c.id = '.$service->getCategory()->getId())
->andWhere('s.isEnabled = 1')
->getQuery()->getResult();
return $this->render('Default/service.html.twig',[
'service'=>$service,
'list'=>$list,
]);
}
/**
* @Route("/projets/", name="projects")
*/
public function projects(Request $request)
{
$offset = $request->get('offset') ?? 1;
$keyword = $request->get('q');
$offset--;
$limit = 50;
$of = $offset*$limit;
$em = $this->getDoctrine()->getManager();
$list = $em->getRepository(Projects::class)->findBy(['isEnabled'=>1],[],$limit,$of);
$count = $em->getRepository(Projects::class)->count(['isEnabled'=>1]);
$query = $em->getRepository(Projects::class)->createQueryBuilder('p')
->where('p.isEnabled = 1');
if($keyword) $query = $query->andWhere('(p.name like :k or p.description like :k or p.details like :k)')
->setParameter('k','%'.$keyword.'%');
$count = $query->select('count(p.id)')->getQuery()->getResult()[0][1];
$list = $query->select('p')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
return $this->render('Default/projects.html.twig',[
'list'=>$list,
'count'=>$count,
'table_limit'=>$limit,
'offset'=>$offset,
'keyword'=>$keyword,
]);
}
/**
* @Route("/projet/{id}/{slug}/", name="project")
*/
public function project(Projects $project)
{
$em = $this->getDoctrine()->getManager();
$list = $em->getRepository(Projects::class)->createQueryBuilder('p')
// ->leftjoin('a.sector','s')
->leftjoin('p.album','aa')
->orderBy('p.name','ASC')
->andWhere('p.id <> '.$project->getId())
->andWhere('p.isEnabled = 1')
->setMaxResults(4)
->getQuery()
->getResult();
return $this->render('Default/project.html.twig',[
'project'=>$project,
'list'=>$list,
]);
}
/**
* @Route("/articles/", name="articles")
* @Route("/articles/{offset}/", name="articles-page", requirements={"offset": "\d+"})
* @Route("/articles/{cat}/", name="articles-cat")
* @Route("/articles/{cat}/{offset}/", name="articles-cat-page", requirements={"offset": "\d+"})
*/
public function articles($offset = 1, $cat = null)
{
$offset--;
$limit = 30;
$of = $offset*$limit;
$params = [];
$em = $this->getDoctrine()->getManager();
$cat = $cat ? $em->getRepository(ArticlesCategories::class)->findOneBySlug($cat) : null;
$list = $em->getRepository(Articles::class)->createQueryBuilder('a')
->leftjoin('a.banner','b')
->leftjoin('a.category','c')
->leftjoin('a.type','t')
->leftjoin('a.album','aa')
->leftjoin('a.biblio','ab')
->orderBy('a.date','DESC')
->andWhere("a.date <= '".(new \DateTime())->format('Y-m-d H:i:s')."'")
->andWhere('a.isEnabled = 1')
;
if($cat) {
$list = $list->andWhere('c.id = '.$cat->getId());
$params['cat'] = $cat->getSlug();
}
$count = $list->select('count(distinct(a.id))')->getQuery()->getResult()[0][1];
$list = $list->select('a')
->setMaxResults($limit)
->setFirstResult($of)
->getQuery()->getResult();
return $this->render('Default/articles.html.twig',[
'list'=>$list,
'cat'=>$cat,
'count'=>$count,
'table_limit'=>$limit,
'offset'=>$offset,
'params'=>$params
]);
}
/**
* @Route("/article/{id}/{slug}/", name="article", requirements={"id": "\d+"})
* @Route("/article/{id}/", requirements={"id": "\d+"})
*/
public function article(Articles $article, $slug = null)
{
if(!$article->getIsEnabled() && !$this->isGranted('ROLE_USER'))
return $this->redirectToRoute('articles');
if($article->getURL())
return $this->redirect($article->getURL());
$em = $this->getDoctrine()->getManager();
$list = $em->getRepository(Articles::class)->createQueryBuilder('a')
->leftjoin('a.banner','b')
->leftjoin('a.category','c')
->leftjoin('a.type','t')
->leftjoin('a.album','aa')
->leftjoin('a.biblio','ab')
->orderBy('a.date','DESC')
// ->andWhere('a.id <> '.$article->getId())
->andWhere("a.date <= '".(new \DateTime())->format('Y-m-d H:i:s')."'")
->andWhere('a.isEnabled = 1')
->setMaxResults(6)
->getQuery()
->getResult();
return $this->render('Default/article.html.twig',[
'article'=>$article,
'list'=>$list,
]);
}
/**
* @Route("/evenements/", name="events")
*/
public function events(Request $request)
{
$offset = $request->get('offset') ?? 1;
$keyword = $request->get('q');
$offset--;
$limit = 50;
$of = $offset*$limit;
$em = $this->getDoctrine()->getManager();
$query = $em->getRepository(Events::class)->createQueryBuilder('e')
->where('e.isEnabled = 1')
->orderBy('e.startDate','desc');
if($keyword) $query = $query->andWhere('(e.name like :k or e.startDate like :k or e.endDate like :k or e.place like :k)')
->setParameter('k','%'.$keyword.'%');
$count = $query->select('count(e.id)')->getQuery()->getResult()[0][1];
$list = $query->select('e')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
return $this->render('Default/events.html.twig',[
'list'=>$list,
'count'=>$count,
'table_limit'=>$limit,
'offset'=>$offset,
'keyword'=>$keyword,
]);
}
/**
* @Route("/videos/", name="videos")
* @Route("/videos/{cat}/", name="videos-cat")
*/
public function videos($cat = null)
{
$em = $this->getDoctrine()->getManager();
$videos = $em->getRepository(Videos::class)->findBy(['isEnabled'=>1], ['id'=>'desc']);
return $this->render('Default/videos.html.twig',[
'list'=>$videos
]);
}
/**
* @Route("/video/{id}/", name="video", requirements={"id": "\d+"})
*/
public function video(Videos $video)
{
return $this->render('Default/video.html.twig',[
'video'=>$video
]);
}
/**
* @Route("/structures/", name="structures")
* @Route("/structures/{slug}/", name="structures-cat")
*/
public function structures(StructuresCategories $cat = null)
{
$em = $this->getDoctrine()->getManager();
$filter = ['isEnabled' => 1];
if($cat) $filter['category'] = $cat->getId();
$list = $em->getRepository(Structures::class)->findBy($filter, ['position'=>'DESC']);
// $groups = $cat ? null : $em->getRepository(StructuresCategories::class)->findBy(['isEnabled'=>1], ['id'=>'asc']);
$groups = $em->getRepository(StructuresCategories::class)->findBy(['isEnabled'=>1], ['id'=>'asc']);
return $this->render('Default/structures.html.twig',[
'list'=>$list,
'groups'=>$groups,
'cat'=>$cat,
]);
}
/**
* @Route("/structure/{id}/{slug}/", name="structure")
*/
public function structure(Structures $struct)
{
return $this->render('Default/structure.html.twig',[
'struct'=>$struct,
]);
}
/**
* @Route("/plateformes-services/", name="plateformes-services")
*/
public function partners(Request $request)
{
$offset = $request->get('offset') ?? 1;
$keyword = $request->get('q');
$offset--;
$limit = 50;
$of = $offset*$limit;
$em = $this->getDoctrine()->getManager();
$list = $em->getRepository(Partners::class)->findBy(['isEnabled'=>1],[],$limit,$of);
$count = $em->getRepository(Partners::class)->count(['isEnabled'=>1]);
$query = $em->getRepository(Partners::class)->createQueryBuilder('p')
->where('p.isEnabled = 1');
if($keyword) $query = $query->andWhere('(p.name like :k or p.description like :k or p.website like :k)')
->setParameter('k','%'.$keyword.'%');
$count = $query->select('count(p.id)')->getQuery()->getResult()[0][1];
$list = $query->select('p')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
return $this->render('Default/partners.html.twig',[
'list'=>$list,
'count'=>$count,
'table_limit'=>$limit,
'offset'=>$offset,
'keyword'=>$keyword,
]);
}
/**
* @Route("/documents/", name="resources")
* @Route("/documents/{slug}/", name="resources-cat")
*/
public function resources(Request $request, ResourcesCategories $cat = null)
{
$keyword = $request->get('q');
$offset = $request->get('offset') ?? 1;
$offset--;
$limit = 50;
$of = $offset*$limit;
$em = $this->getDoctrine()->getManager();
$query = $em->getRepository(Resources::class)->createQueryBuilder('r')
->leftjoin('r.category','c')
->where('r.isEnabled = 1')
->orderBy('r.date','desc');
if($cat) $query = $query->andWhere('c.id = '.$cat->getId())->addOrderBy('r.isImportant','desc');
if($keyword)
$query = $query->andWhere('(r.title like :k or r.description like :k or c.label like :k )')
->setParameter('k','%'.$keyword.'%');
$count = $query->select('count(r.id)')->getQuery()->getResult()[0][1];
$list = $query->select('r')->setMaxResults($limit)->setFirstResult($of)->getQuery()->getResult();
return $this->render('Default/resources.html.twig',[
'cat'=>$cat,
'list'=>$list,
'count'=>$count,
'table_limit'=>$limit,
'offset'=>$offset,
'keyword'=>$keyword
]);
}
}