<?php
namespace App\Repository;
use App\Entity\ForumReponse;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<ForumReponse>
*
* @method ForumReponse|null find($id, $lockMode = null, $lockVersion = null)
* @method ForumReponse|null findOneBy(array $criteria, array $orderBy = null)
* @method ForumReponse[] findAll()
* @method ForumReponse[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ForumReponseRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ForumReponse::class);
}
public function add(ForumReponse $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(ForumReponse $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return ForumReponse[] Returns an array of ForumReponse objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('f.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?ForumReponse
// {
// return $this->createQueryBuilder('f')
// ->andWhere('f.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
/**
* @return ForumReponse[] Returns an array of ForumReponse objects
*/
public function finResponsesdWithUser($sujetForum, $user = null, $ofsset ): array
{
return $this->createQueryBuilder('f')
->where('f.etat = :val1')
->andWhere('f.sujetforum = :val2')
->andWhere('f.parent is NULL')
->orWhere('f.user = :val3')
->andWhere('f.sujetforum = :val2')
->andWhere('f.parent is NULL')
->setParameter('val1', true)
->setParameter('val2', $sujetForum)
->setParameter('val3', $user)
->orderBy('f.id', 'DESC')
->setFirstResult($ofsset)
->setMaxResults(1) // Set maximum results to 3
->getQuery()
->getResult()
;
}
public function findTopLevelResponses()
{
return $this->createQueryBuilder('r')
->where('r.parent IS NULL')
->getQuery()
->getResult();
}
}