<?php
namespace Products\NotificationsBundle\Doctrine\Repository\Notifications;
use App\Util\Pagination;
use App\Util\Querying;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Products\NotificationsBundle\Doctrine\Repository\AbstractNotificationRepository;
use Products\NotificationsBundle\Entity\AbstractNotification;
use Products\NotificationsBundle\Entity\Automation;
use Products\NotificationsBundle\Entity\Notifications\Invocation;
use Products\NotificationsBundle\Entity\Notifications\Message;
/**
* Class MessageRepository
* @package Products\NotificationsBundle\Doctrine\RepositoryNotifications
*
* @method Message find($id, $lockMode = null, $lockVersion = null)
* @method Message findOneBy(array $criteria, array $orderBy = null)
* @method array|Message[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @method array|Message[] findAll()
* @method iterable|Paginator|array|Message[] findBySearch(array $search, ?int $limit = null, ?int $offset = null)
*/
class MessageRepository extends AbstractNotificationRepository
{
/**
* @param int $limit
* @return array<Message>
*/
public function findByRecentlySent(int $limit = Pagination::PAGE_LIMIT): array
{
return $this->createQueryBuilder('message')
->andWhere('message.status != :status')
->setParameter('status', AbstractNotification::STATUSES__DRAFT)
->addOrderBy('message.touchedAt', 'DESC')
->setMaxResults(max(1, $limit))
->getQuery()
->getResult();
}
}