Completed
Push — master ( 740d41...a3b506 )
by Michal
07:10 queued 16s
created

ReportsHelper::entriesFromIncidents()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 9
cp 0.8889
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 3
crap 3.0123
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