LSsearch/LSsearchEntry : Added customInfos feature

This commit is contained in:
Benjamin Renard 2009-11-11 19:52:47 +00:00
parent 9b5eb1fae0
commit 9ddb6c17e2
2 changed files with 38 additions and 0 deletions

View file

@ -57,6 +57,7 @@ class LSsearch {
'displayFormat' => NULL, 'displayFormat' => NULL,
'nbObjectsByPage' => NB_LSOBJECT_LIST, 'nbObjectsByPage' => NB_LSOBJECT_LIST,
'nbPageLinkByPage' => 10, 'nbPageLinkByPage' => 10,
'customInfos' => array(),
'withoutCache' => false 'withoutCache' => false
); );
@ -442,6 +443,24 @@ class LSsearch {
$this -> params['displayFormat'] = $params['displayFormat']; $this -> params['displayFormat'] = $params['displayFormat'];
} }
// Custom Infos
if (is_array($params['customInfos'])) {
foreach($params['customInfos'] as $name => $data) {
if(is_array($data['function']) && is_string($data['function'][0])) {
LSsession::loadLSclass($data['function'][0]);
}
if (is_callable($data['function'])) {
$this -> params['customInfos'][$name] = array (
'function' => &$data['function'],
'args' => $data['args']
);
}
else {
LSerror :: addErrorCode('LSsearch_14',$name);
}
}
}
$this -> saveParamsInSession(); $this -> saveParamsInSession();
return $OK; return $OK;
} }
@ -1126,5 +1145,8 @@ _("LSsearch : Error during the search.")
LSerror :: defineError('LSsearch_13', LSerror :: defineError('LSsearch_13',
_("LSsearch : Error sorting the search.") _("LSsearch : Error sorting the search.")
); );
LSerror :: defineError('LSsearch_14',
_("LSsearch : The function of the custum information %{name} is not callable.")
);
?> ?>

View file

@ -113,6 +113,9 @@ class LSsearchEntry {
$this -> cache['displayName'] = $this -> getFData($this -> params['displayFormat']); $this -> cache['displayName'] = $this -> getFData($this -> params['displayFormat']);
return $this -> cache['displayName']; return $this -> cache['displayName'];
} }
elseif ($key=='LSobject'||$key=='type_name'||$key=='type') {
return $this -> LSobject;
}
elseif ($key=='dn') { elseif ($key=='dn') {
return $this -> dn; return $this -> dn;
} }
@ -174,7 +177,20 @@ class LSsearchEntry {
elseif (in_array($key,array_keys($this -> attrs))) { elseif (in_array($key,array_keys($this -> attrs))) {
return $this -> attrs[$key]; return $this -> attrs[$key];
} }
elseif (array_key_exists($key,$this->params['customInfos'])) {
if(isset($this -> cache['customInfos'][$key])) {
return $this -> cache['customInfos'][$key];
}
if(is_array($this->params['customInfos'][$key]['function']) && is_string($this->params['customInfos'][$key]['function'][0])) {
LSsession::loadLSclass($this->params['customInfos'][$key]['function'][0]);
}
if(is_callable($this->params['customInfos'][$key]['function'])) {
$this -> cache['customInfos'][$key]=call_user_func($this->params['customInfos'][$key]['function'],$this,$this->params['customInfos'][$key]['args']);
return $this -> cache['customInfos'][$key];
}
}
else { else {
LSlog('LSsearchEntry : '.$this -> dn.' => Unknown property '.$key.' !');
return __("Unknown property !"); return __("Unknown property !");
} }
} }