|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
|
6
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
7
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
8
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent; |
|
9
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\User; |
|
10
|
|
|
|
|
11
|
|
|
class SubscriptionEventRepository extends EntityRepository |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @return integer |
|
15
|
|
|
*/ |
|
16
|
4 |
|
public function getLastDayEventsCount() |
|
17
|
|
|
{ |
|
18
|
4 |
|
$qb = $this->createQueryBuilder('se'); |
|
19
|
|
|
|
|
20
|
4 |
|
$now = new \DateTime(); |
|
21
|
|
|
|
|
22
|
|
|
return $qb |
|
23
|
4 |
|
->select('COUNT(se)') |
|
24
|
4 |
|
->where('se.date > :time') |
|
25
|
4 |
|
->setParameter('time', $now->sub(new \DateInterval('PT24H'))) |
|
26
|
4 |
|
->getQuery()->getSingleScalarResult() |
|
27
|
|
|
; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Creates QueryBuilder object for pagination of user subscribers events |
|
32
|
|
|
* |
|
33
|
|
|
* @param User $user |
|
34
|
|
|
* |
|
35
|
|
|
* @return QueryBuilder |
|
36
|
|
|
*/ |
|
37
|
3 |
|
public function createUserLastSubscribersEventsQuery(User $user) |
|
38
|
|
|
{ |
|
39
|
3 |
|
$qb = $this->createQueryBuilder('se'); |
|
40
|
|
|
|
|
41
|
|
|
return $qb |
|
42
|
3 |
|
->select(['se', 's']) |
|
43
|
3 |
|
->join('se.subscriber', 's') |
|
44
|
3 |
|
->where('se.author = :author') |
|
45
|
3 |
|
->orderBy('se.date', 'desc') |
|
46
|
3 |
|
->setParameter('author', $user->getId()) |
|
47
|
|
|
; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get last global subscriptions QueryBuilder for pagination |
|
52
|
|
|
* |
|
53
|
|
|
* @return QueryBuilder |
|
54
|
|
|
*/ |
|
55
|
2 |
|
public function createLastSubscriptionEventsQuery() |
|
56
|
|
|
{ |
|
57
|
2 |
|
$qb = $this->createQueryBuilder('se'); |
|
58
|
|
|
|
|
59
|
|
|
return $qb |
|
60
|
2 |
|
->select(['se', 'a', 's']) |
|
61
|
2 |
|
->innerJoin('se.author', 'a') |
|
62
|
2 |
|
->innerJoin('se.subscriber', 's') |
|
63
|
2 |
|
->orderBy('se.date', 'desc') |
|
64
|
|
|
; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get last global subscription events |
|
69
|
|
|
* |
|
70
|
|
|
* @param int $limit |
|
71
|
|
|
* |
|
72
|
|
|
* @return SubscriptionEvent[] |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getLastSubscriptionEvents($limit = 20) |
|
75
|
|
|
{ |
|
76
|
|
|
$qb = $this->createLastSubscriptionEventsQuery(); |
|
77
|
|
|
$qb->setMaxResults($limit); |
|
78
|
|
|
|
|
79
|
|
|
return $qb->getQuery()->getResult(); |
|
80
|
|
|
} |
|
81
|
|
|
} |