1
|
|
|
<?php |
2
|
|
|
namespace Kunstmaan\DashboardBundle\Command\Helper\Analytics; |
3
|
|
|
|
4
|
|
|
use Doctrine\ORM\EntityManager; |
5
|
|
|
use Kunstmaan\DashboardBundle\Entity\AnalyticsOverview; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
|
8
|
|
|
abstract class AbstractAnalyticsCommandHelper |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** @var ConfigHelper $configHelper */ |
12
|
|
|
protected $configHelper; |
13
|
|
|
/** @var GooglequeryHelper $queryHelper */ |
14
|
|
|
protected $query; |
15
|
|
|
/** @var EntityManager $em */ |
16
|
|
|
protected $em; |
17
|
|
|
/** @var OutputInterface $output */ |
18
|
|
|
protected $output; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor |
22
|
|
|
* |
23
|
|
|
* @param $configHelper |
24
|
|
|
* @param $queryHelper |
25
|
|
|
* @param $output |
26
|
|
|
* @param $em |
27
|
|
|
*/ |
28
|
|
|
public function __construct($configHelper, $queryHelper, $output, $em) |
29
|
|
|
{ |
30
|
|
|
$this->configHelper = $configHelper; |
31
|
|
|
$this->query = $queryHelper; |
32
|
|
|
$this->output = $output; |
33
|
|
|
$this->em = $em; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
* |
39
|
|
|
* @param AnalyticsOverview $overview |
40
|
|
|
* |
41
|
|
|
* @return array |
|
|
|
|
42
|
|
|
*/ |
43
|
|
|
protected function getTimestamps(AnalyticsOverview &$overview) { |
44
|
|
|
// if yearoverview set the begin time to the first day of this year |
45
|
|
|
$profileStartDate = explode('T', $this->configHelper->getActiveProfile()['created'])[0]; |
46
|
|
|
if ($overview->getUseYear()) { |
47
|
|
|
$begin_date = date('Y-m-d', mktime(0, 0, 0, 1, 1, date('Y'))); |
48
|
|
|
$begin = strtotime($profileStartDate) > strtotime($begin_date) ? date('Y-m-d', strtotime($profileStartDate)) : $begin_date; |
49
|
|
|
} else { |
50
|
|
|
// check if timespan is't more than existence of the profile; if so, use the creation time in stead of the timespan time |
51
|
|
|
$begin = strtotime($profileStartDate) > strtotime('-' . $overview->getTimespan() . ' days') ? date('Y-m-d', strtotime($profileStartDate)) : date('Y-m-d', strtotime('-' . $overview->getTimespan() . ' days')); |
52
|
|
|
} |
53
|
|
|
// set the end time |
54
|
|
|
$end = date('Y-m-d', strtotime('-' . $overview->getStartOffset() . ' days')); |
55
|
|
|
|
56
|
|
|
return array('begin' => $begin, 'end' => $end); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* get the extra data for an overview, can be overridden |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
|
|
protected function getExtra(AnalyticsOverview $overview) { |
65
|
|
|
$extra = array(); |
66
|
|
|
|
67
|
|
|
// add segment |
68
|
|
|
if ($overview->getSegment()) { |
69
|
|
|
$extra['segment'] = $overview->getSegment()->getQuery(); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $extra; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Executes the query |
77
|
|
|
* |
78
|
|
|
* @return array the resultset |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
protected function executeQuery(AnalyticsOverview $overview, $metrics) { |
|
|
|
|
81
|
|
|
$timestamps = $this->getTimestamps($overview); |
82
|
|
|
$extra = $this->getExtra($overview); |
83
|
|
|
|
84
|
|
|
// execute query |
85
|
|
|
$results = $this->query->getResultsByDate( |
86
|
|
|
$timestamps['begin'], |
87
|
|
|
$timestamps['end'], |
88
|
|
|
$metrics, |
89
|
|
|
$extra |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
return $results->getRows(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public abstract function getData(&$overview); |
|
|
|
|
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.