2015-06-03 14:34:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Tables;
|
|
|
|
|
2016-03-24 13:08:35 +01:00
|
|
|
use Icinga\Module\Director\Web\Table\QuickTable;
|
2015-06-03 14:34:54 +02:00
|
|
|
|
2016-03-24 13:08:35 +01:00
|
|
|
class IcingaServiceTable extends QuickTable
|
2015-06-03 14:34:54 +02:00
|
|
|
{
|
2015-07-29 15:30:10 +02:00
|
|
|
protected $searchColumns = array(
|
|
|
|
'service',
|
|
|
|
);
|
|
|
|
|
2015-06-03 14:34:54 +02:00
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
return array(
|
2016-03-24 13:08:35 +01:00
|
|
|
'id' => 's.id',
|
|
|
|
'service' => 's.object_name',
|
|
|
|
'object_type' => 's.object_type',
|
|
|
|
'check_command_id' => 's.check_command_id',
|
2015-06-03 14:34:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:08:35 +01:00
|
|
|
protected function listTableClasses()
|
|
|
|
{
|
|
|
|
return array_merge(array('assignment-table'), parent::listTableClasses());
|
|
|
|
}
|
|
|
|
|
2015-06-03 14:34:54 +02:00
|
|
|
protected function getActionUrl($row)
|
|
|
|
{
|
2016-03-18 13:02:45 +01:00
|
|
|
// TODO: Remove once we got a separate apply table
|
2016-03-06 14:28:12 +01:00
|
|
|
if ($row->object_type === 'apply') {
|
|
|
|
$params['id'] = $row->id;
|
|
|
|
} else {
|
|
|
|
$params = array('name' => $row->service);
|
2016-03-18 13:02:45 +01:00
|
|
|
|
2015-12-10 12:55:34 +01:00
|
|
|
}
|
2016-03-06 14:28:12 +01:00
|
|
|
|
2015-12-10 12:55:34 +01:00
|
|
|
return $this->url('director/service', $params);
|
2015-06-03 14:34:54 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:08:35 +01:00
|
|
|
protected function renderRow($row)
|
|
|
|
{
|
|
|
|
$v = $this->view();
|
|
|
|
$extra = $this->appliedOnes($row->id);
|
|
|
|
$htm = " <tr" . $this->getRowClassesString($row) . ">\n";
|
|
|
|
$htm .= '<td>' . $v->qlink($row->service, $this->getActionUrl($row));
|
|
|
|
if (empty($extra)) {
|
|
|
|
if ($row->check_command_id) {
|
|
|
|
$htm .= ' ' . $v->qlink(
|
|
|
|
'Create apply-rule',
|
|
|
|
'director/service/apply',
|
|
|
|
array('template' => $row->service),
|
|
|
|
array('class' => 'icon-plus')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$htm .= '. Related apply rules: <ul class="apply-rules">';
|
|
|
|
foreach ($extra as $id => $service) {
|
|
|
|
$htm .= '<li>'
|
|
|
|
. $v->qlink($service, 'director/service', array('id' => $id))
|
|
|
|
. '</li>';
|
|
|
|
}
|
|
|
|
$htm .= '</ul>';
|
|
|
|
$htm .= $v->qlink(
|
|
|
|
'Add more',
|
|
|
|
'director/service/apply',
|
|
|
|
array('template' => $row->service),
|
|
|
|
array('class' => 'icon-plus')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$htm .= '</td>';
|
|
|
|
return $htm . " </tr>\n";
|
|
|
|
}
|
|
|
|
|
2015-06-03 14:34:54 +02:00
|
|
|
public function getTitles()
|
|
|
|
{
|
|
|
|
$view = $this->view();
|
|
|
|
return array(
|
|
|
|
'service' => $view->translate('Servicename'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-07-30 16:24:17 +02:00
|
|
|
public function getUnfilteredQuery()
|
2015-06-03 14:34:54 +02:00
|
|
|
{
|
|
|
|
$db = $this->connection()->getConnection();
|
|
|
|
$query = $db->select()->from(
|
|
|
|
array('s' => 'icinga_service'),
|
2015-07-23 16:19:22 +02:00
|
|
|
array()
|
2015-06-03 14:34:54 +02:00
|
|
|
);
|
|
|
|
|
2015-07-23 16:19:22 +02:00
|
|
|
return $query;
|
2015-06-03 14:34:54 +02:00
|
|
|
}
|
2015-07-30 16:24:17 +02:00
|
|
|
|
2016-03-24 13:08:35 +01:00
|
|
|
protected function appliedOnes($id)
|
|
|
|
{
|
|
|
|
$db = $this->connection()->getConnection();
|
|
|
|
$query = $db->select()->from(
|
|
|
|
array('s' => 'icinga_service'),
|
|
|
|
array(
|
|
|
|
'id' => 's.id',
|
|
|
|
'objectname' => 's.object_name',
|
|
|
|
)
|
|
|
|
)->join(
|
|
|
|
array('i' => 'icinga_service_inheritance'),
|
|
|
|
'i.service_id = s.id',
|
|
|
|
array()
|
2016-03-24 18:50:48 +01:00
|
|
|
)->where('i.parent_service_id = ?', $id)
|
|
|
|
->where('s.object_type = ?', 'apply');
|
2016-03-24 13:08:35 +01:00
|
|
|
|
|
|
|
return $db->fetchPairs($query);
|
|
|
|
}
|
|
|
|
|
2015-07-30 16:24:17 +02:00
|
|
|
public function getBaseQuery()
|
|
|
|
{
|
2016-03-18 13:02:45 +01:00
|
|
|
return $this->getUnfilteredQuery()->where(
|
|
|
|
's.object_type IN (?)',
|
2016-03-24 13:08:35 +01:00
|
|
|
array('template')
|
2016-03-24 18:50:48 +01:00
|
|
|
)->order('CASE WHEN s.check_command_id IS NULL THEN 1 ELSE 0 END')
|
|
|
|
->order('s.object_name');
|
2015-07-30 16:24:17 +02:00
|
|
|
}
|
2015-06-03 14:34:54 +02:00
|
|
|
}
|