<?php
namespace App\Repository;
use App\Entity\Company;
use App\Entity\Product;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Company|null find($id, $lockMode = null, $lockVersion = null)
* @method Company|null findOneBy(array $criteria, array $orderBy = null)
* @method Company[] findAll()
* @method Company[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CompanyRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Company::class);
}
public function searchCompany(array $parameters)
{
$qb = $this->createQueryBuilder('c')
->leftJoin('c.products', 'products')
->addSelect('products')
->leftJoin('products.avis', 'avis')
->addSelect('avis')
->leftJoin('products.subCategories', 'subCategories')
->leftJoin('products.departments', 'departments')
->where('c.isConfirmed = 1')
->andWhere('c.isValidDocument = 1')
->orderBy('avis.globalNote', 'DESC');
if ($parameters['department']) {
$qb
->andWhere('departments.id = :department')
->setParameter('department', $parameters['department']);
}
if ($parameters['category']) {
$qb
->andWhere('subCategories.id = :subCategories')
->setParameter('subCategories', $parameters['category']);
}
return $qb->getQuery()->getResult();
}
public function getCompanies()
{
return $this->createQueryBuilder('c')
->leftJoin('c.products', 'products')
->addSelect('products')
->leftJoin('products.photos', 'photos')
->addSelect('photos')
->orderBy('c.id', 'DESC')
->getQuery()
->getResult();
}
public function getCompaniesprodActif()
{
return $this->createQueryBuilder('c')
->where('c.isConfirmed = 1')
->andWhere('c.isValidDocument = 1')
->leftJoin('c.products', 'products')
->addSelect('products')
->leftJoin('products.avis', 'avis')
->addSelect('avis')
->andWhere('products.isActivated = 1')
->orderBy('avis.globalNote', 'DESC')
->getQuery()
->getResult();
}
public function getSubscribedCompanies()
{
return $this->createQueryBuilder('c')
->join('c.abonnements', 'ca')
->andWhere('ca.isActive = true')
->orWhere('ca.isActive = false')
->orderBy('c.id', 'DESC')
->getQuery()
->getResult();
}
/**
* Undocumented function
*
* @return CompanyAbone89[]
*/
public function findAllVerifPretAbonne($id):array
{
return $this->createQueryBuilder('c')
->select('c')
->where('c.id = :id')
->setParameter('id', $id)
->leftJoin('c.abonnement','abonnement')
->addSelect('abonnement')
->leftJoin('abonnement.typeAbonnement','typeAbonnement')
->addSelect('typeAbonnement')
->andWhere('abonnement.isActive = true')
->andWhere('typeAbonnement.prix = 89')
->getQuery()
->getResult()
;
}
/**
* Undocumented function
*
* @return CompanyAbone[]
*/
public function VerifPretAbonne($id):array
{
return $this->createQueryBuilder('c')
->select('c')
->where('c.id = :id')
->setParameter('id', $id)
->leftJoin('c.abonnement','abonnement')
->addSelect('abonnement')
->andWhere('abonnement.isActive = true')
->getQuery()
->getResult()
;
}
public function findCompanyConect()
{
return $this->createQueryBuilder('c')
->Where('c.statuCon = :true')
->setParameter('true', 1)
->andWhere('c.etatNetwork IS NOT NULL')
->orderBy('c.id', 'ASC')
->getQuery()
->getResult();
}
public function findCompanyType($value){
return $this->createQueryBuilder('c')
->select('c.type')
->where('c.id= :val')
->setParameter('val',$value)
->getQuery()
->getResult();
}
public function findAllExceptCurrentUserpresta($currentUserId)
{
return $this->createQueryBuilder('c')
->andWhere('c.id != :currentUserId')
->setParameter('currentUserId', $currentUserId)
->getQuery()
->getResult();
}
public function findCompanyByKeyword($keyword)
{
return $this->createQueryBuilder('c')
->where("CONCAT(' ', c.companyName, ' ') LIKE :keyword ")
->setParameter('keyword', '%' . $keyword . '%')
->orWhere('c.companyName LIKE :keyword1')
->setParameter('keyword1', '%' . $keyword . '%')
->setMaxResults(10)
->getQuery()
->getResult();
}
public function findIsDirectReservation($id)
{
return $this->createQueryBuilder('c')
->select('c.isDirectReservationMode')
->where('c.id= :val')
->setParameter('val', $id)
->getQuery()
->getSingleResult();
}
// public function CompanyPros(Product $product):array
// {
// return $this->createQueryBuilder('c')
// ->where('c.products = :products')
// ->setParameter('products', $product)
// ->leftJoin('c.products','products')
// ->addSelect('products')
// ->orderBy('c.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// /**
// * @return Company[] Returns an array of Company objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->orderBy('c.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Company
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}