|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\StatsBundle\Handler; |
|
12
|
|
|
|
|
13
|
|
|
use LoginCidadao\StatsBundle\Entity\Statistics; |
|
14
|
|
|
use LoginCidadao\StatsBundle\Entity\StatisticsRepository; |
|
15
|
|
|
|
|
16
|
|
|
class StatsHandler |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var StatisticsRepository */ |
|
19
|
|
|
private $repo; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* StatsHandler constructor. |
|
23
|
|
|
* @param StatisticsRepository $repo |
|
24
|
|
|
*/ |
|
25
|
5 |
|
public function __construct(StatisticsRepository $repo) |
|
26
|
|
|
{ |
|
27
|
5 |
|
$this->repo = $repo; |
|
28
|
5 |
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
public function get($index, $key = null, \DateTime $afterDate = null) |
|
31
|
|
|
{ |
|
32
|
1 |
|
return $this->repo->findStatsByIndexKeyDate($index, $key, $afterDate); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function getIndexed($index, $key = null, $days = null) |
|
36
|
|
|
{ |
|
37
|
1 |
|
return $this->repo->findIndexedStatsByIndexKeyDays($index, $key, $days); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function getIndexedUniqueDate($index, $keys = null, \DateTime $afterDate = null) |
|
41
|
|
|
{ |
|
42
|
1 |
|
return $this->repo->findIndexedUniqueStatsByIndexKeyDate($index, $keys, $afterDate); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function getIndexedUniqueLastDays($index, $keys = null, $days = null) |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $this->repo->findIndexedUniqueStatsByIndexKeyDays($index, $keys, $days); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param \DateTime $date |
|
52
|
|
|
* @param $index |
|
53
|
|
|
* @param $key |
|
54
|
|
|
* @return null|Statistics |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function getOneByDate(\DateTime $date, $index, $key) |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var Statistics|null $stat */ |
|
59
|
1 |
|
$stat = $this->repo->findOneBy([ |
|
60
|
1 |
|
'timestamp' => $date, |
|
61
|
1 |
|
'index' => $index, |
|
62
|
1 |
|
'key' => $key, |
|
63
|
|
|
]); |
|
64
|
|
|
|
|
65
|
1 |
|
return $stat; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|