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