<?php
namespace App\Repository;
use App\Entity\Battle;
use App\Entity\Client;
use App\Entity\Rapper;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Battle>
*
* @method Battle|null find($id, $lockMode = null, $lockVersion = null)
* @method Battle|null findOneBy(array $criteria, array $orderBy = null)
* @method Battle[] findAll()
* @method Battle[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BattleRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Battle::class);
}
/**
* @return Battle[] Returns an array of Battle objects
*/
public function findAllForHomepage(): array
{
return $this->createQueryBuilder('b')
->andWhere('b.isConfirmed = :confirmed')
->setParameter('confirmed', true)
->orderBy('b.createdAt', 'ASC')
->setMaxResults(9)
->getQuery()
->getResult()
;
}
/**
* @return Battle[] Returns an array of Battle objects
*/
public function findLatestForRapper(Rapper $rapper,int $limit): array
{
$res = $this->createQueryBuilder('b')
->andWhere('b.isConfirmed = 1 OR b.isCompleted = 1 OR b.isCanceled = 1')
->andWhere('b.challenger = :rapper OR b.oponnent = :rapper')
->setParameter('rapper', $rapper)
->orderBy('b.createdAt', 'ASC')
;
if($limit>0){
$res->setMaxResults($limit);
}
return $res->getQuery()
->getResult()
;
}
/**
* @return Battle[] Returns an array of Battle objects
*/
public function findOpenedForRapper(Rapper $rapper,int $limit): array
{
$res = $this->createQueryBuilder('b')
->andWhere('b.isConfirmed = :confirmed')
->setParameter('confirmed', false)
->andWhere('b.isCompleted = :completed')
->setParameter('completed', false)
->andWhere('b.isCanceled = :canceled')
->setParameter('canceled', false)
->andWhere('b.challenger = :rapper OR b.oponnent = :rapper')
->setParameter('rapper', $rapper)
->orderBy('b.createdAt', 'ASC')
;
if($limit>0){
$res->setMaxResults($limit);
}
return $res->getQuery()
->getResult()
;
}
public function save(Battle $entity, bool $flush = false): Battle
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
return $entity;
}
public function remove(Battle $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Battle[] Returns an array of Battle objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('b.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Battle
// {
// return $this->createQueryBuilder('b')
// ->andWhere('b.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}