<?php
namespace App\Repository;
use App\Entity\Discussion;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Discussion>
*
* @method Discussion|null find($id, $lockMode = null, $lockVersion = null)
* @method Discussion|null findOneBy(array $criteria, array $orderBy = null)
* @method Discussion[] findAll()
* @method Discussion[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class DiscussionRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Discussion::class);
}
public function save(Discussion $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Discussion $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function findBySites($siteId, $limit = null, $page = null, $type)
{
$qb = $this->createQueryBuilder('d')
->andWhere('d.site = :site')
->andWhere('d.type = :type')
->setParameter('site', $siteId)
->setParameter('type', $type);
if ($limit) {
$qb->setMaxResults($limit);
}
if ($page) {
$qb->setFirstResult($limit * $page);
}
return $qb->orderBy('d.updatedAt', 'DESC')
->getQuery()
->getResult();
}
// /**
// * @return Discussion[] Returns an array of Discussion objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('d')
// ->andWhere('d.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('d.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Discussion
// {
// return $this->createQueryBuilder('d')
// ->andWhere('d.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}