From ba0c6a7ed77c90cec5d0dc10dfebb767d6a7fee3 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 23 May 2022 12:51:32 +0200 Subject: [PATCH] added filter in services treeview --- .../include/class/TreeService.class.php | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index ebca4562a6..49f9a8a144 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -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. *