Completed
Push — master ( aed5b3...caff4d )
by Michal
05:21
created

ReportsHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
5
namespace app\View\Helper;
6
7
use App\Utility\Sanitize;
8
use App\View\Helper\AppHelper;
9
use Cake\Utility\Inflector;
10
use Cake\View\View;
11
12
class ReportsHelper extends AppHelper
13
{
14
    public $helpers = array('Incidents');
15
16 6
    public function __construct(View $view, $settings = array())
17
    {
18 6
        parent::__construct($view, $settings);
19 6
    }
20
21 1
    public function entriesFromIncidents($entries, $totalCount, $key)
22
    {
23
        //$entries = Sanitize::clean($entries);
24 1
        $values = array();
25 1
        foreach ($entries as $entry) {
26 1
            $values[] = "$entry[$key] <span class='count'>("
27 1
                . $entry['count'] . ')</span>';
28
        }
29 1
        $fullString = implode(', ', $values);
30 1
        $remaining = $totalCount - count($values);
31 1
        if ($remaining) {
32
            $fullString .= " <small>and $remaining others</small>";
33
        }
34
35 1
        return $fullString;
36
    }
37
38 1
    public function createReportsLinks($reports)
39
    {
40 1
        $links = array();
41 1
        foreach ($reports as $report) {
42 1
            $links[] = $this->linkToReport($report);
43
        }
44 1
        $string = implode(', ', $links);
45
46 1
        return $string;
47
    }
48
49 3
    public function linkToReport($report)
50
    {
51 3
        $reportId = $report['id'];
52 3
        $link = '<a href=/' . BASE_DIR . "reports/view/$reportId>#$reportId</a>";
53
54 3
        return $link;
55
    }
56
57 1
    public function linkToReportFromIncident($incident)
58
    {
59 1
        $reportId = $incident['report_id'];
60 1
        $link = '<a href=/' . BASE_DIR . "reports/view/$reportId>#$reportId</a>";
61
62 1
        return $link;
63
    }
64
65 1
    public function getStacktracesForIncidents($incidents)
66
    {
67 1
        $count = 0;
68 1
        $html = '<div class="row">';
69 1
        foreach ($incidents as $incident) {
70 1
            $class = 'well span5';
71
72 1
            if ($count % 2 == 1) {
73
                $class .= ' ';
74
            } else {
75 1
                $html .= "</div><div class='row'>";
76
            }
77
78 1
            $html .= $this->Incidents->getStacktrace($incident, $class);
79 1
            ++$count;
80
        }
81 1
        $html .= '</div>';
82
83 1
        return $html;
84
    }
85
86 1
    public function getChartArray($arrayName, $columns, $relatedEntries)
87
    {
88 1
        $html = "var $arrayName = [], chart = {};";
89 1
        foreach ($columns as $column) {
90 1
            $column = htmlspecialchars($column, ENT_QUOTES | ENT_HTML5);
91 1
            $html .= 'chart = {};';
92 1
            $html .= "chart.name = '$column';";
93 1
            $html .= "chart.title = '" . Inflector::humanize($column) . "';";
94 1
            $html .= 'chart.labels = []; chart.values = [];';
95 1
            foreach ($relatedEntries[$column] as $entry) {
96 1
                $count = $entry['count'];
97 1
                $html .= "chart.labels.push('$entry[$column] ($count)');";
98 1
                $html .= "chart.values.push($count);";
99
            }
100 1
            $html .= "$arrayName.push(chart);";
101
        }
102
103 1
        return $html;
104
    }
105
106
    public function getLineChartData($arrayName, $entries)
107
    {
108
        $html = "var $arrayName = [];";
109
        foreach ($entries as $entry) {
110
            $html .= "$arrayName.push(['" . $entry['date'] . "', "
111
                    . $entry['count'] . ']);';
112
        }
113
114
        return $html;
115
    }
116
}
117