Skip to content
Extraits de code Groupes Projets
Valider f037cb63 rédigé par esj's avatar esj
Parcourir les fichiers

criteres de boucles à présent compatibles avec des serveurs/tables externes

parent aee30962
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
<tr><td>&#35;PETITION</td><td> #PETITION</td></tr> <tr><td>&#35;PETITION</td><td> #PETITION</td></tr>
<tr><td>&#35;POPULARITE</td><td> #POPULARITE</td></tr> <tr><td>&#35;POPULARITE</td><td> #POPULARITE</td></tr>
<tr><td>&#35;EXTRA</td><td> #EXTRA</td></tr> <tr><td>&#35;EXTRA</td><td> #EXTRA</td></tr>
<tr><td>&#35;PARAMETRES_FORUM</td><td> #PARAMETRES_FORUM</td></tr>
</table> </table>
<hr /> <hr />
<table border='1' width='100%'> <table border='1' width='100%'>
...@@ -46,7 +47,7 @@ ...@@ -46,7 +47,7 @@
<tr><td>&#35;TOTAL_BOUCLE</td><td><BOUCLE_TOTAL_BOUCLE(AUTEURS)> #TOTAL_BOUCLE</BOUCLE_TOTAL_BOUCLE></td></tr> <tr><td>&#35;TOTAL_BOUCLE</td><td><BOUCLE_TOTAL_BOUCLE(AUTEURS)> #TOTAL_BOUCLE</BOUCLE_TOTAL_BOUCLE></td></tr>
<tr><td>&#35;COMPTEUR_BOUCLE</td><td><BOUCLE_COMPTEUR_BOUCLE(AUTEURS)> #COMPTEUR_BOUCLE</BOUCLE_COMPTEUR_BOUCLE></td></tr> <tr><td>&#35;COMPTEUR_BOUCLE</td><td><BOUCLE_COMPTEUR_BOUCLE(AUTEURS)> #COMPTEUR_BOUCLE</BOUCLE_COMPTEUR_BOUCLE></td></tr>
<tr><td>&#35;EXPOSER</td><td><BOUCLE_EXPOSER(ARTICLES){1,1}> #EXPOSER</BOUCLE_EXPOSER></td></tr> <tr><td>&#35;EXPOSER</td><td><BOUCLE_EXPOSER(ARTICLES){1,1}> #EXPOSER</BOUCLE_EXPOSER></td></tr>
<tr><td>&#35;LESAUTEURS</td><td><BOUCLE_LESAUTEURS(pgsql:ARTICLES){1,1}> #LESAUTEURS</BOUCLE_LESAUTEURS></td></tr> <tr><td>&#35;LESAUTEURS</td><td><BOUCLE_LESAUTEURS(ARTICLES){1,1}> #LESAUTEURS</BOUCLE_LESAUTEURS></td></tr>
<tr><td>{titre=&#35;NOM_SITE_SPIP}</td><td><BOUCLE_TITRE2(ARTICLES){id_rubrique}{id_article=#NOM_SITE_SPIP}{"<br />"}>#ID_ARTICLE #TITRE #NOM_SITE_SPIP</BOUCLE_TITRE2></td></tr> <tr><td>{titre=&#35;NOM_SITE_SPIP}</td><td><BOUCLE_TITRE2(ARTICLES){id_rubrique}{id_article=#NOM_SITE_SPIP}{"<br />"}>#ID_ARTICLE #TITRE #NOM_SITE_SPIP</BOUCLE_TITRE2></td></tr>
<tr><td>{id_article=&#35;ID_RUBRIQUE}</td><td><BOUCLE1(RUBRIQUES){par id_rubrique}><BOUCLE_TITRE1(ARTICLES){id_rubrique}{id_article=#ID_RUBRIQUE}{"<br />"}>#ID_RUBRIQUE #ID_ARTICLE </BOUCLE_TITRE1><br />#TOTAL_BOUCLE</B_TITRE1> </BOUCLE1></td></tr> <tr><td>{id_article=&#35;ID_RUBRIQUE}</td><td><BOUCLE1(RUBRIQUES){par id_rubrique}><BOUCLE_TITRE1(ARTICLES){id_rubrique}{id_article=#ID_RUBRIQUE}{"<br />"}>#ID_RUBRIQUE #ID_ARTICLE </BOUCLE_TITRE1><br />#TOTAL_BOUCLE</B_TITRE1> </BOUCLE1></td></tr>
<tr><td>{titre=&#35;TITRE*}</td><td><BOUCLE3(RUBRIQUES){par id_rubrique}><BOUCLE_TITRE3(ARTICLES){id_rubrique}{id_article=#TITRE*}{"<br />"}>#ID_RUBRIQUE #TITRE #ID_ARTICLE </BOUCLE_TITRE3></B_TITRE3> </BOUCLE3></td></tr> <tr><td>{titre=&#35;TITRE*}</td><td><BOUCLE3(RUBRIQUES){par id_rubrique}><BOUCLE_TITRE3(ARTICLES){id_rubrique}{id_article=#TITRE*}{"<br />"}>#ID_RUBRIQUE #TITRE #ID_ARTICLE </BOUCLE_TITRE3></B_TITRE3> </BOUCLE3></td></tr>
...@@ -122,5 +123,13 @@ ...@@ -122,5 +123,13 @@
<tr><td>[[g1 (&#35;TITRE) d1 [[g3 (&#35;TITRE) d3] (&#35;TITRE|strtoupper) [g4 (&#35;TITRE) d4]]] (&#35;TITRE|strtoupper) [g5 (&#35;TITRE) d5]][g6 (&#35;TITRE) d7]</td><td><BOUCLE_a(ARTICLES){1,1}> <tr><td>[[g1 (&#35;TITRE) d1 [[g3 (&#35;TITRE) d3] (&#35;TITRE|strtoupper) [g4 (&#35;TITRE) d4]]] (&#35;TITRE|strtoupper) [g5 (&#35;TITRE) d5]][g6 (&#35;TITRE) d7]</td><td><BOUCLE_a(ARTICLES){1,1}>
[[g1 (#TITRE)d1 [[g3 (#TITRE) d3] (#TITRE|strtoupper) [g4 (#TITRE) d4]]] (#TITRE|strtoupper) [g5 (#TITRE) d5]][g6 (#TITRE) d7]</td></tr></BOUCLE_a> [[g1 (#TITRE)d1 [[g3 (#TITRE) d3] (#TITRE|strtoupper) [g4 (#TITRE) d4]]] (#TITRE|strtoupper) [g5 (#TITRE) d5]][g6 (#TITRE) d7]</td></tr></BOUCLE_a>
</table> </table>
<hr />
<table border='1' width='100%'>
<tr><td colspan=2 align=center>Criteres de feu</td></tr>
<tr><td>{exclus}</td><td><BOUCLE_exclus(ARTICLES){1,1}{exclus}>#TITRE</td></tr></BOUCLE_exclus>
<tr><td>{doublons}</td><td><BOUCLE_doublons(ARTICLES){1,1}{doublons}>#TITRE</td></tr></BOUCLE_doublons>
<tr><td>{par}</td><td><BOUCLE_par(ARTICLES){1,1}{par titre}>#TITRE</td></tr></BOUCLE_par>
</table>
...@@ -112,7 +112,7 @@ function index_pile($idb, $nom_champ, &$boucles, $explicite='') { ...@@ -112,7 +112,7 @@ function index_pile($idb, $nom_champ, &$boucles, $explicite='') {
} }
if (!$t) $t = $r; // pour les tables non Spip if (!$t) $t = $r; // pour les tables non Spip
// $t est le nom PHP de cette table // $t est le nom PHP de cette table
#spip_log("Go: idb='$idb' r='$r' c='$c' nom='$nom_champ'"); # spip_log("Go: idb='$idb' r='$r' c='$c' nom='$nom_champ' s=$s");
$desc = $tables_des_serveurs_sql[$s][$t]; $desc = $tables_des_serveurs_sql[$s][$t];
if (!$desc) { if (!$desc) {
include_local("inc-admin.php3"); include_local("inc-admin.php3");
......
...@@ -134,7 +134,7 @@ function calculer_texte($texte, $id_boucle, &$boucles, $id_mere) { ...@@ -134,7 +134,7 @@ function calculer_texte($texte, $id_boucle, &$boucles, $id_mere) {
// remplissant une variable $t0 retourne'e en valeur // remplissant une variable $t0 retourne'e en valeur
// //
function calculer_boucle($id_boucle, &$boucles) { function calculer_boucle($id_boucle, &$boucles) {
global $table_primary, $table_des_tables; global $table_primary, $table_des_tables, $tables_des_serveurs_sql;
$boucle = &$boucles[$id_boucle]; $boucle = &$boucles[$id_boucle];
$type_boucle = $boucle->type_requete; $type_boucle = $boucle->type_requete;
...@@ -152,7 +152,16 @@ function calculer_boucle($id_boucle, &$boucles) { ...@@ -152,7 +152,16 @@ function calculer_boucle($id_boucle, &$boucles) {
if (!function_exists($f)) $f = $f.'_dist'; // definition spip if (!function_exists($f)) $f = $f.'_dist'; // definition spip
if (!function_exists($f)) $f = 'boucle_DEFAUT'; // definition par defaut if (!function_exists($f)) $f = 'boucle_DEFAUT'; // definition par defaut
$id_table = $table_des_tables[$type_boucle]; $id_table = $table_des_tables[$type_boucle];
$id_field = $id_table . "." . $table_primary[$type_boucle]; if ($id_table) {
$primary = $table_primary[$type_boucle];
} else { // table non Spip. Pas mal l'indexation, hein ?
$id_table = $type_boucle;
$serveur = $boucle->sql_serveur;
$primary = $tables_des_serveurs_sql[$serveur ? $serveur : 'localhost'][$type_boucle]['key']["PRIMARY KEY"];
}
$id_field = $id_table . "." . $primary; # articles.id_article -> 'table_id'
spip_log($id_field);
$f($boucle, $boucles, $type_boucle, $id_table, $id_field); $f($boucle, $boucles, $type_boucle, $id_table, $id_field);
...@@ -177,21 +186,17 @@ function calculer_boucle($id_boucle, &$boucles) { ...@@ -177,21 +186,17 @@ function calculer_boucle($id_boucle, &$boucles) {
// cas general ({lang_select} sur une table externe) // cas general ({lang_select} sur une table externe)
. 'lang'; . 'lang';
// Qui sommes-nous ?
$primary_key = $table_primary[$type_boucle];
// Calculer les invalideurs si c'est une boucle non constante // Calculer les invalideurs si c'est une boucle non constante
$constant = ereg("^\(?'[^']*'\)?$",$return); $constant = ereg("^\(?'[^']*'\)?$",$return);
if ((!$primary_key) || $constant) if ((!$primary) || $constant)
$invalide = ''; $invalide = '';
else { else {
$id_table = $table_des_tables[$type_boucle]; $boucle->select[] = $id_field;
$boucle->select[] = "$id_table.$primary_key";
$invalide = "\n \$Cache['$primary_key']"; $invalide = "\n \$Cache['$primary']";
if ($primary_key != 'id_forum') if ($primary != 'id_forum')
$invalide .= "[\$Pile[\$SP]['$primary_key']] = 1;"; $invalide .= "[\$Pile[\$SP]['$primary']] = 1;";
else else
$invalide .= "[calcul_index_forum(" . $invalide .= "[calcul_index_forum(" .
// Retournera 4 [$SP] mais force la demande du champ a MySQL // Retournera 4 [$SP] mais force la demande du champ a MySQL
...@@ -227,7 +232,7 @@ function calculer_boucle($id_boucle, &$boucles) { ...@@ -227,7 +232,7 @@ function calculer_boucle($id_boucle, &$boucles) {
if ($boucle->doublons) if ($boucle->doublons)
$debut .= "\n \$doublons['".$boucle->doublons."'] .= ','. " . $debut .= "\n \$doublons['".$boucle->doublons."'] .= ','. " .
index_pile($id_boucle, $primary_key, $boucles) index_pile($id_boucle, $primary, $boucles)
. "; // doublons"; . "; // doublons";
// gestion optimale des separateurs et des boucles constantes // gestion optimale des separateurs et des boucles constantes
...@@ -304,11 +309,11 @@ function calculer_boucle($id_boucle, &$boucles) { ...@@ -304,11 +309,11 @@ function calculer_boucle($id_boucle, &$boucles) {
// En absence de champ c'est un decompte : // En absence de champ c'est un decompte :
// on prend la primary pour avoir qqch // on prend la primary pour avoir qqch
// car le COUNT incompatible avec le cas general // car le COUNT incompatible avec le cas general
// pour les tables sans primary, prendre * mais faudrait trouver mieux
$init .= "spip_abstract_select(\n\t\tarray(\"". $init .= "spip_abstract_select(\n\t\tarray(\"".
(($boucle->select) ? (($boucle->select) ?
join("\",\n\t\t\"", array_unique($boucle->select)) : join("\",\n\t\t\"", array_unique($boucle->select)) :
((strlen($id_field) > 1) ? $id_field : '*')) . $id_field) .
'"), # SELECT '"), # SELECT
array("' . array("' .
join('","', array_unique($boucle->from)) . join('","', array_unique($boucle->from)) .
...@@ -568,7 +573,7 @@ function calculer_squelette($squelette, $nom, $gram, $sourcefile) { ...@@ -568,7 +573,7 @@ function calculer_squelette($squelette, $nom, $gram, $sourcefile) {
if ($boucle->type_requete != 'boucle') if ($boucle->type_requete != 'boucle')
{ {
$descr['id_mere'] = $id; $descr['id_mere'] = $id;
$res = calculer_criteres($id, $boucles, $descr); $res = calculer_criteres($id, $boucles);
if (is_array($res)) return $res; # erreur if (is_array($res)) return $res; # erreur
$boucles[$id]->return = $boucles[$id]->return =
calculer_liste($boucle->milieu, calculer_liste($boucle->milieu,
......
...@@ -300,14 +300,21 @@ function relations_externes ($type, $col) { ...@@ -300,14 +300,21 @@ function relations_externes ($type, $col) {
// comme {1,4}, etc. // comme {1,4}, etc.
// //
function calculer_criteres ($idb, &$boucles) { function calculer_criteres ($idb, &$boucles) {
global $tables_relations, $table_primary, $table_des_tables, $table_date; global $tables_relations, $table_primary, $table_des_tables, $table_date, $tables_des_serveurs_sql;
$boucle = &$boucles[$idb]; # nom de la boucle $boucle = &$boucles[$idb]; # nom de la boucle
$type = $boucle->type_requete; # articles
$params = $boucle->param; $params = $boucle->param;
$id_table = $table_des_tables[$type]; # articles -> 'table' if (!is_array($params)) return; // rien a faire
$primary = $table_primary[$type]; # id_article -> 'id'
$id_field = $id_table . "." . $primary; # articles.id_article -> 'table_id'
$type = $boucle->type_requete; # articles
$serveur = $boucle->sql_serveur;
$id_table = $table_des_tables[$type]; # articles -> 'table';
if ($id_table) {
$primary = $table_primary[$type]; # id_article -> 'id'
} else { // table non Spip. Pas mal l'indexation, hein ?
$id_table = $type;
$primary = $tables_des_serveurs_sql[$serveur ? $serveur : 'localhost'][$type]['key']["PRIMARY KEY"];
}
$id_field = $id_table . "." . $primary; # articles.id_article -> 'table_id'
// les infos complementaires a passer aux fonctions critere_xxx // les infos complementaires a passer aux fonctions critere_xxx
$infos = array( $infos = array(
'type' => $type, # (articles) 'type' => $type, # (articles)
...@@ -319,8 +326,6 @@ function calculer_criteres ($idb, &$boucles) { ...@@ -319,8 +326,6 @@ function calculer_criteres ($idb, &$boucles) {
); );
if (!is_array($params)) return; // rien a faire
// Boucle hierarchie, supprimer le critere id_article/id_rubrique/id_syndic // Boucle hierarchie, supprimer le critere id_article/id_rubrique/id_syndic
// qui est superfetatoire (mais indique dans la doc) // qui est superfetatoire (mais indique dans la doc)
if ($type == 'hierarchie') { if ($type == 'hierarchie') {
...@@ -418,7 +423,7 @@ function calculer_criteres ($idb, &$boucles) { ...@@ -418,7 +423,7 @@ function calculer_criteres ($idb, &$boucles) {
// Si id_parent, comparer l'id_parent avec l'id_objet // Si id_parent, comparer l'id_parent avec l'id_objet
// de la boucle superieure // de la boucle superieure
if ($val == 'id_parent') if ($val == 'id_parent')
$val = $table_primary[$type]; $val = $primary;
// Si id_enfant, comparer l'id_objet avec l'id_parent // Si id_enfant, comparer l'id_objet avec l'id_parent
// de la boucle superieure // de la boucle superieure
else if ($val == 'id_enfant') else if ($val == 'id_enfant')
...@@ -435,7 +440,7 @@ function calculer_criteres ($idb, &$boucles) { ...@@ -435,7 +440,7 @@ function calculer_criteres ($idb, &$boucles) {
if ($s = relations_externes($type, $col)) { if ($s = relations_externes($type, $col)) {
$col_table = $s; $col_table = $s;
$boucle->from[] = "$col_table AS $col_table"; $boucle->from[] = "$col_table AS $col_table";
$boucle->where[] = "$id_field=$col_table." . $table_primary[$type]; $boucle->where[] = "$id_field=$col_table." . $primary;
$boucle->group = $id_field; $boucle->group = $id_field;
$boucle->lien = true; $boucle->lien = true;
} }
...@@ -451,7 +456,7 @@ function calculer_criteres ($idb, &$boucles) { ...@@ -451,7 +456,7 @@ function calculer_criteres ($idb, &$boucles) {
$col_lien = $type; $col_lien = $type;
$boucle->from[] = "mots_$col_lien AS lien_mot"; $boucle->from[] = "mots_$col_lien AS lien_mot";
$boucle->from[] = 'mots AS mots'; $boucle->from[] = 'mots AS mots';
$boucle->where[] = "$id_field=lien_mot." . $table_primary[$type]; $boucle->where[] = "$id_field=lien_mot." . $primary;
$boucle->where[] = 'lien_mot.id_mot=mots.id_mot'; $boucle->where[] = 'lien_mot.id_mot=mots.id_mot';
$boucle->group = $id_field; $boucle->group = $id_field;
$col_table = 'mots'; $col_table = 'mots';
...@@ -481,7 +486,7 @@ function calculer_criteres ($idb, &$boucles) { ...@@ -481,7 +486,7 @@ function calculer_criteres ($idb, &$boucles) {
// Cas particulier : id_enfant => utiliser la colonne id_objet // Cas particulier : id_enfant => utiliser la colonne id_objet
if ($col == 'id_enfant') if ($col == 'id_enfant')
$col = $table_primary[$type]; $col = $primary;
// Cas particulier : id_secteur = id_rubrique pour certaines tables // Cas particulier : id_secteur = id_rubrique pour certaines tables
if (($type == 'breves' OR $type == 'forums') AND $col == 'id_secteur') if (($type == 'breves' OR $type == 'forums') AND $col == 'id_secteur')
$col = 'id_rubrique'; $col = 'id_rubrique';
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter