1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Icinga\Module\Trapdirector\Tables; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
trait TrapDirectorTableGrouping |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/*************** Grouping ************/ |
11
|
|
|
|
12
|
|
|
/** @var boolean $grouppingActive set to true if grouping is active by query or function call */ |
13
|
|
|
protected $grouppingActive=false; |
14
|
|
|
|
15
|
|
|
/** @var string $groupingColumn Name of column (can be hidden) for grouping */ |
16
|
|
|
protected $groupingColumn=''; |
17
|
|
|
|
18
|
|
|
/**@var string $groupingVal Current value of grouping column in row (used while rendering) */ |
19
|
|
|
protected $groupingVal=''; |
20
|
|
|
|
21
|
|
|
/** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */ |
22
|
|
|
protected $groupingColSpan=1; |
23
|
|
|
|
24
|
|
|
/***************** Grouping ****************/ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Set grouping. column must be DB name |
28
|
|
|
* @param string $columnDBName |
29
|
|
|
*/ |
30
|
|
|
public function setGrouping(string $columnDBName) |
31
|
|
|
{ |
32
|
|
|
$this->groupingColumn = $columnDBName; |
33
|
|
|
$this->grouppingActive = TRUE; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Init of grouping before rendering |
38
|
|
|
*/ |
39
|
|
|
public function initGrouping() |
40
|
|
|
{ |
41
|
|
|
$this->groupingVal = ''; |
42
|
|
|
$this->groupingColSpan = count($this->titles); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Function to print grouping value (for ovveride in specific tables) |
47
|
|
|
* @param string $value |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function groupingPrintData( string $value ) |
51
|
|
|
{ |
52
|
|
|
$html = "$value"; |
53
|
|
|
return $html; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* When to display new grouping line (for ovveride in specific tables) |
58
|
|
|
* @param string $val1 Current value in grouping |
59
|
|
|
* @param string $val2 Value of current line |
60
|
|
|
* @return boolean TRUE if a new grouping line is needed. |
61
|
|
|
*/ |
62
|
|
|
public function groupingEvalNext(string $val1, string $val2) |
63
|
|
|
{ |
64
|
|
|
if ($val1 != $val2) |
65
|
|
|
return TRUE; |
66
|
|
|
else |
67
|
|
|
return FALSE; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Called before each line to check if grouping line is needed. |
72
|
|
|
* @param mixed $values |
73
|
|
|
* @return string with line or empty. |
74
|
|
|
*/ |
75
|
|
|
public function groupingNextLine( $values) |
76
|
|
|
{ |
77
|
|
|
if ($this->grouppingActive === FALSE) return ''; |
78
|
|
|
|
79
|
|
|
$dbcol = $this->groupingColumn; |
80
|
|
|
if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$values->$dbcol) === TRUE ) |
81
|
|
|
{ |
82
|
|
|
$this->groupingVal = $values->$dbcol; |
83
|
|
|
$html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>'; |
84
|
|
|
return $html; |
85
|
|
|
} |
86
|
|
|
return ''; |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
} |