<?php
namespace App\Repository;
use App\Entity\Post;
use App\Pagination\Paginator;
use App\Entity\PostTranslation;
use Symfony\Component\Intl\Locale;
use Doctrine\Persistence\ManagerRegistry;
use App\Repository\PostRefRepositoryMethodsTrait;
use App\Repository\PostActualitesRepositoryMethodsTrait;
use App\Repository\MethodsTrait\NbPostRepositoryMethodsTrait;
use App\Repository\MethodsTrait\PostArchiveRepositoryMethodsTrait;
use App\Repository\MethodsTrait\SearchResultatRepositoryMethodsTrait;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
/**
* @method Post|null find($id, $lockMode = null, $lockVersion = null)
* @method Post|null findOneBy(array $criteria, array $orderBy = null)
* @method Post[] findAll()
* @method Post[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PostRepository extends ServiceEntityRepository
{
use PostRefRepositoryMethodsTrait;
use PostArchiveRepositoryMethodsTrait;
use PostActualitesRepositoryMethodsTrait;
use SearchResultatRepositoryMethodsTrait;
use NbPostRepositoryMethodsTrait;
private $languageRepository;
public function __construct(ManagerRegistry $registry,LanguageRepository $languageRepository)
{
parent::__construct($registry, Post::class);
$this->languageRepository = $languageRepository;
}
/** find conut nb resultat post **/
public function findCountPost($type = null)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->select('count(p.id)');
if($type != null){
$sql->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->setParameter('type', $type);
}
return $sql->getQuery()->getSingleScalarResult();
}
/** end off method **/
//Method used only in front
public function findPostBySlug($slug)
{
$languages = $this->languageRepository->findActifLang();
$locale = Locale::getDefault();
// $sql = $this->createQueryBuilder('p')
// ->join('p.translations','t')
// ->andWhere('t.locale = :locale')
// ->setParameter('locale', $locale)
// ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
// ->setParameter('currentDate', new \DateTime());
// if($slug){
// $sql->andWhere('t.slug = :slug')
// ->setParameter('slug', $slug);
// }
// return $sql->getQuery()->getOneOrNullResult();
$resultat = null;
if ($languages) {
foreach ($languages as $language) {
$qb = $this->createQueryBuilder('u')
->join('u.translations','t')
->andWhere('t.slug =:slug')
->andWhere('t.locale = :locale')
->setParameter('slug', $slug)
->setParameter('locale', $language->getLanguageCode());
if ($qb->setMaxResults(1)->getQuery()->getOneOrNullResult()) {
$resultat = $qb->setMaxResults(1)->getQuery()->getOneOrNullResult();
return $resultat;
}
}
}
return $resultat;
}
public function findPostById($id)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('p.id = :id')
->andWhere('t.actif = true')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('id', $id)
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime());
return $sql->getQuery()->getResult();
}
public function findAllPostByType($locale,$type,$categorie = null)
{
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('p.post_archive is null')
->andWhere('p.post_archive = 0 OR p.post_archive is null')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale);
if($type){
$sql->join('p.type_post','tp')
->andWhere('tp.id = :type')
->setParameter('type', $type);
// if($type == '6'){
// $sql->orderBy('p.date_publication','DESC');
// }
}
if ($categorie != null) {
$sql->join('p.PostCategory','post_categorie')
->andWhere('post_categorie.Category IN (:categorie_ids)')
->setParameter('categorie_ids', [$categorie]);
}
$sql->orderBy('p.position','asc');
return $sql->getQuery()->getResult();
}
public function findAllOtherPosts($id)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('p.post_archive = 0 OR p.post_archive is null')
->andWhere('t.locale = :locale')
->andWhere('t.actif = true')
->setParameter('locale', $locale);
if($id){
$sql->andWhere('p.id != :id')
->setParameter('id', $id);
}
$sql->orderBy('p.position','ASC');
return $sql->getQuery()->getResult();
}
public function findAllActivesPostsByType($locale,$type)
{
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('p.post_archive = 0 OR p.post_archive is null')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale);
if($type){
$sql->join('p.type_post','tp')
->andWhere('tp.id = :type')
->andWhere('t.actif = true')
->setParameter('type', $type);
}
$sql->orderBy('p.position','asc');
return $sql->getQuery()->getResult();
}
public function findPostByType($type,$option,$nb)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->andWhere('t.actif = true')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('type', $type)
->setMaxResults($nb);
if($option == '1'){
$sql->orderBy('p.id', 'ASC');
}elseif($option == '2'){
$sql->orderBy('p.id', 'DESC');
}
return $sql->getQuery()->getResult();
}
public function findPostActifsHomeByType($type,$option,$nb = 1,$all_post = false)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->andWhere('t.actif = true')
->andWhere('p.actif_home = 1')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('type', $type)
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime());
if($all_post == false){
$sql->setMaxResults($nb);
}
if($option == '1'){
$sql->orderBy('p.id', 'ASC');
}elseif($option == '2'){
$sql->orderBy('p.id', 'DESC');
}elseif($option == '3'){
$sql->orderBy('p.date_publication','DESC');
}elseif($option == '4'){
$sql->orderBy('p.position', 'ASC');
}elseif($option == '5'){
$sql->orderBy('RAND()');
}
return $sql->getQuery()->getResult();
}
public function findPostByTypeInterne($type,$option,$nb)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->andWhere('t.actif = true')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('type', $type)
->setMaxResults($nb);
if($option == '1'){
$sql->orderBy('p.id', 'ASC');
}elseif($option == '2'){
$sql->orderBy('p.id', 'DESC');
}elseif($option == '3'){
$sql->orderBy('p.date_publication','DESC');
}elseif($option == '4'){
$sql->orderBy('p.position', 'ASC');
}elseif($option == '5'){
$sql->orderBy('RAND()');
}
return $sql->getQuery()->getResult();
}
public function findPostBySystemName($name)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.type_post','typePost')
->join('typePost.translations','translation')
->join('p.translations','t')
->andWhere('t.actif = true')
->andWhere('translation.system_name = :name')
->andWhere('translation.locale = :locale')
->setParameter('locale', $locale)
->setParameter('name', $name)
->getQuery()
->getResult();
return $sql;
}
public function findPostBySystemNames($system_name)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.type_post','typePost')
->join('typePost.translations','translation')
->join('p.translations','t')
->andWhere('t.actif = true')
->andWhere("translation.system_name IN(:system_name)")
->andWhere('translation.locale = :locale')
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->setParameter('locale', $locale)
->setParameter('system_name', $system_name)
->getQuery()
->getResult();
return $sql;
}
public function findPostMaxPosition()
{
$sql = $this->createQueryBuilder('p')
->select('MAX(p.position) as max_position');
return $sql->getQuery()->getOneOrNullResult();
}
public function findPostByCategory($categorie,$page = 1)
{
$id_categorie = $categorie->getId();
$pagination = $categorie->getPagination() != null ? $categorie->getPagination() : false;
$page_size = $categorie->getPageSize() != null ? $categorie->getPageSize() : 10;
$order_by = 1;
$order_by = $categorie->getOrderBy();
$req_order = "p.position";
$asc_desc = "ASC";
if($order_by == 0){
$req_order = "p.date_publication";
$asc_desc = "DESC";
}
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.PostCategory','post_categorie')
->andWhere('t.actif = true')
->andWhere('post_categorie.Category =:categorie_id')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('categorie_id', $id_categorie)
->orderBy($req_order, $asc_desc);
if ($pagination == true) {
return (new Paginator($sql))->paginate($page,$page_size);
}else{
return $sql->getQuery()->getResult();
}
}
/**
* Retourne les posts par type et par id avec limit
*/
public function getPostsWithLimit($locale,$type,$limit,$order,$IdSite)
{
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale);
if($type){
$sql->join('p.type_post','tp')
->andWhere('tp.id = :type')
->setParameter('type', $type);
/* if($type == '6'){
$sql->orderBy('p.date_publication','DESC');
} */
}
switch ($order) {
case 0:
$sql->orderBy('RAND()');
break;
case 1:
$sql->orderBy('p.id','ASC');
break;
case 2:
$sql->orderBy('p.id','DESC');
break;
case 3:
$sql->orderBy('p.date_publication','DESC');
break;
default:
$sql->orderBy('p.id','ASC');
break;
}
if($limit){
$sql->setMaxResults($limit);
}
return $sql->getQuery()->getResult();
}
/**
* Retourne la liste des catégories du post
*/
public function getCategoryPost($post_category, $_locale){
$categories = [];
if($post_category){
foreach ($post_category as $key => $post_cat) {
if($post_cat->getCategory()){
$cat = $post_cat->getCategory();
$categories[] = ['id'=> $cat->getId(),'title'=> $cat->translate($_locale)->getTitreCategorie()];
}
}
}
return $categories;
}
// get article prev or next
public function findPostPrevOrNext($categoiePost,$post,$action = 'next')
{
$id_categorie = $categoiePost->getId();
$order_categorie = $categoiePost->getOrderBy();
$id_post = $post->getId();
$position_post = $post->getPosition();
$date_publication = $post->getDatePublication();
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.PostCategory','post_categorie')
->andWhere('t.actif = true')
->andWhere('p.id != :id_post')
->andWhere('post_categorie.Category = :id_categorie')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('id_categorie', $id_categorie)
->setMaxResults(1);
if(($order_categorie == 0 || $order_categorie == 2) and $date_publication){
$sql->setParameter('date_publication', $date_publication);
if($action == 'next') {
$sql->andWhere('p.date_publication > :date_publication')
->orderBy('p.date_publication', 'asc');
}else{
$sql->andWhere('p.date_publication < :date_publication')
->orderBy('p.date_publication', 'DESC');
}
}else{
$sql->setParameter('position_post', $position_post);
if($action == 'next') {
$sql->andWhere('p.position > :position_post')
->orderBy('p.position', 'asc');
}else{
$sql->andWhere('p.position < :position_post')
->orderBy('p.position', 'DESC');
}
}
$sql->setParameter('id_post', $id_post);
return $sql->getQuery()->getOneOrNullResult();
}
/*****************************************************************
** get liste actualite related with secteur activte ***
*****************************************************************/
public function findActualiteByActivite()
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->andWhere('p.id_activite IS NOT NULL or p.id_sous_activite IS NOT NULL or p.id_secteur IS NOT NULL')
->join('p.translations','t')
->andWhere('t.actif = true')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->join('p.type_post','typepost')
->andWhere('typepost.id != 11')
->getQuery()
->getResult();
return $sql;
}
/*****************************************************************
** requete sql ref ***
*****************************************************************/
public function findPostByIdSecteur($id,$id_activite,$id_secteur)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->andWhere('p.id != :id')
->join('p.translations','t')
->andWhere('t.actif = true')
->andWhere('p.id_secteur = :id_secteur')
->andWhere('p.id_activite = :id_activite')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('id_secteur', $id_secteur)
->setParameter('id_activite', $id_activite)
->setParameter('id', $id)
->getQuery()
->getResult();
return $sql;
}
public function findPageRefByIdActivite($id_activite,$id_diff = null)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id = 11')
->andWhere('t.actif = true')
->andWhere('p.id_activite = :id_activite')
->andWhere('t.locale = :locale')
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->setParameter('locale', $locale)
->setParameter('id_activite', $id_activite)
->andWhere('p.id_sous_activite is NULL')
->setMaxResults(3)
->orderBy('p.id','desc');
if ($id_diff != null) {
$sql->andWhere('p.id != :id_diff')
->setParameter('id_diff', $id_diff);
}
return $sql->getQuery()->getResult();
}
public function findPageRefByIdSousActivite($id_sous_activite,$id_diff = null)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id = 11')
->andWhere('t.actif = true')
->andWhere('p.id_sous_activite = :id_sous_activite')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->setParameter('id_sous_activite', $id_sous_activite)
->setMaxResults(3)
->orderBy('p.id','desc');
if ($id_diff != null) {
$sql->andWhere('p.id != :id_diff')
->setParameter('id_diff', $id_diff);
}
return $sql->getQuery()->getResult();
}
public function findPageRefByIdActiviteAndIdSousActivite($id_activite,$id_sous_activite,$id_diff = null)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id = 11')
->andWhere('t.actif = true')
->andWhere('p.id_activite = :id_activite')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('id_activite', $id_activite)
->andWhere('p.id_sous_activite = :id_sous_activite')
->setParameter('id_sous_activite', $id_sous_activite)
->setMaxResults(3)
->orderBy('p.id','desc');
if ($id_diff != null) {
$sql->andWhere('p.id != :id_diff')
->setParameter('id_diff', $id_diff);
}
return $sql->getQuery()->getResult();
}
public function findPageClientByIdActiviteOrSousActivite($id_activite,$type = 'activite')
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id != 11')
->andWhere('t.actif = true')
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->andWhere('t.locale = :locale')
->setParameter('locale', $locale);
if ($type == 'activite') {
$sql->andWhere('p.id_activite = :id_activite')
->setParameter('id_activite', $id_activite);
}else{
$sql->andWhere('p.id_sous_activite = :id_sous_activite')
->setParameter('id_sous_activite', $id_activite);
}
$sql->setMaxResults(3)->orderBy('p.id','desc');
return $sql->getQuery()->getResult();
}
public function findPageClientByIdActiviteAndSousActivite($id_activite,$sous_activite)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id != 11')
->andWhere('t.actif = true')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->andWhere('p.id_activite = :id_activite')
->setParameter('id_activite', $id_activite)
->andWhere('p.id_sous_activite = :id_sous_activite')
->setParameter('id_sous_activite', $sous_activite);
$sql->setMaxResults(3)->orderBy('p.id','desc');
return $sql->getQuery()->getResult();
}
public function findPageRefByIdsSousActivite($ids_sous_activite = [])
{
$locale = Locale::getDefault();
$req1 = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id = 11')
->andWhere('t.actif = true')
->andWhere('p.actif_home = true')
->andWhere('p.id_sous_activite IN (:ids_sous_activite)')
->andWhere('p.type_page_ref = :type_page_ref')
->andWhere('t.locale = :locale')
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->setParameter('locale', $locale)
->setParameter('ids_sous_activite', $ids_sous_activite)
->setParameter('type_page_ref', 'activite_secondaire')
->setMaxResults(3)
->orderBy('p.id','desc')->getQuery()->getResult();
if (empty($req1)) {
$req1 = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id = 11')
->andWhere('t.actif = true')
// ->andWhere('p.actif_home = true')
->andWhere('p.id_sous_activite IN (:ids_sous_activite)')
->andWhere('p.type_page_ref = :type_page_ref')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('ids_sous_activite', $ids_sous_activite)
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->setParameter('type_page_ref', 'activite_secondaire')
->setMaxResults(3)
->orderBy('RAND()')
->orderBy('p.id','desc')->getQuery()->getResult();
}
return $req1;
}
public function findPageRefByIdsSousActiviteAndActivitePrincipal($id_activite,$id_secteur = null)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typepost')
->andWhere('typepost.id = 11')
->andWhere('t.actif = true')
->andWhere('p.id_sous_activite IS NOT NULL')
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
//->andWhere('p.id_sous_activite IN (:ids_sous_activite)')
// ->setParameter('ids_sous_activite', $ids_sous_activite)
->andWhere('p.type_page_ref = :type_page_ref')
->andWhere('p.id_activite = :id_activite')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('id_activite', $id_activite)
->setParameter('type_page_ref', 'activite_secondaire');
if ($id_secteur != null) {
$sql->andWhere('p.id_secteur = :id_secteur')
->setParameter('id_secteur', $id_secteur);
}
$sql->groupBy('p.id_sous_activite')
//->distinct('p.id_secteur');
->orderBy('RAND()')
->setMaxResults(3);
//->orderBy('p.id','desc');
return $sql->getQuery()->getResult();
}
public function findAllPostNotArchived($locale)
{
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('p.post_archive = 0 OR p.post_archive is null')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale);
$sql->orderBy('p.position','ASC');
return $sql->getQuery()->getResult();
}
/********************* Sql gestion des produits suivant categories ***********************/
public function findPostBySpecifiqueCategory($categorie,$page = 1,$categorie_ids = [])
{
// $id_categorie = $categorie->getId();
$pagination = $categorie->getPagination() != null ? $categorie->getPagination() : false;
$page_size = $categorie->getPageSize() != null ? $categorie->getPageSize() : 10;
$order_by = $categorie->getOrderBy();
switch ($order_by) {
case 0:
$req_order = "p.date_publication";
$asc_desc = "ASC";
break;
case 1:
$req_order = "p.id";
$asc_desc = "ASC";
break;
case 2:
$req_order = "p.date_publication";
$asc_desc = "DESC";
break;
case 3:
$req_order = "p.id";
$asc_desc = "DESC";
break;
case 4:
$req_order = "p.position";
$asc_desc = "ASC";
break;
default:
$req_order = "p.position";
$asc_desc = "ASC";
}
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.PostCategory','post_categorie')
->andWhere('t.actif = true')
->andWhere('p.archive IS NULL OR p.archive = false')
->andWhere('post_categorie.Category = :categorie or post_categorie.Category IN (:categorie_ids)')
->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
->setParameter('currentDate', new \DateTime())
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('categorie_ids', $categorie_ids)
->setParameter('categorie', $categorie)
->addOrderBy('CASE WHEN p.generate_with_ai = 1 THEN 1 ELSE 0 END,'. $req_order, $asc_desc)
->orderBy($req_order, $asc_desc);
if ($pagination == true) {
return (new Paginator($sql))->paginate($page,$page_size);
}else{
return $sql->getQuery()->getResult();
}
}
/**************** get produit related *************/
public function findProductRelated($type,$diff_id,$id_default_categorie)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('t.actif = true')
->andWhere('p.id != :diff_id')
->andWhere('p.default_categorie = :id_default_categorie')
->andWhere('p.post_archive = 0 OR p.post_archive is null')
->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->andWhere('t.locale = :locale')
->setParameter('id_default_categorie', $id_default_categorie)
->setParameter('locale', $locale)
->setParameter('diff_id', $diff_id)
->setParameter('type', $type);
return $sql->getQuery()->getResult();
}
/**************** get related Annonces *************/
public function findRelatedAnnonces($type,$diff_id)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('t.actif = true')
->andWhere('p.id != :diff_id')
->andWhere('p.post_archive = 0 OR p.post_archive is null')
->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('diff_id', $diff_id)
->setParameter('type', $type);
return $sql->getQuery()->getResult();
}
/*****************************************************************************************/
/********************** Affichage Détails produit pour le panier *************************/
public function getCartProductInfos($id)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->select('p.id', 't.title', 'p.prix_produit', 'p.image')
->join('p.translations','t')
->andWhere('t.actif = true')
->andWhere('p.id = :id')
->andWhere('p.post_archive = 0 OR p.post_archive is null')
->join('p.type_post','typePost')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('id', $id)
->getQuery()
->getOneOrNullResult();
return $sql;
}
/*****************************************************************************************/
/* find slug page by alias */
public function findSlugPageByAlias($alias)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->andWhere('p.alias = :alias')
->setParameter('alias', $alias);
return $sql->getQuery()->getOneOrNullResult();
}
public function findSlugPageById($id_post)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->select('t.slug')
->join('p.translations','t')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->andWhere('p.id = :id_post')
->setParameter('id_post', $id_post);
return $sql->getQuery()->getOneOrNullResult();
}
public function findSystemNameByIdPost($id_post)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->select('typePost.id')
->join('p.type_post','typePost')
// ->join('typePost.translations','translation')
->andWhere('p.id = :id_post')
->setParameter('id_post', $id_post)
->getQuery()
->getOneOrNullResult();
return $sql;
}
public function findPageParentByCategoryId($categoryId)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->where('p.ids_categoies_related LIKE :categoryId')
->setParameter('categoryId', '%'.$categoryId.'%')
->getQuery()
->getOneOrNullResult();
return $sql;
}
public function findPostNotValidImage()
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->andWhere('t.actif = true')
->join('p.translations','t')
->andWhere('p.image IS NOT NULL')
->andWhere('p.image_import_valide is null');
//->setMaxResults('10');
return $sql->getQuery()->getResult();
}
public function findPostArchive()
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->andWhere('t.actif = true')
->andWhere('p.archive = true')
->join('p.translations','t')
->orderBy('p.id','ASC');
return $sql->getQuery()->getResult();
}
/******************* post aleatoire ***************************/
public function findPostAleatoire($type,$nb = 1,$id)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->andWhere('t.actif = true')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('type', $type)
->andWhere('p.id != :id')
->setParameter('id', $id)
// ->andWhere('p.date_publication IS NULL OR p.date_publication <= :currentDate')
// ->setParameter('currentDate', new \DateTime('now'))
->orderBy('RAND()')
->setMaxResults($nb);
return $sql->getQuery()->getResult();
}
public function findPostAssocier($type,$id = null)
{
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.type_post','typePost')
->andWhere('typePost.id = :type')
->andWhere('t.actif = true')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('type', $type);
if($id != null){
$sql->andWhere('p.id != :id_post')
->setParameter('id_post', $id);
}
return $sql->getQuery()->getResult();
}
public function findPostExpressionBySpecifiqueCategory($id_categorie)
{
$req_order = "p.position";
$asc_desc = "ASC";
$locale = Locale::getDefault();
$sql = $this->createQueryBuilder('p')
->join('p.translations','t')
->join('p.PostCategory','post_categorie')
->andWhere('t.actif = true')
->andWhere('post_categorie.Category =:categorie_id')
->andWhere('t.locale = :locale')
->setParameter('locale', $locale)
->setParameter('categorie_id', $id_categorie)
->orderBy($req_order, $asc_desc);
return $sql->getQuery()->getResult();
}
}