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,
'nbObjectsByPage' => NB_LSOBJECT_LIST,
'nbPageLinkByPage' => 10,
'customInfos' => array(),
'withoutCache' => false
);
@ -441,6 +442,24 @@ class LSsearch {
if (is_string($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();
return $OK;
@ -1126,5 +1145,8 @@ _("LSsearch : Error during the search.")
LSerror :: defineError('LSsearch_13',
_("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']);
return $this -> cache['displayName'];
}
elseif ($key=='LSobject'||$key=='type_name'||$key=='type') {
return $this -> LSobject;
}
elseif ($key=='dn') {
return $this -> dn;
}
@ -174,7 +177,20 @@ class LSsearchEntry {
elseif (in_array($key,array_keys($this -> attrs))) {
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 {
LSlog('LSsearchEntry : '.$this -> dn.' => Unknown property '.$key.' !');
return __("Unknown property !");
}
}