40 lines
917 B
PHP
40 lines
917 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Signal;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Signal>
|
|
*/
|
|
class SignalRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Signal::class);
|
|
}
|
|
|
|
/**
|
|
* @return list<Signal>
|
|
*/
|
|
public function findRecent(int $limit): array
|
|
{
|
|
return $this->createQueryBuilder('signal')
|
|
->orderBy('signal.createdAt', 'DESC')
|
|
->setMaxResults($limit)
|
|
->getQuery()
|
|
->getResult();
|
|
}
|
|
|
|
public function save(Signal $signal): void
|
|
{
|
|
$entityManager = $this->getEntityManager();
|
|
$entityManager->persist($signal);
|
|
$entityManager->flush();
|
|
}
|
|
}
|