2015-06-23 09:38:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Entity;
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
|
|
|
|
class SubscriptionEventRepository extends EntityRepository
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return integer
|
|
|
|
*/
|
|
|
|
public function getLastDayEventsCount()
|
|
|
|
{
|
|
|
|
$qb = $this->createQueryBuilder('se');
|
|
|
|
|
|
|
|
$now = new \DateTime();
|
|
|
|
|
2015-06-23 09:42:59 +00:00
|
|
|
return $qb
|
2015-06-23 09:38:43 +00:00
|
|
|
->select('COUNT(se)')
|
|
|
|
->where('se.date > :time')
|
|
|
|
->setParameter('time', $now->sub(new \DateInterval('PT24H')))
|
|
|
|
->getQuery()->getSingleScalarResult()
|
|
|
|
;
|
|
|
|
}
|
2015-06-23 10:34:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param integer $limit
|
|
|
|
* @return SubscriptionEvent[]
|
|
|
|
*/
|
|
|
|
public function getUserLastSubscriptionEventsById(User $user, $limit)
|
|
|
|
{
|
|
|
|
if (!is_int($limit)) {
|
|
|
|
throw new \InvalidArgumentException('$limit must be an integer');
|
|
|
|
}
|
|
|
|
|
|
|
|
$qb = $this->createQueryBuilder('se');
|
|
|
|
|
|
|
|
return $qb
|
|
|
|
->select()
|
|
|
|
->where('se.author = :author')
|
|
|
|
->orderBy('se.date', 'desc')
|
|
|
|
->setMaxResults($limit)
|
|
|
|
->setParameter('author', $user)
|
|
|
|
->getQuery()->getResult()
|
|
|
|
;
|
|
|
|
}
|
2015-06-23 09:38:43 +00:00
|
|
|
}
|