src/Repository/DiscussionRepository.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Discussion;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @extends ServiceEntityRepository<Discussion>
  8.  *
  9.  * @method Discussion|null find($id, $lockMode = null, $lockVersion = null)
  10.  * @method Discussion|null findOneBy(array $criteria, array $orderBy = null)
  11.  * @method Discussion[]    findAll()
  12.  * @method Discussion[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. class DiscussionRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryDiscussion::class);
  19.     }
  20.     public function save(Discussion $entitybool $flush false): void
  21.     {
  22.         $this->getEntityManager()->persist($entity);
  23.         if ($flush) {
  24.             $this->getEntityManager()->flush();
  25.         }
  26.     }
  27.     public function remove(Discussion $entitybool $flush false): void
  28.     {
  29.         $this->getEntityManager()->remove($entity);
  30.         if ($flush) {
  31.             $this->getEntityManager()->flush();
  32.         }
  33.     }
  34.     public function findBySites($siteId$limit null$page null$type)
  35.     {
  36.         $qb $this->createQueryBuilder('d')
  37.             ->andWhere('d.site = :site')
  38.             ->andWhere('d.type = :type')
  39.             ->setParameter('site'$siteId)
  40.             ->setParameter('type'$type);
  41.         if ($limit) {
  42.             $qb->setMaxResults($limit);
  43.         }
  44.         if ($page) {
  45.             $qb->setFirstResult($limit $page);
  46.         }
  47.         return $qb->orderBy('d.updatedAt''DESC')
  48.             ->getQuery()
  49.             ->getResult();
  50.     }
  51. //    /**
  52. //     * @return Discussion[] Returns an array of Discussion objects
  53. //     */
  54. //    public function findByExampleField($value): array
  55. //    {
  56. //        return $this->createQueryBuilder('d')
  57. //            ->andWhere('d.exampleField = :val')
  58. //            ->setParameter('val', $value)
  59. //            ->orderBy('d.id', 'ASC')
  60. //            ->setMaxResults(10)
  61. //            ->getQuery()
  62. //            ->getResult()
  63. //        ;
  64. //    }
  65. //    public function findOneBySomeField($value): ?Discussion
  66. //    {
  67. //        return $this->createQueryBuilder('d')
  68. //            ->andWhere('d.exampleField = :val')
  69. //            ->setParameter('val', $value)
  70. //            ->getQuery()
  71. //            ->getOneOrNullResult()
  72. //        ;
  73. //    }
  74. }