<?php
namespace App\Repository\Distinctions;
use App\Entity\Distinctions\Distinctions;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Distinctions|null find($id, $lockMode = null, $lockVersion = null)
* @method Distinctions|null findOneBy(array $criteria, array $orderBy = null)
* @method Distinctions[] findAll()
* @method Distinctions[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class DistinctionsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Distinctions::class);
}
public function getDistinctionsRandom(Distinctions $distinction, $limit)
{
return $this->createQueryBuilder('d')
->andWhere('d.id != :distinction')
->setParameter('distinction', $distinction)
->orderBy('RAND()')
->setMaxResults($limit)
->getQuery()
->getResult()
;
}
public function findSingleDistinction(int $id): ?Distinctions
{
return $this->createQueryBuilder('d')
->andWhere('d.id = :id')
->andWhere('d.online = 1')
->setParameter('id', $id)
->getQuery()
->getOneOrNullResult()
;
}
// /**
// * @return Distinctions[] Returns an array of Distinctions objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('d')
->andWhere('d.exampleField = :val')
->setParameter('val', $value)
->orderBy('d.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Distinctions
{
return $this->createQueryBuilder('d')
->andWhere('d.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}