mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-25 10:57:41 +02:00
parent
ea141b7e0a
commit
46aac60c7d
@ -3,6 +3,8 @@
|
|||||||
namespace Icinga\Module\Director\Tables;
|
namespace Icinga\Module\Director\Tables;
|
||||||
|
|
||||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||||
|
use Zend_Db_Adapter_Abstract as ZfDbAdapter;
|
||||||
|
use Zend_Db_Select as ZfDbSelect;
|
||||||
|
|
||||||
class DatafieldTable extends QuickTable
|
class DatafieldTable extends QuickTable
|
||||||
{
|
{
|
||||||
@ -13,11 +15,13 @@ class DatafieldTable extends QuickTable
|
|||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'id' => 'f.id',
|
'id' => 'df.id',
|
||||||
'varname' => 'f.varname',
|
'varname' => 'df.varname',
|
||||||
'caption' => 'f.caption',
|
'caption' => 'df.caption',
|
||||||
'description' => 'f.description',
|
'description' => 'df.description',
|
||||||
'datatype' => 'f.datatype',
|
'datatype' => 'df.datatype',
|
||||||
|
'assigned_fields' => 'SUM(used_fields.cnt)',
|
||||||
|
'assigned_vars' => 'SUM(used_vars.cnt)',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,16 +34,87 @@ class DatafieldTable extends QuickTable
|
|||||||
{
|
{
|
||||||
$view = $this->view();
|
$view = $this->view();
|
||||||
return array(
|
return array(
|
||||||
'caption' => $view->translate('Label'),
|
'caption' => $view->translate('Label'),
|
||||||
'varname' => $view->translate('Field name'),
|
'varname' => $view->translate('Field name'),
|
||||||
|
'assigned_fields' => $view->translate('# Used'),
|
||||||
|
'assigned_vars' => $view->translate('# Vars'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseQuery()
|
public function getBaseQuery()
|
||||||
{
|
{
|
||||||
return $this->db()->select()->from(
|
$db = $this->db();
|
||||||
array('f' => 'director_datafield'),
|
$fieldTypes = array('command', 'host', 'notification', 'service', 'user');
|
||||||
|
$varsTypes = array('command', 'host', 'notification', 'service', 'service_set', 'user');
|
||||||
|
|
||||||
|
$fieldsQueries = array();
|
||||||
|
foreach ($fieldTypes as $type) {
|
||||||
|
$fieldsQueries[] = $this->makeDatafieldSub($type, $db);
|
||||||
|
}
|
||||||
|
|
||||||
|
$varsQueries = array();
|
||||||
|
foreach ($varsTypes as $type) {
|
||||||
|
$varsQueries[] = $this->makeVarSub($type, $db);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $db->select()->from(
|
||||||
|
array('df' => 'director_datafield'),
|
||||||
array()
|
array()
|
||||||
)->order('caption ASC');
|
)->joinLeft(
|
||||||
|
array('used_fields' => $db->select()->union($fieldsQueries, ZfDbSelect::SQL_UNION_ALL)),
|
||||||
|
'used_fields.datafield_id = df.id',
|
||||||
|
array()
|
||||||
|
)->joinLeft(
|
||||||
|
array('used_vars' => $db->select()->union($varsQueries, ZfDbSelect::SQL_UNION_ALL)),
|
||||||
|
'used_vars.varname = df.varname',
|
||||||
|
array()
|
||||||
|
)->group('df.id')->group('df.varname')->order('caption ASC');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count()
|
||||||
|
{
|
||||||
|
$db = $this->db();
|
||||||
|
return $db->fetchOne(
|
||||||
|
$db->select()->from(
|
||||||
|
array('sub' => $this->getBaseQuery()->columns($this->getColumns())),
|
||||||
|
'COUNT(*)'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $type
|
||||||
|
* @param ZfDbAdapter $db
|
||||||
|
*
|
||||||
|
* @return ZfDbSelect
|
||||||
|
*/
|
||||||
|
protected function makeDatafieldSub($type, ZfDbAdapter $db)
|
||||||
|
{
|
||||||
|
return $db->select()
|
||||||
|
->from(
|
||||||
|
sprintf('icinga_%s_field', $type),
|
||||||
|
array(
|
||||||
|
'cnt' => 'COUNT(*)',
|
||||||
|
'datafield_id'
|
||||||
|
)
|
||||||
|
)->group('datafield_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $type
|
||||||
|
* @param ZfDbAdapter $db
|
||||||
|
*
|
||||||
|
* @return ZfDbSelect
|
||||||
|
*/
|
||||||
|
protected function makeVarSub($type, ZfDbAdapter $db)
|
||||||
|
{
|
||||||
|
return $db->select()
|
||||||
|
->from(
|
||||||
|
sprintf('icinga_%s_var', $type),
|
||||||
|
array(
|
||||||
|
'cnt' => 'COUNT(*)',
|
||||||
|
'varname'
|
||||||
|
)
|
||||||
|
)->group('varname');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user