<?php
namespace App\Repository\Salons;
use App\Entity\Salons\Salons;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\NonUniqueResultException;
/**
* @method Salons|null find($id, $lockMode = null, $lockVersion = null)
* @method Salons|null findOneBy(array $criteria, array $orderBy = null)
* @method Salons[] findAll()
* @method Salons[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SalonsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Salons::class);
}
/**
* @param Salons $salons
* @param $limit
* @return int|mixed|string
*/
public function getSalonRandom(Salons $salons, $limit)
{
return $this->createQueryBuilder('s')
->andWhere('s.id != :salon')
->setParameter('salon', $salons)
->orderBy('RAND()')
->setMaxResults($limit)
->getQuery()
->getResult()
;
}
/**
* @return int|mixed|string|null
* @throws NonUniqueResultException
*/
public function featured()
{
return $this->createQueryBuilder('s')
->andWhere('s.online = 1')
->andWhere('s.featured = 1')
->orderBy('s.updatedAt', 'DESC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;
}
}