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 @@
<tr><td>&#35;PETITION</td><td> #PETITION</td></tr>
<tr><td>&#35;POPULARITE</td><td> #POPULARITE</td></tr>
<tr><td>&#35;EXTRA</td><td> #EXTRA</td></tr>
<tr><td>&#35;PARAMETRES_FORUM</td><td> #PARAMETRES_FORUM</td></tr>
</table>
<hr />
<table border='1' width='100%'>
......@@ -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;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;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>{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>
......@@ -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}>
[[g1 (#TITRE)d1 [[g3 (#TITRE) d3] (#TITRE|strtoupper) [g4 (#TITRE) d4]]] (#TITRE|strtoupper) [g5 (#TITRE) d5]][g6 (#TITRE) d7]</td></tr></BOUCLE_a>
</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='') {
}
if (!$t) $t = $r; // pour les tables non Spip
// $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];
if (!$desc) {
include_local("inc-admin.php3");
......
......@@ -134,7 +134,7 @@ function calculer_texte($texte, $id_boucle, &$boucles, $id_mere) {
// remplissant une variable $t0 retourne'e en valeur
//
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];
$type_boucle = $boucle->type_requete;
......@@ -152,7 +152,16 @@ function calculer_boucle($id_boucle, &$boucles) {
if (!function_exists($f)) $f = $f.'_dist'; // definition spip
if (!function_exists($f)) $f = 'boucle_DEFAUT'; // definition par defaut
$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);
......@@ -177,21 +186,17 @@ function calculer_boucle($id_boucle, &$boucles) {
// cas general ({lang_select} sur une table externe)
. 'lang';
// Qui sommes-nous ?
$primary_key = $table_primary[$type_boucle];
// Calculer les invalideurs si c'est une boucle non constante
$constant = ereg("^\(?'[^']*'\)?$",$return);
if ((!$primary_key) || $constant)
if ((!$primary) || $constant)
$invalide = '';
else {
$id_table = $table_des_tables[$type_boucle];
$boucle->select[] = "$id_table.$primary_key";
$boucle->select[] = $id_field;
$invalide = "\n \$Cache['$primary_key']";
if ($primary_key != 'id_forum')
$invalide .= "[\$Pile[\$SP]['$primary_key']] = 1;";
$invalide = "\n \$Cache['$primary']";
if ($primary != 'id_forum')
$invalide .= "[\$Pile[\$SP]['$primary']] = 1;";
else
$invalide .= "[calcul_index_forum(" .
// Retournera 4 [$SP] mais force la demande du champ a MySQL
......@@ -227,7 +232,7 @@ function calculer_boucle($id_boucle, &$boucles) {
if ($boucle->doublons)
$debut .= "\n \$doublons['".$boucle->doublons."'] .= ','. " .
index_pile($id_boucle, $primary_key, $boucles)
index_pile($id_boucle, $primary, $boucles)
. "; // doublons";
// gestion optimale des separateurs et des boucles constantes
......@@ -304,11 +309,11 @@ function calculer_boucle($id_boucle, &$boucles) {
// En absence de champ c'est un decompte :
// on prend la primary pour avoir qqch
// 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(\"".
(($boucle->select) ?
join("\",\n\t\t\"", array_unique($boucle->select)) :
((strlen($id_field) > 1) ? $id_field : '*')) .
$id_field) .
'"), # SELECT
array("' .
join('","', array_unique($boucle->from)) .
......@@ -568,7 +573,7 @@ function calculer_squelette($squelette, $nom, $gram, $sourcefile) {
if ($boucle->type_requete != 'boucle')
{
$descr['id_mere'] = $id;
$res = calculer_criteres($id, $boucles, $descr);
$res = calculer_criteres($id, $boucles);
if (is_array($res)) return $res; # erreur
$boucles[$id]->return =
calculer_liste($boucle->milieu,
......
......@@ -300,14 +300,21 @@ function relations_externes ($type, $col) {
// comme {1,4}, etc.
//
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
$type = $boucle->type_requete; # articles
$params = $boucle->param;
$id_table = $table_des_tables[$type]; # articles -> 'table'
$primary = $table_primary[$type]; # id_article -> 'id'
$id_field = $id_table . "." . $primary; # articles.id_article -> 'table_id'
if (!is_array($params)) return; // rien a faire
$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
$infos = array(
'type' => $type, # (articles)
......@@ -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
// qui est superfetatoire (mais indique dans la doc)
if ($type == 'hierarchie') {
......@@ -418,7 +423,7 @@ function calculer_criteres ($idb, &$boucles) {
// Si id_parent, comparer l'id_parent avec l'id_objet
// de la boucle superieure
if ($val == 'id_parent')
$val = $table_primary[$type];
$val = $primary;
// Si id_enfant, comparer l'id_objet avec l'id_parent
// de la boucle superieure
else if ($val == 'id_enfant')
......@@ -435,7 +440,7 @@ function calculer_criteres ($idb, &$boucles) {
if ($s = relations_externes($type, $col)) {
$col_table = $s;
$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->lien = true;
}
......@@ -451,7 +456,7 @@ function calculer_criteres ($idb, &$boucles) {
$col_lien = $type;
$boucle->from[] = "mots_$col_lien AS lien_mot";
$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->group = $id_field;
$col_table = 'mots';
......@@ -481,7 +486,7 @@ function calculer_criteres ($idb, &$boucles) {
// Cas particulier : id_enfant => utiliser la colonne id_objet
if ($col == 'id_enfant')
$col = $table_primary[$type];
$col = $primary;
// Cas particulier : id_secteur = id_rubrique pour certaines tables
if (($type == 'breves' OR $type == 'forums') AND $col == 'id_secteur')
$col = 'id_rubrique';
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter