-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotService.php
More file actions
52 lines (45 loc) · 1.3 KB
/
PlotService.php
File metadata and controls
52 lines (45 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace San\ReportBundle;
use Doctrine\Common\Persistence\ObjectManager;
use San\ReportBundle\Model\Plot;
use San\ReportBundle\Repository\ReportRepository;
class PlotService
{
/**
* @var \Doctrine\Common\Persistence\ObjectManager
*/
protected $dm;
/**
* @var string
*/
protected $namespace;
/**
* @param ObjectManager $dm
* @param string $namespace
*/
public function __construct(ObjectManager $dm, $namespace)
{
$this->dm = $dm;
$this->namespace = $namespace;
}
/**
* @param Plot $plotModel
*/
public function getData(Plot $plotModel)
{
$plotData = array();
foreach ($plotModel->getReports() as $report) {
$data = array();
$counts = $this->dm->getRepository($this->namespace)->countByReportDate($report, $plotModel->getFrom(), $plotModel->getTo());
foreach ($counts['result'] as $count) {
$date = sprintf('%s/%s/%s', $count['_id']['month'], $count['_id']['day'], $count['_id']['year']);
$data[] = array($date, $count['total']);
}
$plotData[] = array(
'report' => $report->getType(),
'data' => $data,
);
}
return $plotData;
}
}