34 lines
857 B
PHP
34 lines
857 B
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\News;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<News>
|
|
*/
|
|
class NewsRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, News::class);
|
|
}
|
|
|
|
public function getLatestForDashboard(): ?News
|
|
{
|
|
$qb = $this->createQueryBuilder('news');
|
|
|
|
return $qb
|
|
->where($qb->expr()->neq('news.status', ':status'))
|
|
->orderBy('news.status', 'DESC')
|
|
->addOrderBy('news.createdAt', 'DESC')
|
|
->setParameter('status', News::STATUS_DEACTIVATED)
|
|
->setMaxResults(1)
|
|
->getQuery()
|
|
->getOneOrNullResult()
|
|
;
|
|
}
|
|
}
|