_em->persist(entity: $entity); if ($flush) { $this->_em->flush(); } } public function remove(Quotes $entity, bool $flush = true): void { $this->_em->remove(entity: $entity); if ($flush) { $this->_em->flush(); } } public function findOneRandom(): ?Quotes { try { $idLimits = $this->createQueryBuilder(alias: 'q') ->select('MIN(q.id)', 'MAX(q.id)') ->getQuery() ->getOneOrNullResult(); } catch (NonUniqueResultException) { $idLimits = 0; } try { $randomPossibleId = random_int(min: $idLimits[1], max: $idLimits[2]); } catch(Exception) { $randomPossibleId = 0; // return first, if any } try { return $this->createQueryBuilder(alias: 'q') ->where(predicates: 'q.id >= :random_id') ->setParameter(key: 'random_id', value: $randomPossibleId) ->setMaxResults(maxResults: 1) ->getQuery() ->getOneOrNullResult(); } catch (NonUniqueResultException) { // max results is 1 return null; } } // /** // * @return Quotes[] Returns an array of Quotes objects // */ /* public function findByExampleField($value) { return $this->createQueryBuilder('q') ->andWhere('q.exampleField = :val') ->setParameter('val', $value) ->orderBy('q.id', 'ASC') ->setMaxResults(10) ->getQuery() ->getResult() ; } */ /* public function findOneBySomeField($value): ?Quotes { return $this->createQueryBuilder('q') ->andWhere('q.exampleField = :val') ->setParameter('val', $value) ->getQuery() ->getOneOrNullResult() ; } */ }