src/Repository/PostRepository.php line 667

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Post;
  4. use App\Entity\PostTranslation;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Component\Intl\Locale;
  8. use App\Pagination\Paginator;
  9. /**
  10.  * @method Post|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method Post|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method Post[]    findAll()
  13.  * @method Post[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14.  */
  15. class PostRepository extends ServiceEntityRepository
  16. {
  17.     public function __construct(ManagerRegistry $registry)
  18.     {
  19.         parent::__construct($registryPost::class);
  20.     }
  21.     /** find conut nb resultat post **/
  22.     public function findCountPost($type null)
  23.     {
  24.         $locale Locale::getDefault();
  25.         $sql =  $this->createQueryBuilder('p')
  26.                      ->select('count(p.id)');
  27.       
  28.         if($type != null){
  29.             $sql->join('p.type_post','typePost')
  30.                 ->andWhere('typePost.id = :type')
  31.                 ->setParameter('type'$type);
  32.         }
  33.         return $sql->getQuery()->getSingleScalarResult();
  34.     }
  35.     /** end off method **/
  36.     public function findPostBySlug($slug)
  37.     {
  38.         $locale Locale::getDefault();
  39.         dump($locale);
  40.         $sql =  $this->createQueryBuilder('p')
  41.                      ->join('p.translations','t')
  42.                      ->andWhere('t.locale = :locale')
  43.                      ->setParameter('locale'$locale);
  44.       
  45.         if($slug){
  46.             $sql->andWhere('t.slug = :slug')
  47.                 ->setParameter('slug'$slug);
  48.         }
  49.         return $sql->getQuery()->getOneOrNullResult();
  50.     }
  51.     public function findPostById($id)
  52.     {
  53.         $locale Locale::getDefault();
  54.         $sql =  $this->createQueryBuilder('p')
  55.                      ->join('p.translations','t')
  56.                      ->andWhere('p.id = :id')
  57.                      ->andWhere('t.actif = true')
  58.                      ->andWhere('t.locale = :locale')
  59.                      ->setParameter('locale'$locale)
  60.                      ->setParameter('id'$id);
  61.       
  62.         return $sql->getQuery()->getResult();
  63.     }
  64.         
  65.     public function findAllPostByType($locale,$type)
  66.     {
  67.        
  68.         $sql =  $this->createQueryBuilder('p')
  69.                      ->join('p.translations','t')
  70.                      ->andWhere('p.post_archive = 0 OR p.post_archive is null')
  71.                      ->andWhere('t.locale = :locale')
  72.                      ->setParameter('locale'$locale);
  73.         if($type){
  74.             $sql->join('p.type_post','tp')
  75.                 ->andWhere('tp.id = :type')
  76.                 ->setParameter('type'$type);
  77.             // if($type == '6'){
  78.             //     $sql->orderBy('p.date_publication','DESC');
  79.             // }
  80.         }
  81.      
  82.         $sql->orderBy('p.position','ASC');
  83.         return $sql->getQuery()->getResult();
  84.     }
  85.     public function findAllOtherPosts($id)
  86.     {
  87.         $locale Locale::getDefault();
  88.         $sql =  $this->createQueryBuilder('p')
  89.                      ->join('p.translations','t')
  90.                      ->andWhere('p.post_archive = 0 OR p.post_archive is null')
  91.                      ->andWhere('t.locale = :locale')
  92.                      ->andWhere('t.actif = true')
  93.                      ->setParameter('locale'$locale);
  94.                     if($id){
  95.                     $sql->andWhere('p.id != :id')
  96.                         ->setParameter('id'$id);
  97.                     }
  98.      
  99.         $sql->orderBy('p.position','ASC');
  100.         return $sql->getQuery()->getResult();
  101.     }
  102.     public function findAllActivesPostsByType($locale,$type)
  103.     {
  104.        
  105.         $sql =  $this->createQueryBuilder('p')
  106.                      ->join('p.translations','t')
  107.                      ->andWhere('p.post_archive = 0 OR p.post_archive is null')
  108.                      ->andWhere('t.locale = :locale')
  109.                      ->setParameter('locale'$locale);
  110.         if($type){
  111.             $sql->join('p.type_post','tp')
  112.                 ->andWhere('tp.id = :type')
  113.                 ->andWhere('t.actif = true')
  114.                 ->setParameter('type'$type);
  115.         }
  116.         $sql->orderBy('p.position','asc');
  117.         
  118.         return $sql->getQuery()->getResult();
  119.     }
  120.     public function findPostByType($type,$option,$nb)
  121.     {
  122.         $locale Locale::getDefault();
  123.         $sql =  $this->createQueryBuilder('p')
  124.                      ->join('p.translations','t')
  125.                      ->join('p.type_post','typePost')
  126.                      ->andWhere('typePost.id = :type')
  127.                      ->andWhere('t.actif = true')
  128.                      ->andWhere('t.locale = :locale')
  129.                      ->setParameter('locale'$locale)
  130.                      ->setParameter('type'$type)
  131.                      ->setMaxResults($nb);
  132.         if($option == '1'){
  133.             $sql->orderBy('p.id''ASC');
  134.         }elseif($option == '2'){
  135.             $sql->orderBy('p.id''DESC');
  136.         }
  137.       
  138.         return $sql->getQuery()->getResult();
  139.     }
  140.     public function findPostActifsHomeByType($type,$option,$nb 1,$all_post false)
  141.     {
  142.         $locale Locale::getDefault();
  143.         $sql =  $this->createQueryBuilder('p')
  144.                      ->join('p.translations','t')
  145.                      ->join('p.type_post','typePost')
  146.                      ->andWhere('typePost.id = :type')
  147.                      ->andWhere('t.actif = true')
  148.                      ->andWhere('p.actif_home = 1')
  149.                      ->andWhere('t.locale = :locale')
  150.                      ->setParameter('locale'$locale)
  151.                      ->setParameter('type'$type);
  152.                      
  153.         if($all_post == false){
  154.            $sql->setMaxResults($nb);
  155.         }
  156.         if($option == '1'){
  157.             $sql->orderBy('p.id''ASC');
  158.         }elseif($option == '2'){
  159.             $sql->orderBy('p.id''DESC');
  160.         }elseif($option == '3'){
  161.             $sql->orderBy('p.date_publication','DESC');
  162.         }elseif($option == '4'){
  163.             $sql->orderBy('p.position''ASC');
  164.         }elseif($option == '5'){
  165.             $sql->orderBy('RAND()');
  166.         }
  167.       
  168.         return $sql->getQuery()->getResult();
  169.     }
  170.     public function findPostByTypeInterne($type,$option,$nb)
  171.     {
  172.         $locale Locale::getDefault();
  173.         $sql =  $this->createQueryBuilder('p')
  174.                      ->join('p.translations','t')
  175.                      ->join('p.type_post','typePost')
  176.                      ->andWhere('typePost.id = :type')
  177.                      ->andWhere('t.actif = true')
  178.                      ->andWhere('t.locale = :locale')
  179.                      ->setParameter('locale'$locale)
  180.                      ->setParameter('type'$type)
  181.                      ->setMaxResults($nb);
  182.         if($option == '1'){
  183.             $sql->orderBy('p.id''ASC');
  184.         }elseif($option == '2'){
  185.             $sql->orderBy('p.id''DESC');
  186.         }elseif($option == '3'){
  187.             $sql->orderBy('p.date_publication','DESC');
  188.         }elseif($option == '4'){
  189.             $sql->orderBy('p.position''ASC');
  190.         }elseif($option == '5'){
  191.             $sql->orderBy('RAND()');
  192.         }
  193.       
  194.         return $sql->getQuery()->getResult();
  195.     }
  196.     
  197.     public function findPostBySystemName($name)
  198.     {
  199.         $locale Locale::getDefault();
  200.         $sql =  $this->createQueryBuilder('p')
  201.                      ->join('p.type_post','typePost')
  202.                      ->join('typePost.translations','translation')
  203.                      ->join('p.translations','t')
  204.                      ->andWhere('t.actif = true')
  205.                      ->andWhere('translation.system_name = :name')
  206.                      ->andWhere('translation.locale = :locale')
  207.                      ->setParameter('locale'$locale)
  208.                      ->setParameter('name'$name)
  209.                      ->getQuery()
  210.                      ->getResult();
  211.      
  212.         return $sql;
  213.     }
  214.     public function findPostBySystemNames($system_name)
  215.     {
  216.         $locale Locale::getDefault();
  217.         $sql =  $this->createQueryBuilder('p')
  218.                      ->join('p.type_post','typePost')
  219.                      ->join('typePost.translations','translation')
  220.                      ->join('p.translations','t')
  221.                      ->andWhere('t.actif = true')
  222.                      ->andWhere("translation.system_name IN(:system_name)")
  223.                      ->andWhere('translation.locale = :locale')
  224.                      ->setParameter('locale'$locale)
  225.                      ->setParameter('system_name'$system_name)
  226.                      ->getQuery()
  227.                      ->getResult();
  228.      
  229.         return $sql;
  230.     }
  231.     public function findPostMaxPosition()
  232.     {
  233.         $sql =  $this->createQueryBuilder('p')
  234.                      ->select('MAX(p.position) as max_position');
  235.         return $sql->getQuery()->getOneOrNullResult();
  236.     }
  237.     public function findPostByCategory($categorie,$page 1)
  238.     {
  239.         
  240.         $id_categorie $categorie->getId();
  241.         $pagination $categorie->getPagination() != null $categorie->getPagination() : false;
  242.         $page_size $categorie->getPageSize() != null $categorie->getPageSize() : 10;
  243.         $order_by 1;
  244.         $order_by $categorie->getOrderBy();
  245.         $req_order "p.position";
  246.         $asc_desc "ASC";
  247.         if($order_by == 0){
  248.             $req_order "p.date_publication";
  249.             $asc_desc "DESC";
  250.         }
  251.         $locale Locale::getDefault();
  252.         $sql =  $this->createQueryBuilder('p')
  253.                      ->join('p.translations','t')
  254.                      ->join('p.PostCategory','post_categorie')
  255.                      ->andWhere('t.actif = true')
  256.                      ->andWhere('post_categorie.Category =:categorie_id')
  257.                      ->andWhere('t.locale = :locale')
  258.                      ->setParameter('locale'$locale)
  259.                      ->setParameter('categorie_id'$id_categorie)
  260.                      ->orderBy($req_order$asc_desc);
  261.         if ($pagination == true) {
  262.             return (new Paginator($sql))->paginate($page,$page_size);
  263.         }else{
  264.             return $sql->getQuery()->getResult();
  265.         }
  266.     }
  267.     /**
  268.      * Retourne les posts par type et par id avec limit
  269.      */
  270.     public function getPostsWithLimit($locale,$type,$limit,$order,$IdSite)
  271.     {
  272.        
  273.         $sql =  $this->createQueryBuilder('p')
  274.                      ->join('p.translations','t')
  275.                      ->andWhere('t.locale = :locale')
  276.                      ->setParameter('locale'$locale);
  277.         if($type){
  278.             $sql->join('p.type_post','tp')
  279.                 ->andWhere('tp.id = :type')
  280.                 ->setParameter('type'$type);
  281.            /* if($type == '6'){
  282.               $sql->orderBy('p.date_publication','DESC');
  283.            } */
  284.         }
  285.         switch ($order) {
  286.             case 0:
  287.                 $sql->orderBy('RAND()');
  288.                 break;
  289.             case 1:
  290.                 $sql->orderBy('p.id','ASC');
  291.                 break;
  292.             case 2:
  293.                 $sql->orderBy('p.id','DESC');
  294.                 break;
  295.             case 3:
  296.                 $sql->orderBy('p.date_publication','DESC');
  297.                 break;
  298.             
  299.             default:
  300.                 $sql->orderBy('p.id','ASC');
  301.                 break;
  302.         }
  303.         if($limit){
  304.             $sql->setMaxResults($limit);
  305.         }
  306.      
  307.         return $sql->getQuery()->getResult();
  308.     }
  309.     /**
  310.      * Retourne la liste des catégories du post
  311.      */
  312.     public function getCategoryPost($post_category$_locale){
  313.         $categories = [];
  314.         if($post_category){
  315.             foreach ($post_category as $key => $post_cat) {
  316.               if($post_cat->getCategory()){
  317.                 $cat $post_cat->getCategory();
  318.                 $categories[] = ['id'=> $cat->getId(),'title'=> $cat->translate($_locale)->getTitreCategorie()];
  319.               }
  320.             }
  321.          }
  322.          return $categories;
  323.     }
  324.     // get article prev or next   
  325.     public function findPostPrevOrNext($ids_categories,$id_post,$action 'next')
  326.     {
  327.         $locale Locale::getDefault();
  328.         $sql =  $this->createQueryBuilder('p')
  329.                      ->join('p.translations','t')
  330.                      ->join('p.PostCategory','post_categorie')
  331.                      ->andWhere('t.actif = true')
  332.                      ->andWhere('p.id != :id_post')
  333.                      ->andWhere('post_categorie.Category IN (:ids_categories)')
  334.                      ->andWhere('t.locale = :locale')
  335.                      ->setParameter('locale'$locale)
  336.                      ->setParameter('ids_categories'$ids_categories)
  337.                      ->setMaxResults(1);
  338.                     
  339.         if($action == 'next') {
  340.              $sql->andWhere('p.id > :id_post')
  341.                  ->orderBy('p.id''asc');
  342.         }else{
  343.              $sql->andWhere('p.id < :id_post')
  344.                  ->orderBy('p.id''DESC');
  345.         }
  346.         $sql->setParameter('id_post'$id_post);
  347.         return $sql->getQuery()->getOneOrNullResult();
  348.     }
  349.     /*****************************************************************
  350.      **     get liste actualite related with secteur activte       ***
  351.      *****************************************************************/
  352.     public function findActualiteByActivite()
  353.     {
  354.         $locale Locale::getDefault();
  355.         $sql =  $this->createQueryBuilder('p')
  356.                      ->andWhere('p.id_activite IS NOT NULL or p.id_sous_activite IS NOT NULL or p.id_secteur IS NOT NULL')
  357.                      ->join('p.translations','t')
  358.                      ->andWhere('t.actif = true')
  359.                      ->andWhere('t.locale = :locale')
  360.                      ->setParameter('locale'$locale)
  361.                      ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
  362.                      ->setParameter('currentDate', new \DateTime())
  363.                      ->join('p.type_post','typepost')
  364.                      ->andWhere('typepost.id != 11')
  365.                      ->getQuery()
  366.                      ->getResult();
  367.      
  368.         return $sql;
  369.     }
  370.     /*****************************************************************
  371.     **     requete sql ref                                         ***
  372.     *****************************************************************/
  373.     public function findPostByIdSecteur($id,$id_activite,$id_secteur)
  374.     {
  375.         $locale Locale::getDefault();
  376.         $sql =  $this->createQueryBuilder('p')
  377.                      ->andWhere('p.id != :id')
  378.                      ->join('p.translations','t')
  379.                      ->andWhere('t.actif = true')
  380.                      ->andWhere('p.id_secteur = :id_secteur')
  381.                      ->andWhere('p.id_activite = :id_activite')
  382.                      ->andWhere('t.locale = :locale')
  383.                      ->setParameter('locale'$locale)
  384.                      ->setParameter('id_secteur'$id_secteur)
  385.                      ->setParameter('id_activite'$id_activite)
  386.                      ->setParameter('id'$id)
  387.                      ->getQuery()
  388.                      ->getResult();
  389.      
  390.         return $sql;
  391.     }
  392.     public function findPageRefByIdActivite($id_activite,$id_diff null)
  393.     {
  394.         $locale Locale::getDefault();
  395.         $sql =  $this->createQueryBuilder('p')
  396.                      ->join('p.translations','t')
  397.                      ->join('p.type_post','typepost')
  398.                      ->andWhere('typepost.id = 11')
  399.                      ->andWhere('t.actif = true')
  400.                      ->andWhere('p.id_activite = :id_activite')
  401.                      ->andWhere('t.locale = :locale')
  402.                      ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
  403.                      ->setParameter('currentDate', new \DateTime())
  404.                      ->setParameter('locale'$locale)
  405.                      ->setParameter('id_activite'$id_activite)
  406.                      ->andWhere('p.id_sous_activite is NULL')
  407.                      ->setMaxResults(3)
  408.                      ->orderBy('p.id','desc');
  409.                   
  410.         if ($id_diff != null) {
  411.             $sql->andWhere('p.id != :id_diff')
  412.                 ->setParameter('id_diff'$id_diff);
  413.         }
  414.      
  415.         return $sql->getQuery()->getResult();
  416.     }
  417.     public function findPageRefByIdSousActivite($id_sous_activite,$id_diff null)
  418.     {
  419.         $locale Locale::getDefault();
  420.         $sql =  $this->createQueryBuilder('p')
  421.                      ->join('p.translations','t')
  422.                      ->join('p.type_post','typepost')
  423.                      ->andWhere('typepost.id = 11')
  424.                      ->andWhere('t.actif = true')
  425.                      ->andWhere('p.id_sous_activite = :id_sous_activite')
  426.                      ->andWhere('t.locale = :locale')
  427.                      ->setParameter('locale'$locale)
  428.                      ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
  429.                      ->setParameter('currentDate', new \DateTime())
  430.                      ->setParameter('id_sous_activite'$id_sous_activite)
  431.                      ->setMaxResults(3)
  432.                      ->orderBy('p.id','desc');
  433.                      
  434.         if ($id_diff != null) {
  435.             $sql->andWhere('p.id != :id_diff')
  436.                 ->setParameter('id_diff'$id_diff);
  437.         }
  438.                  
  439.         return $sql->getQuery()->getResult();
  440.     }
  441.     public function findPageRefByIdActiviteAndIdSousActivite($id_activite,$id_sous_activite,$id_diff null)
  442.     {
  443.         $locale Locale::getDefault();
  444.         $sql =  $this->createQueryBuilder('p')
  445.                      ->join('p.translations','t')
  446.                      ->join('p.type_post','typepost')
  447.                      ->andWhere('typepost.id = 11')
  448.                      ->andWhere('t.actif = true')
  449.                      ->andWhere('p.id_activite = :id_activite')
  450.                      ->andWhere('t.locale = :locale')
  451.                      ->setParameter('locale'$locale)
  452.                      ->setParameter('id_activite'$id_activite)
  453.                      ->andWhere('p.id_sous_activite = :id_sous_activite')
  454.                      ->setParameter('id_sous_activite'$id_sous_activite)
  455.                      ->setMaxResults(3)
  456.                      ->orderBy('p.id','desc');
  457.                   
  458.         if ($id_diff != null) {
  459.             $sql->andWhere('p.id != :id_diff')
  460.                 ->setParameter('id_diff'$id_diff);
  461.         }
  462.      
  463.         return $sql->getQuery()->getResult();
  464.     }
  465.     public function findPageClientByIdActiviteOrSousActivite($id_activite,$type 'activite')
  466.     {
  467.         $locale Locale::getDefault();
  468.         $sql =  $this->createQueryBuilder('p')
  469.                      ->join('p.translations','t')
  470.                      ->join('p.type_post','typepost')
  471.                      ->andWhere('typepost.id != 11')
  472.                      ->andWhere('t.actif = true')
  473.                      ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
  474.                      ->setParameter('currentDate', new \DateTime())
  475.                      ->andWhere('t.locale = :locale')
  476.                      ->setParameter('locale'$locale);
  477.              
  478.         if ($type == 'activite') {
  479.             $sql->andWhere('p.id_activite = :id_activite')
  480.                 ->setParameter('id_activite'$id_activite);
  481.         }else{
  482.             $sql->andWhere('p.id_sous_activite = :id_sous_activite')
  483.                 ->setParameter('id_sous_activite'$id_activite);
  484.         }
  485.         $sql->setMaxResults(3)->orderBy('p.id','desc');
  486.      
  487.         return $sql->getQuery()->getResult();
  488.     }
  489.     public function findPageClientByIdActiviteAndSousActivite($id_activite,$sous_activite)
  490.     {
  491.         $locale Locale::getDefault();
  492.         $sql =  $this->createQueryBuilder('p')
  493.                      ->join('p.translations','t')
  494.                      ->join('p.type_post','typepost')
  495.                      ->andWhere('typepost.id != 11')
  496.                      ->andWhere('t.actif = true')
  497.                      ->andWhere('t.locale = :locale')
  498.                      ->setParameter('locale'$locale)
  499.                      ->andWhere('p.id_activite = :id_activite')
  500.                      ->setParameter('id_activite'$id_activite)
  501.                      ->andWhere('p.id_sous_activite = :id_sous_activite')
  502.                      ->setParameter('id_sous_activite'$sous_activite);
  503.         $sql->setMaxResults(3)->orderBy('p.id','desc');
  504.      
  505.         return $sql->getQuery()->getResult();
  506.     }
  507.     public function findPageRefByIdsSousActivite($ids_sous_activite = [])
  508.     {
  509.         $locale Locale::getDefault();
  510.         $req1 =  $this->createQueryBuilder('p')
  511.                      ->join('p.translations','t')
  512.                      ->join('p.type_post','typepost')
  513.                      ->andWhere('typepost.id = 11')
  514.                      ->andWhere('t.actif = true')
  515.                      ->andWhere('p.actif_home = true')
  516.                      ->andWhere('p.id_sous_activite IN (:ids_sous_activite)')
  517.                      ->andWhere('p.type_page_ref = :type_page_ref')
  518.                      ->andWhere('t.locale = :locale')
  519.                      ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
  520.                      ->setParameter('currentDate', new \DateTime())
  521.                      ->setParameter('locale'$locale)
  522.                      ->setParameter('ids_sous_activite'$ids_sous_activite)
  523.                      ->setParameter('type_page_ref''activite_secondaire')
  524.                      ->setMaxResults(3)
  525.                      ->orderBy('p.id','desc')->getQuery()->getResult();
  526.         if (empty($req1)) {
  527.             $req1 =  $this->createQueryBuilder('p')
  528.                         ->join('p.translations','t')
  529.                         ->join('p.type_post','typepost')
  530.                         ->andWhere('typepost.id = 11')
  531.                         ->andWhere('t.actif = true')
  532.                        // ->andWhere('p.actif_home = true')
  533.                         ->andWhere('p.id_sous_activite IN (:ids_sous_activite)')
  534.                         ->andWhere('p.type_page_ref = :type_page_ref')
  535.                         ->andWhere('t.locale = :locale')
  536.                         ->setParameter('locale'$locale)
  537.                         ->setParameter('ids_sous_activite'$ids_sous_activite)
  538.                         ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
  539.                         ->setParameter('currentDate', new \DateTime())
  540.                         ->setParameter('type_page_ref''activite_secondaire')
  541.                         ->setMaxResults(3)
  542.                         ->orderBy('RAND()')
  543.                         ->orderBy('p.id','desc')->getQuery()->getResult();
  544.         }
  545.                  
  546.         return $req1;
  547.     }
  548.     
  549.     public function findPageRefByIdsSousActiviteAndActivitePrincipal($id_activite,$id_secteur null)
  550.     {
  551.         $locale Locale::getDefault();
  552.         $sql =  $this->createQueryBuilder('p')
  553.                      ->join('p.translations','t')
  554.                      ->join('p.type_post','typepost')
  555.                      ->andWhere('typepost.id = 11')
  556.                      ->andWhere('t.actif = true')
  557.                      ->andWhere('p.id_sous_activite IS NOT NULL')
  558.                      ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
  559.                      ->setParameter('currentDate', new \DateTime())
  560.                      //->andWhere('p.id_sous_activite IN (:ids_sous_activite)')
  561.                      // ->setParameter('ids_sous_activite', $ids_sous_activite)
  562.                      ->andWhere('p.type_page_ref = :type_page_ref')
  563.                      ->andWhere('p.id_activite = :id_activite')
  564.                      ->andWhere('t.locale = :locale')
  565.                      ->setParameter('locale'$locale)
  566.                      ->setParameter('id_activite'$id_activite)
  567.                      ->setParameter('type_page_ref''activite_secondaire');
  568.             
  569.         if ($id_secteur != null) {
  570.             $sql->andWhere('p.id_secteur = :id_secteur')
  571.                 ->setParameter('id_secteur'$id_secteur);
  572.         }
  573.         $sql->groupBy('p.id_sous_activite')
  574.             //->distinct('p.id_secteur');
  575.             ->orderBy('RAND()')
  576.             ->setMaxResults(3);
  577.             //->orderBy('p.id','desc');
  578.         return $sql->getQuery()->getResult();
  579.     }
  580.     public function findAllPostNotArchived($locale)
  581.     {
  582.        
  583.         $sql =  $this->createQueryBuilder('p')
  584.                      ->join('p.translations','t')
  585.                      ->andWhere('p.post_archive = 0 OR p.post_archive is null')
  586.                      ->andWhere('t.locale = :locale')
  587.                      ->setParameter('locale'$locale);
  588.      
  589.         $sql->orderBy('p.position','ASC');
  590.         return $sql->getQuery()->getResult();
  591.     }
  592.     /********************* Sql gestion des produits suivant categories ***********************/
  593.     public function findPostBySpecifiqueCategory($categorie,$page 1,$categorie_ids = [])
  594.     {
  595.         
  596.        // $id_categorie = $categorie->getId();
  597.         $pagination $categorie->getPagination() != null $categorie->getPagination() : false;
  598.         $page_size $categorie->getPageSize() != null $categorie->getPageSize() : 10;
  599.         $order_by 1;
  600.         $order_by $categorie->getOrderBy();
  601.         $req_order "p.position";
  602.         $asc_desc "ASC";
  603.         if($order_by == 0){
  604.             $req_order "p.date_publication";
  605.             $asc_desc "DESC";
  606.         }
  607.         $locale Locale::getDefault();
  608.         $sql =  $this->createQueryBuilder('p')
  609.                      ->join('p.translations','t')
  610.                      ->join('p.PostCategory','post_categorie')
  611.                      ->andWhere('t.actif = true')
  612.                      ->andWhere('post_categorie.Category IN (:categorie_ids)')
  613.                      ->andWhere('t.locale = :locale')
  614.                      ->setParameter('locale'$locale)
  615.                      ->setParameter('categorie_ids'$categorie_ids)
  616.                      ->orderBy($req_order$asc_desc);
  617.         if ($pagination == true) {
  618.             return (new Paginator($sql))->paginate($page,$page_size);
  619.         }else{
  620.             return $sql->getQuery()->getResult();
  621.         }
  622.     }
  623.     /**************** get produit related *************/
  624.     public function findProductRelated($type,$diff_id,$id_default_categorie)
  625.     {
  626.         $locale Locale::getDefault();
  627.         $sql =  $this->createQueryBuilder('p')
  628.                      ->join('p.translations','t')
  629.                      ->andWhere('t.actif = true')
  630.                      ->andWhere('p.id != :diff_id')
  631.                      ->andWhere('p.default_categorie = :id_default_categorie')
  632.                      ->andWhere('p.post_archive = 0 OR p.post_archive is null')
  633.                      ->join('p.type_post','typePost')
  634.                      ->andWhere('typePost.id = :type')
  635.                      ->andWhere('t.locale = :locale')
  636.                      ->setParameter('id_default_categorie'$id_default_categorie)
  637.                      ->setParameter('locale'$locale)
  638.                      ->setParameter('diff_id'$diff_id)
  639.                      ->setParameter('type'$type);
  640.      
  641.         return $sql->getQuery()->getResult();
  642.     }
  643.     /**************** get related Annonces *************/
  644.     public function findRelatedAnnonces($type,$diff_id)
  645.     {
  646.         $locale Locale::getDefault();
  647.         $sql =  $this->createQueryBuilder('p')
  648.                         ->join('p.translations','t')
  649.                         ->andWhere('t.actif = true')
  650.                         ->andWhere('p.id != :diff_id')
  651.                         ->andWhere('p.post_archive = 0 OR p.post_archive is null')
  652.                         ->join('p.type_post','typePost')
  653.                         ->andWhere('typePost.id = :type')
  654.                         ->andWhere('t.locale = :locale')
  655.                         ->setParameter('locale'$locale)
  656.                         ->setParameter('diff_id'$diff_id)
  657.                         ->setParameter('type'$type);
  658.         
  659.         return $sql->getQuery()->getResult();
  660.     }
  661.     /*****************************************************************************************/
  662.     /********************** Affichage Détails produit pour le panier *************************/
  663.     public function getCartProductInfos($id)
  664.     {
  665.         $locale Locale::getDefault();
  666.         $sql =  $this->createQueryBuilder('p')
  667.                     ->select('p.id''t.title''p.prix_produit''p.image')
  668.                      ->join('p.translations','t')
  669.                      ->andWhere('t.actif = true')
  670.                      ->andWhere('p.id = :id')
  671.                      ->andWhere('p.post_archive = 0 OR p.post_archive is null')
  672.                      ->join('p.type_post','typePost')
  673.                      ->andWhere('t.locale = :locale')
  674.                      ->setParameter('locale'$locale)
  675.                      ->setParameter('id'$id)
  676.                      ->getQuery()
  677.                      ->getOneOrNullResult();
  678.         return $sql;
  679.     }
  680.     /*****************************************************************************************/
  681.     /* find slug page by alias */
  682.     public function findSlugPageByAlias($alias)
  683.     {
  684.         $locale Locale::getDefault();
  685.         $sql =  $this->createQueryBuilder('p')
  686.                      ->join('p.translations','t')
  687.                      ->andWhere('t.locale = :locale')
  688.                      ->setParameter('locale'$locale)      
  689.                      ->andWhere('p.alias = :alias')
  690.                      ->setParameter('alias'$alias);
  691.       
  692.         return $sql->getQuery()->getOneOrNullResult();
  693.     }
  694.     public function findSystemNameByIdPost($id_post)
  695.     {
  696.         $locale Locale::getDefault();
  697.         $sql =  $this->createQueryBuilder('p')
  698.                      ->select('typePost.id')
  699.                      ->join('p.type_post','typePost')
  700.                     // ->join('typePost.translations','translation')
  701.                      ->andWhere('p.id = :id_post')
  702.                      ->setParameter('id_post'$id_post)
  703.                      ->getQuery()
  704.                      ->getOneOrNullResult();
  705.      
  706.         return $sql;
  707.     }
  708. }