Skip to content

Instantly share code, notes, and snippets.

@ger86
Last active February 14, 2019 16:21
Show Gist options
  • Save ger86/11c24d200eb6abe2b82144467704c5b6 to your computer and use it in GitHub Desktop.
Save ger86/11c24d200eb6abe2b82144467704c5b6 to your computer and use it in GitHub Desktop.
<?php
namespace App\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
use App\Repository\EntityStatsRepositoryInterface;
class EntityStatsRepositoryDecorator extends ServiceEntityRepository {
public function __construct(
RegistryInterface $registry,
ServiceEntityRepository $repository
) {
parent::__construct($registry, $repository->getClassName());
}
public function findTodayStats(): int {
$today = new \DateTime();
return $this->createQueryBuilder('o')
->select('COUNT(o) as total')
->andWhere('o.createdAt = :today')
->setParameter('today', $today)
->getQuery()
->getSingleScalarResult();
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment