src/Repository/Salons/SalonsRepository.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Salons;
  3. use App\Entity\Salons\Salons;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Doctrine\ORM\NonUniqueResultException;
  7. /**
  8.  * @method Salons|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method Salons|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method Salons[]    findAll()
  11.  * @method Salons[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class SalonsRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registrySalons::class);
  18.     }
  19.     /**
  20.      * @param Salons $salons
  21.      * @param $limit
  22.      * @return int|mixed|string
  23.      */
  24.     public function getSalonRandom(Salons $salons$limit)
  25.     {
  26.         return $this->createQueryBuilder('s')
  27.             ->andWhere('s.id != :salon')
  28.             ->setParameter('salon'$salons)
  29.             ->orderBy('RAND()')
  30.             ->setMaxResults($limit)
  31.             ->getQuery()
  32.             ->getResult()
  33.             ;
  34.     }
  35.     /**
  36.      * @return int|mixed|string|null
  37.      * @throws NonUniqueResultException
  38.      */
  39.     public function featured()
  40.     {
  41.         return $this->createQueryBuilder('s')
  42.             ->andWhere('s.online = 1')
  43.             ->andWhere('s.featured = 1')
  44.             ->orderBy('s.updatedAt''DESC')
  45.             ->setMaxResults(1)
  46.             ->getQuery()
  47.             ->getOneOrNullResult()
  48.             ;
  49.     }
  50. }