DatafieldTable: modernize formatting
This commit is contained in:
parent
f12dac159d
commit
cd55a65a9c
|
@ -9,14 +9,14 @@ use Zend_Db_Select as ZfDbSelect;
|
||||||
|
|
||||||
class DatafieldTable extends ZfQueryBasedTable
|
class DatafieldTable extends ZfQueryBasedTable
|
||||||
{
|
{
|
||||||
protected $searchColumns = array(
|
protected $searchColumns = [
|
||||||
'df.varname',
|
'df.varname',
|
||||||
'df.caption',
|
'df.caption',
|
||||||
);
|
];
|
||||||
|
|
||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'id' => 'df.id',
|
'id' => 'df.id',
|
||||||
'varname' => 'df.varname',
|
'varname' => 'df.varname',
|
||||||
'caption' => 'df.caption',
|
'caption' => 'df.caption',
|
||||||
|
@ -25,7 +25,7 @@ class DatafieldTable extends ZfQueryBasedTable
|
||||||
'category' => 'dfc.category_name',
|
'category' => 'dfc.category_name',
|
||||||
'assigned_fields' => 'SUM(used_fields.cnt)',
|
'assigned_fields' => 'SUM(used_fields.cnt)',
|
||||||
'assigned_vars' => 'SUM(used_vars.cnt)',
|
'assigned_vars' => 'SUM(used_vars.cnt)',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderRow($row)
|
public function renderRow($row)
|
||||||
|
@ -45,46 +45,46 @@ class DatafieldTable extends ZfQueryBasedTable
|
||||||
|
|
||||||
public function getColumnsToBeRendered()
|
public function getColumnsToBeRendered()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
$this->translate('Label'),
|
$this->translate('Label'),
|
||||||
$this->translate('Field name'),
|
$this->translate('Field name'),
|
||||||
$this->translate('Category'),
|
$this->translate('Category'),
|
||||||
$this->translate('# Used'),
|
$this->translate('# Used'),
|
||||||
$this->translate('# Vars'),
|
$this->translate('# Vars'),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepareQuery()
|
public function prepareQuery()
|
||||||
{
|
{
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
$fieldTypes = array('command', 'host', 'notification', 'service', 'user');
|
$fieldTypes = ['command', 'host', 'notification', 'service', 'user'];
|
||||||
$varsTypes = array('command', 'host', 'notification', 'service', 'service_set', 'user');
|
$varsTypes = ['command', 'host', 'notification', 'service', 'service_set', 'user'];
|
||||||
|
|
||||||
$fieldsQueries = array();
|
$fieldsQueries = [];
|
||||||
foreach ($fieldTypes as $type) {
|
foreach ($fieldTypes as $type) {
|
||||||
$fieldsQueries[] = $this->makeDatafieldSub($type, $db);
|
$fieldsQueries[] = $this->makeDatafieldSub($type, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
$varsQueries = array();
|
$varsQueries = [];
|
||||||
foreach ($varsTypes as $type) {
|
foreach ($varsTypes as $type) {
|
||||||
$varsQueries[] = $this->makeVarSub($type, $db);
|
$varsQueries[] = $this->makeVarSub($type, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $db->select()->from(
|
return $db->select()->from(
|
||||||
array('df' => 'director_datafield'),
|
['df' => 'director_datafield'],
|
||||||
$this->getColumns()
|
$this->getColumns()
|
||||||
)->joinLeft(
|
)->joinLeft(
|
||||||
['dfc' => 'director_datafield_category'],
|
['dfc' => 'director_datafield_category'],
|
||||||
'df.category_id = dfc.id',
|
'df.category_id = dfc.id',
|
||||||
[]
|
[]
|
||||||
)->joinLeft(
|
)->joinLeft(
|
||||||
array('used_fields' => $db->select()->union($fieldsQueries, ZfDbSelect::SQL_UNION_ALL)),
|
['used_fields' => $db->select()->union($fieldsQueries, ZfDbSelect::SQL_UNION_ALL)],
|
||||||
'used_fields.datafield_id = df.id',
|
'used_fields.datafield_id = df.id',
|
||||||
array()
|
[]
|
||||||
)->joinLeft(
|
)->joinLeft(
|
||||||
array('used_vars' => $db->select()->union($varsQueries, ZfDbSelect::SQL_UNION_ALL)),
|
['used_vars' => $db->select()->union($varsQueries, ZfDbSelect::SQL_UNION_ALL)],
|
||||||
'used_vars.varname = df.varname',
|
'used_vars.varname = df.varname',
|
||||||
array()
|
[]
|
||||||
)->group('df.id')->group('df.varname')->order('caption ASC');
|
)->group('df.id')->group('df.varname')->order('caption ASC');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,14 +96,10 @@ class DatafieldTable extends ZfQueryBasedTable
|
||||||
*/
|
*/
|
||||||
protected function makeDatafieldSub($type, ZfDbAdapter $db)
|
protected function makeDatafieldSub($type, ZfDbAdapter $db)
|
||||||
{
|
{
|
||||||
return $db->select()
|
return $db->select()->from("icinga_${type}_field", [
|
||||||
->from(
|
'cnt' => 'COUNT(*)',
|
||||||
sprintf('icinga_%s_field', $type),
|
'datafield_id'
|
||||||
array(
|
])->group('datafield_id');
|
||||||
'cnt' => 'COUNT(*)',
|
|
||||||
'datafield_id'
|
|
||||||
)
|
|
||||||
)->group('datafield_id');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,13 +110,9 @@ class DatafieldTable extends ZfQueryBasedTable
|
||||||
*/
|
*/
|
||||||
protected function makeVarSub($type, ZfDbAdapter $db)
|
protected function makeVarSub($type, ZfDbAdapter $db)
|
||||||
{
|
{
|
||||||
return $db->select()
|
return $db->select()->from("icinga_${type}_var", [
|
||||||
->from(
|
'cnt' => 'COUNT(*)',
|
||||||
sprintf('icinga_%s_var', $type),
|
'varname'
|
||||||
array(
|
])->group('varname');
|
||||||
'cnt' => 'COUNT(*)',
|
|
||||||
'varname'
|
|
||||||
)
|
|
||||||
)->group('varname');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue