OnlineRepository.php
1 <?php 2 3 namespace App\Repository; 4 5 use App\Entity\Online; 6 use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; 7 use Doctrine\Persistence\ManagerRegistry; 8 9 /** 10 * @extends ServiceEntityRepository<Online> 11 * 12 * @method Online|null find($id, $lockMode = null, $lockVersion = null) 13 * @method Online|null findOneBy(array $criteria, array $orderBy = null) 14 * @method Online[] findAll() 15 * @method Online[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) 16 */ 17 class OnlineRepository extends ServiceEntityRepository 18 { 19 public function __construct(ManagerRegistry $registry) 20 { 21 parent::__construct($registry, Online::class); 22 } 23 24 public function getTotalByCrc32server( 25 int $crc32server 26 ): int 27 { 28 return 29 $this->createQueryBuilder('o') 30 ->select('count(o.id)') 31 ->where('o.crc32server = :crc32server') 32 ->setParameter('crc32server', $crc32server) 33 ->getQuery() 34 ->getSingleScalarResult(); 35 } 36 37 public function getMaxPlayersByTimeInterval( 38 int $from, 39 int $to 40 ): int 41 { 42 return (int) 43 $this->createQueryBuilder('o') 44 ->select('max(o.players)') 45 ->where('o.time >= :from AND o.time <= :to') 46 ->setParameter('from', $from) 47 ->setParameter('to', $to) 48 ->getQuery() 49 ->getSingleScalarResult(); 50 } 51 }