From f41ca9e87615f826c87ecd1d391e85537faa2fa7 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Sat, 13 Jan 2007 08:44:39 +0000 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20[8308]:=20le=20crit?= =?UTF-8?q?=C3=A8re=20se=20compilant=20en=20un=20Group=20By=20admet=20?= =?UTF-8?q?=C3=A0=20pr=C3=A9sent=20un=20champ=20pass=C3=A9=20par=20l'URL?= =?UTF-8?q?=20comme=20dans=20le=20squelette=20ci-dessous.=20Le=20nom=20ret?= =?UTF-8?q?enu=20est=20finalement=20'''fusion''',=20mot=20=C3=A0=20la=20fo?= =?UTF-8?q?is=20fran=C3=A7ais=20et=20anglais=20contrairement=20au=20groupb?= =?UTF-8?q?y=20de=20SQL=20(lui-meme=20d=C3=A9j=C3=A0=20pas=20tr=C3=A8s=20h?= =?UTF-8?q?eureux).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fil & Emmanuel {{{ <B_a>#PAGINATION / #GRAND_TOTAL <BOUCLE_a(SYNDIC_ARTICLES){par date}{pagination}><br />#URL</BOUCLE_a> <hr /> <B_b>#PAGINATION / #GRAND_TOTAL <BOUCLE_b(SYNDIC_ARTICLES){par date}{inverse}{pagination}{fusion #ENV{fusion}}> <br />#URL </BOUCLE_b> }}} --- ecrire/public/criteres.php | 63 ++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php index e00bbca96b..8302ebd72c 100644 --- a/ecrire/public/criteres.php +++ b/ecrire/public/criteres.php @@ -246,6 +246,41 @@ function critere_logo_dist($idb, &$boucles, $crit) { $boucle->where[]= $c; } + +// http://doc.spip.org/@critere_groupby_dist +function critere_fusion_dist($idb,&$boucles, $crit) { + if (isset($crit->param[0])) { + $x = $crit->param[0]; + if ($x[0]->type == 'texte') + $boucles[$idb]->group[] = $x[0]->texte; + else $boucles[$idb]->group[] = '".' . calculer_critere_arg_dynamique($idb, $boucles, $x) . '."'; + } else + erreur_squelette(_T('zbug_info_erreur_squelette'), + "{groupby ?} BOUCLE$idb"); +} + +function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix='') +{ + global $table_des_tables, $tables_des_serveurs_sql; + + $boucle = $boucles[$idb]; + + $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); + $r = $boucle->type_requete; + $s = $boucles[$idb]->sql_serveur; + if (!$s) $s = 'localhost'; + $t = $table_des_tables[$r]; + // pour les tables non Spip + if (!$t) $t = $r; else $t = "spip_$t"; + $desc = $tables_des_serveurs_sql[$s][$t]; + + if (is_array($desc['field'])){ + $liste_field = implode(',',array_map('_q',array_keys($desc['field']))); + return "((\$x = preg_replace(\"/\\W/\",'',$arg)) ? ( in_array(\$x,array($liste_field)) ? ('$boucle->id_table.' . \$x$suffix):(\$x$suffix) ) : '')"; + } else { + return "((\$x = preg_replace(\"/\\W/\",'',$arg)) ? ('$boucle->id_table.' . \$x$suffix) : '')"; + } +} // Tri : {par xxxx} // http://www.spip.net/@par // http://doc.spip.org/@critere_par_dist @@ -264,24 +299,7 @@ function critere_parinverse($idb, &$boucles, $crit, $sens) { $fct = ""; // en cas de fonction SQL // tris specifies dynamiquement if ($tri[0]->type != 'texte') { - $order = - calculer_liste($tri, array(), $boucles, $boucles[$idb]->id_parent); - $r = $boucle->type_requete; - $s = $boucles[$idb]->sql_serveur; - if (!$s) $s = 'localhost'; - $t = $table_des_tables[$r]; - // pour les tables non Spip - if (!$t) $t = $r; else $t = "spip_$t"; - $desc = $tables_des_serveurs_sql[$s][$t]; - if (is_array($desc['field'])){ - $liste_field = implode(',',array_map('_q',array_keys($desc['field']))); - $order = - "((\$x = preg_replace(\"/\\W/\",'',$order)) ? ( in_array(\$x,array($liste_field)) ? ('$boucle->id_table.' . \$x$sens):(\$x$sens) ) : '')"; - } - else{ - $order = - "((\$x = preg_replace(\"/\\W/\",'',$order)) ? ('$boucle->id_table.' . \$x$sens) : '')"; - } + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); } else { $par = array_shift($tri); $par = $par->texte; @@ -488,15 +506,6 @@ function critere_agenda_dist($idb, &$boucles, $crit) // sinon on prend tout } -// http://doc.spip.org/@critere_groupby_dist -function critere_groupby_dist($idb,&$boucles, $crit) { - if (isset($crit->param[0])) - $boucles[$idb]->group[] = $crit->param[0][0]->texte; - else - erreur_squelette(_T('zbug_info_erreur_squelette'), - "{groupby ?} BOUCLE$idb"); -} - // http://doc.spip.org/@calculer_critere_parties function calculer_critere_parties($idb, &$boucles, $crit) { $boucle = &$boucles[$idb]; -- GitLab