LSobject : Add possibility to add extra displayed columns in search result

This commit is contained in:
Benjamin Renard 2014-06-17 16:08:41 +02:00
parent 73c9b385f8
commit 33cef8be28
7 changed files with 142 additions and 2 deletions

View file

@ -38,6 +38,20 @@ configuration des &LSobjects;, dans la variable <varname>LSsearch</varname>
'predefinedFilters' => array( 'predefinedFilters' => array(
'filter1' => 'label filter1', 'filter1' => 'label filter1',
'filter2' => 'label filter2' 'filter2' => 'label filter2'
),
'extraDisplayedColumns' => array(
'col1' => array(
'label' => 'label column 1',
'LSformat' => '[LSformat]'
),
'col2' => array(
'label' => 'label column 2',
'LSformat' => '[LSformat]',
'alternativeLSformats' => array (
'[LSformat 1]',
'[LSformat 2]'
)
)
) )
);]]> );]]>
</programlisting> </programlisting>
@ -217,6 +231,44 @@ contexte dans lequel cette recherche est effectuée.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>extraDisplayedColumns</term>
<listitem>
<para>Tableau associatif contenant des colonnes supplémentaires à afficher dans les
résultats de recherche. Les clés sont les identifiants des colonnes supplémentaires
et les valeurs sont leur configuration définie à partir des paramètres suivant :</para>
<variablelist>
<varlistentry>
<term>label</term>
<listitem>
<simpara>Le label de la colonne.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>LSformat</term>
<listitem>
<simpara>Le &LSformat; d'affichage de la colonne. Ce format est composé à partir
des attributs des objets LDAP dans leur format brut.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>alternativeLSformats</term>
<listitem>
<simpara>Tableau des &LSformats; alternatifs à utiliser si le résultat du format
principal est vide. Les formats définis dans cette liste sont essayés les uns
après les autres et le premier &LSformat; retournant une valeur non-vide est
utilisé.</simpara>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</para> </para>

View file

@ -143,6 +143,12 @@ $GLOBALS['LSobjects']['LSpeople'] = array (
'predefinedFilters' => array ( 'predefinedFilters' => array (
'(jpegPhoto=*)' => 'With photo', '(jpegPhoto=*)' => 'With photo',
'(!(jpegPhoto=*))' => 'Without photo' '(!(jpegPhoto=*))' => 'Without photo'
),
'extraDisplayedColumns' => array (
'mail' => array (
'label' => 'Mail',
'LSformat' => '%{mail}'
),
) )
), ),

View file

@ -60,7 +60,8 @@ class LSsearch {
'nbObjectsByPage' => NB_LSOBJECT_LIST, 'nbObjectsByPage' => NB_LSOBJECT_LIST,
'nbPageLinkByPage' => 10, 'nbPageLinkByPage' => 10,
'customInfos' => array(), 'customInfos' => array(),
'withoutCache' => false 'withoutCache' => false,
'extraDisplayedColumns' => false,
); );
// The cache of search parameters // The cache of search parameters
@ -365,7 +366,7 @@ class LSsearch {
// Sort By // Sort By
if (isset($params['sortBy']) && is_string($params['sortBy'])) { if (isset($params['sortBy']) && is_string($params['sortBy'])) {
if (in_array($params['sortBy'],array('displayName','subDn'))) { if (in_array($params['sortBy'],array('displayName','subDn')) || ($this ->extraDisplayedColumns && isset($this ->extraDisplayedColumns[$params['sortBy']]))) {
if ($this -> params['sortBy'] == $params['sortBy']) { if ($this -> params['sortBy'] == $params['sortBy']) {
$this -> toggleSortDirection(); $this -> toggleSortDirection();
} }
@ -452,6 +453,11 @@ class LSsearch {
} }
} }
// Extra Columns
if (isset($params['extraDisplayedColumns'])) {
$this -> params['extraDisplayedColumns']=(bool)$params['extraDisplayedColumns'];
}
// predefinedFilter // predefinedFilter
if (isset($params['predefinedFilter'])) { if (isset($params['predefinedFilter'])) {
if (is_string($params['predefinedFilter'])) { if (is_string($params['predefinedFilter'])) {
@ -788,6 +794,31 @@ class LSsearch {
else { else {
$retval['attributes']=$attrs; $retval['attributes']=$attrs;
} }
// Extra Columns
if ($this -> params['extraDisplayedColumns'] && is_array($this -> config['extraDisplayedColumns'])) {
foreach ($this -> config['extraDisplayedColumns'] as $id => $conf) {
$attrs=getFieldInFormat($conf['LSformat']);
if(is_array($conf['alternativeLSformats'])) {
foreach ($conf['alternativeLSformats'] as $format) {
$attrs=array_merge($attrs,getFieldInFormat($format));
}
}
else {
$attrs=array_merge($attrs,getFieldInFormat($conf['alternativeLSformats']));
}
if(is_array($retval['attributes'])) {
$retval['attributes']=array_merge($attrs,$retval['attributes']);
}
else {
$retval['attributes']=$attrs;
}
}
}
if (is_array($retval['attributes'])) {
$retval['attributes']=array_unique($retval['attributes']);
}
$this -> _searchParams = $retval; $this -> _searchParams = $retval;
} }
@ -1042,6 +1073,14 @@ class LSsearch {
} }
return $retval; return $retval;
} }
elseif ($key=='extraDisplayedColumns') {
if ($this->params['extraDisplayedColumns'] && is_array($this -> config['extraDisplayedColumns'])) {
return $this -> config['extraDisplayedColumns'];
}
else {
return False;
}
}
else { else {
throw new Exception('Incorrect property !'); throw new Exception('Incorrect property !');
} }

View file

@ -174,6 +174,20 @@ class LSsearchEntry {
} }
return; return;
} }
elseif (is_array($this->LSsearch->extraDisplayedColumns) && array_key_exists($key,$this->LSsearch->extraDisplayedColumns)) {
if(isset($this -> cache[$key])) {
return $this -> cache[$key];
}
$ret=$this -> getFData($this->LSsearch->extraDisplayedColumns[$key]['LSformat']);
if (empty($ret) && is_array($this->LSsearch->extraDisplayedColumns[$key]['alternativeLSformats'])) {
foreach($this->LSsearch->extraDisplayedColumns[$key]['alternativeLSformats'] as $format) {
$ret=$this -> getFData($format);
if (!empty($ret)) break;
}
}
$this -> cache[$key] = $ret;
return $ret;
}
elseif (in_array($key,array_keys($this -> attrs))) { elseif (in_array($key,array_keys($this -> attrs))) {
return $this -> attrs[$key]; return $this -> attrs[$key];
} }

View file

@ -122,6 +122,11 @@ if (loadDir('../'.LS_OBJECTS_DIR) && loadDir('../'.LS_LOCAL_DIR.LS_OBJECTS_DIR))
add($lay); add($lay);
} }
} }
if (is_array($conf['LSsearch']['extraDisplayedColumns'])) {
foreach($conf['LSsearch']['extraDisplayedColumns'] as $cid => $cconf) {
add($cconf['label']);
}
}
if(is_array($conf['attrs'])) { if(is_array($conf['attrs'])) {

View file

@ -70,12 +70,35 @@
{/if} {/if}
</th> </th>
{/if} {/if}
{if $LSsearch->extraDisplayedColumns}
{foreach from=$LSsearch->extraDisplayedColumns item=conf key=cid}
<th class='LSobject-list'>
{if $LSsearch->sort}
<a href='view.php?LSobject={$LSsearch->LSobject}&amp;sortBy={$cid}&amp;nocache={$smarty.now}'>
{if $LSsearch->sortBy == $cid}
<strong>{tr msg=$conf.label}</strong>
<img src='{img name=$LSsearch->sortDirection}' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
{else}
{tr msg=$conf.label}
{/if}
</a>
{else}
{tr msg=$conf.label}
{/if}
</th>
{/foreach}
{/if}
<th class='LSobject-list'>{$LSsearch->label_actions}</th> <th class='LSobject-list'>{$LSsearch->label_actions}</th>
</tr> </tr>
{foreach from=$page.list item=object} {foreach from=$page.list item=object}
<tr class='{cycle values="LSobject-list,LSobject-list LSobject-list-bis"}'> <tr class='{cycle values="LSobject-list,LSobject-list LSobject-list-bis"}'>
<td class='LSobject-list LSobject-list-names'><a href='view.php?LSobject={$LSsearch->LSobject}&amp;dn={$object->dn|escape:'url'}' class='LSobject-list'>{$object->displayName}</a> </td> <td class='LSobject-list LSobject-list-names'><a href='view.php?LSobject={$LSsearch->LSobject}&amp;dn={$object->dn|escape:'url'}' class='LSobject-list'>{$object->displayName}</a> </td>
{if $LSsearch->displaySubDn}<td class='LSobject-list'>{$object->subDn}</td>{/if} {if $LSsearch->displaySubDn}<td class='LSobject-list'>{$object->subDn}</td>{/if}
{if $LSsearch->extraDisplayedColumns}
{foreach from=$LSsearch->extraDisplayedColumns item=conf key=cid}
<td class='LSobject-list'>{$object->$cid}</th>
{/foreach}
{/if}
<td class='LSobject-list LSobject-list-actions'> <td class='LSobject-list LSobject-list-actions'>
{foreach from=$object->actions item=item} {foreach from=$object->actions item=item}
<a href='{$item.url}' class='LSobject-list-actions'><img src='{img name=$item.action}' alt='{$item.label}' title='{$item.label}'/></a> <a href='{$item.url}' class='LSobject-list-actions'><img src='{img name=$item.action}' alt='{$item.label}' title='{$item.label}'/></a>

View file

@ -109,6 +109,7 @@ if(LSsession :: startLSsession()) {
LStemplate :: assign('pagetitle',$object -> getLabel()); LStemplate :: assign('pagetitle',$object -> getLabel());
$LSsearch = new LSsearch($LSobject,'LSview'); $LSsearch = new LSsearch($LSobject,'LSview');
$LSsearch -> setParam('extraDisplayedColumns',True);
$LSsearch -> setParamsFormPostData(); $LSsearch -> setParamsFormPostData();
$searchForm = array ( $searchForm = array (