added filter in services treeview

This commit is contained in:
alejandro.campos@artica.es 2022-05-23 12:51:32 +02:00
parent 43bcc4465f
commit ba0c6a7ed7
1 changed files with 38 additions and 6 deletions

View File

@ -252,6 +252,7 @@ class TreeService extends Tree
protected function getProcessedServices()
{
$is_favourite = $this->getServiceFavouriteFilter();
$service_search = $this->getServiceNameSearchFilter();
if (users_can_manage_group_all('AR')) {
$groups_acl = '';
@ -259,6 +260,16 @@ class TreeService extends Tree
$groups_acl = 'AND ts.id_group IN ('.implode(',', $this->userGroupsArray).')';
}
$exclude_children = 'ts.id NOT IN (
SELECT DISTINCT id_service_child
FROM tservice_element
WHERE id_server_meta = 0
)';
if ($service_search !== '') {
$exclude_children = '1=1';
}
$sql = sprintf(
'SELECT
ts.id,
@ -277,15 +288,14 @@ class TreeService extends Tree
FROM tservice ts
LEFT JOIN tservice_element tse
ON tse.id_service = ts.id
WHERE ts.id NOT IN (
SELECT DISTINCT id_service_child
FROM tservice_element
WHERE id_server_meta = 0
)
WHERE %s
%s
%s
%s
GROUP BY ts.id',
$exclude_children,
$is_favourite,
$service_search,
$groups_acl
);
@ -346,7 +356,12 @@ class TreeService extends Tree
global $config;
$service = new Service($this->id, true);
// hd("SRVSRVSRVSRVSRVSRV", true);
// hd($service, true);
/*
if ($this->filter['searchService'] !== '') {
$filter[] = " (tservice.name LIKE '%".$this->filter['searchService']."%' OR tservice.description LIKE '%".$this->filter['searchService']."%')";
}*/
$output = [];
foreach ($service->children() as $item) {
$tmp = [];
@ -704,6 +719,23 @@ class TreeService extends Tree
}
/**
* Retrieve SQL filter for current filter
*
* @return string SQL filter.
*/
protected function getServiceNameSearchFilter()
{
if (isset($this->filter['searchService']) === true
&& empty($this->filter['searchService']) === false
) {
return " AND (ts.name LIKE '%".$this->filter['searchService']."%' OR ts.description LIKE '%".$this->filter['searchService']."%')";
}
return '';
}
/**
* Overwrites partial functionality of general Tree.class.
*