1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Icinga\Module\Trapdirector\Tables; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
trait TrapDirectorTableFilter |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/********* Filter ********/ |
10
|
|
|
/** @var string $filterString : string filter for db columns */ |
11
|
|
|
protected $filterString = ''; |
12
|
|
|
|
13
|
|
|
/** @var array $filterColumn : columns to apply filter to */ |
14
|
|
|
protected $filterColumn = array(); |
15
|
|
|
|
16
|
|
|
protected $filterQuery=''; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/**************** Filtering ******************/ |
20
|
|
|
|
21
|
|
|
public function applyFilter() |
22
|
|
|
{ |
23
|
|
|
if ($this->filterString == '' || count($this->filterColumn) == 0) |
24
|
|
|
{ |
25
|
|
|
return $this; |
26
|
|
|
} |
27
|
|
|
$filter=''; |
28
|
|
|
foreach ($this->filterColumn as $column) |
29
|
|
|
{ |
30
|
|
|
if ($filter != "") $filter.=' OR '; |
31
|
|
|
//$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
32
|
|
|
$filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
33
|
|
|
} |
34
|
|
|
//echo $filter; |
35
|
|
|
|
36
|
|
|
$this->query=$this->query->where($filter); |
|
|
|
|
37
|
|
|
|
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setFilter(string $filter, array $filterCol) |
42
|
|
|
{ |
43
|
|
|
$this->filterString = $filter; |
44
|
|
|
$this->filterColumn = $filterCol; |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function renderFilter() |
49
|
|
|
{ |
50
|
|
|
|
51
|
|
|
$html=' <form id="genfilter" name="mainFilterGen" |
52
|
|
|
enctype="application/x-www-form-urlencoded" |
53
|
|
|
action="'.$this->getCurrentURLAndQS('filter').'" |
|
|
|
|
54
|
|
|
method="get">'; |
55
|
|
|
$html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
56
|
|
|
placeholder="Search..." value="'.$this->filterQuery.'">'; |
57
|
|
|
|
58
|
|
|
$html.='</form>'; |
59
|
|
|
return $html; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getFilterQuery(array $getVars) |
63
|
|
|
{ |
64
|
|
|
if (isset($getVars['f'])) |
65
|
|
|
{ |
66
|
|
|
$this->filterQuery = $getVars['f']; |
67
|
|
|
$this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function curFilterQuery() |
72
|
|
|
{ |
73
|
|
|
if ($this->filterQuery == '') return ''; |
74
|
|
|
return 'f='.$this->filterQuery; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |