TemplatesTable: allow to filter by usage

fixes #1339
This commit is contained in:
Thomas Gelf 2018-10-30 17:55:50 +01:00
parent ffe2ccf170
commit a09bd4df95
3 changed files with 23 additions and 3 deletions

View File

@ -12,6 +12,8 @@ master (will be 1.6.0)
### User Interface
* FIX: link startup log warning even for non-standard package names (#1633)
* FEATURE: allow to filter templates by usage (#1339)
* FEATURE: allow to show SQL used for template tables
### Import and Sync
* FEATURE: new Property Modifier allows to extract specific Array values (#473)

View File

@ -181,7 +181,6 @@ abstract class ObjectsController extends ActionController
* Loads the TemplatesTable or the TemplateTreeRenderer
*
* Passing render=tree switches to the tree view.
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\Http\HttpNotFoundException
* @throws \Icinga\Security\SecurityException
* @throws NotFoundError
@ -210,6 +209,8 @@ abstract class ObjectsController extends ActionController
$table = TemplatesTable::create($shortType, $this->db());
$this->eventuallyFilterCommand($table);
$table->renderTo($this);
(new AdditionalTableActions($this->getAuth(), $this->url(), $table))
->appendTo($this->actions());
}
}
@ -223,7 +224,6 @@ abstract class ObjectsController extends ActionController
}
/**
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\Http\HttpNotFoundException
* @throws \Icinga\Security\SecurityException
* @throws NotFoundError

View File

@ -16,7 +16,7 @@ use dipl\Web\Table\ZfQueryBasedTable;
use dipl\Web\Url;
use Zend_Db_Select as ZfSelect;
class TemplatesTable extends ZfQueryBasedTable
class TemplatesTable extends ZfQueryBasedTable implements FilterableByUsage
{
use MultiSelect;
@ -96,6 +96,24 @@ class TemplatesTable extends ZfQueryBasedTable
return $this;
}
public function showOnlyUsed()
{
$type = $this->getType();
$this->getQuery()->where(
"(EXISTS (SELECT ${type}_id FROM icinga_${type}_inheritance"
. " WHERE parent_${type}_id = o.id))"
);
}
public function showOnlyUnUsed()
{
$type = $this->getType();
$this->getQuery()->where(
"(NOT EXISTS (SELECT ${type}_id FROM icinga_${type}_inheritance"
. " WHERE parent_${type}_id = o.id))"
);
}
protected function applyRestrictions(ZfSelect $query)
{
$auth = Auth::getInstance();