Skip to content
Permalink
Browse files

Permet la gestion des index pactols dans l'affichage de l'alphabet su…

…r la page des index
  • Loading branch information...
lnprieto committed Jan 29, 2019
1 parent de88151 commit 5d841483f66420109afe97e9630e4e45a197659f
Showing with 119 additions and 3 deletions.
  1. +82 −0 lodel/scripts/loops.php
  2. +10 −1 lodel/src/lodel/admin/tpl/entries.html
  3. +27 −2 share/macros/macros_admin.html
@@ -902,6 +902,88 @@ function loop_alphabetSpec($context, $funcname)
usecurrentdb();
}
/**
* Boucle Lodelscript qui affiche la première lettre (distincte) de tous les tuples d'un champ
* Spécifique au cas où le champs de tri est un mltext dans une autre table
* @param array $context le contexte
* @param string $funcname le nom de la fonction
*/
function loop_alphabetSpecEntries($context, $funcname)
{
global $db;
if(empty($context['table']) || empty($context['field']) || empty($context['attributes_table']) || empty($context['idtype']))
trigger_error("ERROR: loop_alphabetSpec requires arguments 'table', 'attributes_table', 'idtype' and 'field'.", E_USER_ERROR);
$whereSelect = $whereCount = '';
$table = $context['table'];
$whereSelect = "WHERE idtype = '{$context['idtype']}'";
$whereCount = " idtype = '{$context['idtype']}' AND ";
$status = C::get('editor', 'lodeluser') ? ' status > -64 ' : ' status > 0 ';
$sql = lq("SELECT entry.id, attribute.{$context['field']} as sortkey FROM #_TP_{$context['table']} entry, #_TP_{$context['attributes_table']} attribute WHERE entry.id=attribute.identry AND entry.idtype={$context['idtype']} AND ".$status);
/*$sql2 = lq("SELECT COUNT({$context['field']}) as nbresults FROM #_TP_{$context['table']} WHERE {$whereCount} {$status} AND SUBSTRING({$context['field']},1,1) = ");
$whereSelect .= !empty($whereSelect) ? ' AND '.$status : 'WHERE '.$status;
$sql = "SELECT DISTINCT(SUBSTRING({$context['field']},1,1)) as l
FROM #_TP_{$table}
{$whereSelect}
ORDER BY l";*/
$results = $db->getArray(lq($sql));
$fields = array();
$firstletters = array();
foreach ($results as $result) {
$fields[$result['id']] = multilingue($result['sortkey'],$context['sitelang']);
$firstletters[$result['id']] = strtoupper(substr($fields[$result['sortkey']], 0, 1));
}
$count_letters = array_count_values($firstletters);
$lettres = array_unique($firstletters);
if(empty($lettres))
{
if(function_exists('code_alter_'.$funcname))
call_user_func('code_alter_'.$funcname, $context);
usecurrentdb();
return;
}
foreach($lettres as &$lettre) {
if($lettre != '<' && $lettre != '>' && $lettre != ' ')
$lettre = strtoupper(makeSortKey($lettre));
}
for ($l = 'A'; $l != 'AA'; $l++) {
$context['lettre'] = $l;
$context['nbresults'] = $count_letters[$l];
call_user_func("code_do_$funcname", $context);
}
// bug PHP : si on ne passe le tableau en référence, il modifie la derniere valeur du tableau et vire les références !!!
foreach($lettres as &$lettre) {
if($lettre >= '0' && $lettre <= '9') {
$context['lettre'] = $lettre;
$context['nbresults'] = $count_letters[$context['lettre']];
call_user_func("code_do_$funcname", $context);
}
}
foreach($lettres as &$lettre) {
if($lettre == '') continue;
if(!preg_match("/[A-Z]/", $lettre) && !preg_match("/[0-9]/", $lettre)) {
$context['lettre'] = $lettre;
$context['nbresults'] = $count_letters[$context['lettre']];
call_user_func("code_do_$funcname", $context);
}
}
usecurrentdb();
}
function loop_classtypes($context, $funcname)
{
@@ -99,7 +99,16 @@
</IF>
<br /><br />
<div id="alphabet">
<FUNC NAME="ALPHABETSPECIFIC" TABLE="entries" FIELD="[#TYPE.SORT]" IDTYPE="[#IDTYPE]" EXTERNAL="[#EXTERNAL]">
<LOOP NAME="screennameType" TABLE="tablefields" SELECT="type" WHERE="name='[#SCREEN_NAME]'">
<DO>
<LET VAR="TYPESN" GLOBAL="1">[#TYPE]</LET>
</DO>
</LOOP>
<IF COND="[%TYPESN] EQ 'mltext'">
<FUNC NAME="ALPHABETSPECIFICENTRIES" TABLE="entries" FIELD="[#SCREEN_NAME]" IDTYPE="[#IDTYPE]" EXTERNAL="[#EXTERNAL]" LISTALL="[#LISTALL]">
<ELSE />
<FUNC NAME="ALPHABETSPECIFIC" TABLE="entries" FIELD="[#TYPE.SORT]" IDTYPE="[#IDTYPE]" EXTERNAL="[#EXTERNAL]" LISTALL="[#LISTALL]">
</IF>
</div>
</IF>

@@ -80,6 +80,27 @@
</LOOP>
</DEFFUNC>

<DEFFUNC NAME="ALPHABETSPECIFICENTRIES" REQUIRED="table, field, idtype" OPTIONAL="listall, external">
<LET VAR="field">[#FIELD]</LET>
<LET VAR="table">[#TABLE]</LET>
<LET VAR="attributestable">#_TP_[#TYPE.CLASS]</LET>
<LOOP NAME="alphabetSpecEntries">
<IF COND="[#LISTALL]">
<IF COND="[#NBRESULTS] GT 0">
<a href="#[#LETTRE]">[#LETTRE]</a>
<ELSE />
[#LETTRE]&nbsp;
</IF>
<ELSE />
<IF COND="[#NBRESULTS] GT 0">
<a href="[#CURRENTURL|reg_replace('/[&?](amp;)?offset_\w+=[^&]+/', '')|reg_replace('/[&?](amp;)?letter=[^&]+/', '')|reg_replace('/[&?](amp;)?clearcache=[^&]+/', '')]&amp;letter=[#LETTRE|urlencode]">[#LETTRE]</a>
<ELSE />
[#LETTRE]&nbsp;
</IF>
</IF>
</LOOP>
</DEFFUNC>

<DEFFUNC NAME="LIST_PERSONS" REQUIRED="id, idtype" OPTIONAL="folder, sort, letter, listall">
<IF COND="[#LISTALL]">
<LET VAR="table">persons</LET>
@@ -148,8 +169,12 @@ <h2 id="[#LETTRESQL|stripslashes]">
</DEFFUNC>

<DEFFUNC NAME="LIST_ENTRIES" REQUIRED="id, idtype" OPTIONAL="folder, sort, letter, listall, external">
<IF COND="[#EXTERNAL]"><LET VAR="table">`[#DB_EXT]`.#_TP_entries</LET><LET VAR="attributes_table">`[#DB_EXT]`.#_TP_[#TYPE.CLASS]</LET>
<ELSE/><LET VAR="table">#_TP_entries</LET><LET VAR="attributes_table">#_TP_[#TYPE.CLASS]</LET>
<IF COND="[#EXTERNAL]">
<LET VAR="table">`[#DB_EXT]`.#_TP_entries</LET>
<LET VAR="attributes_table">`[#DB_EXT]`.#_TP_[#TYPE.CLASS]</LET>
<ELSE/>
<LET VAR="table">#_TP_entries</LET>
<LET VAR="attributes_table">#_TP_[#TYPE.CLASS]</LET>
</IF>
<IF COND="[#SORT] EQ 'sortkey'">
<LET VAR="field">[#SORT]</LET>

0 comments on commit 5d84148

Please sign in to comment.
You can’t perform that action at this time.