Commit 6c8b98c6 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(management) Search in nameAttr and mainAttr

Still needs to be added: ACL check to avoid crashes, and
 plSearchAttribute key in plInfo for tabs to add fields to the search.

issue #5867
Showing with 27 additions and 16 deletions
+27 -16
......@@ -352,7 +352,7 @@ class objects
return static::open('new', $type);
}
static function infos ($type)
static function &infos ($type)
{
global $config;
......@@ -395,11 +395,7 @@ class objects
{
global $config;
if (!isset($config->data['OBJECTS'][strtoupper($type)])) {
throw new NonExistingObjectTypeException('Non-existing type "'.$type.'"');
}
$infos =& $config->data['OBJECTS'][strtoupper($type)];
$infos =& static::infos($type);
if (!isset($infos['filterObject'])) {
$infos['filterObject'] = ldapFilter::parse($infos['filter']);
......@@ -407,6 +403,20 @@ class objects
return $infos['filterObject'];
}
/* This method allows to cache searched attributes list in objectTypes */
static function getSearchedAttributes ($type)
{
global $config;
$infos =& static::infos($type);
if (!isset($infos['searchAttributes'])) {
$infos['searchAttributes'] = array_unique(array($infos['mainAttr'], $infos['nameAttr']));
}
return $infos['searchAttributes'];
}
static function types ()
{
global $config;
......
......@@ -25,7 +25,7 @@ class managementFilter
{
protected $types;
protected $searchAttributes = array('cn', 'description');
protected $searchAttributes = array();
protected $scope = 'one';
protected $showTemplates = FALSE;
......@@ -61,6 +61,7 @@ class managementFilter
'filters' => array(),
'infos' => objects::infos($type),
);
$this->searchAttributes = array_unique(array_merge($this->searchAttributes, objects::getSearchedAttributes($type)));
}
$this->filterElements = array(
......@@ -132,15 +133,6 @@ class managementFilter
{
global $ui;
$elementFilters = array();
if (!empty($this->search)) {
if (preg_match('/^\(.+\)$/', $this->search)) {
$elementFilters[] = $this->search;
} else {
$elementFilters[] = '(|('.implode('=*'.$this->search.'*)(', $this->searchAttributes).'=*'.$this->search.'*))';
}
}
$objectTypeCount = array();
$entries = array();
$row = 0;
......@@ -171,6 +163,15 @@ class managementFilter
}
}
$elementFilters = array();
if (!empty($this->search)) {
if (preg_match('/^\(.+\)$/', $this->search)) {
$elementFilters[] = $this->search;
} else {
$elementFilters[] = '(|('.implode('=*'.$this->search.'*)(', objects::getSearchedAttributes($type)).'=*'.$this->search.'*))';
}
}
$typeElementFilters = $elementFilters;
foreach ($this->filterElements as $element) {
$skip = $element->getFilters($type, $typeElementFilters);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment