amelioration du systeme de filtre, pour gerer au mieux les inconnues

This commit is contained in:
Christophe 2022-04-15 18:12:02 +02:00
parent 8fe52051d3
commit f41d6a6e8b
2 changed files with 11 additions and 9 deletions

View file

@ -23,18 +23,20 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* *
* @return String valeur modifiée ou pas par le filtre * @return String valeur modifiée ou pas par le filtre
*/ */
function gamufiltre($objet, $champ, $valeur) { function gamufiltre($objet, $champ, $ligne) {
$valeur = $ligne[$champ] ?? '';
if (gamuform_objet_autoriser($objet)) { if (gamuform_objet_autoriser($objet)) {
$T = gamuform_recup_tableau_objet($objet); $T = gamuform_recup_tableau_objet($objet);
if (!empty($T)) { if (!empty($T)) {
foreach ($T as $s) { foreach ($T as $s) {
if ( if (
$champ_tab = $s['gamutable']['champ'] ?? $s['options']['nom'] (!empty($s['gamutable']) or !empty($s['options']))
and $champ_tab = $s['gamutable']['champ'] ?? $s['options']['nom']
and $champ_tab === $champ and $champ_tab === $champ
and !empty($s['gamutable']['fonction']) and !empty($s['gamutable']['fonction'])
) { ) {
$filtre = $s['gamutable']['fonction']; $filtre = $s['gamutable']['fonction'];
return $filtre($valeur) ?? ''; return $filtre($valeur ?: $ligne) ?? '';
} }
} }
} }
@ -243,17 +245,17 @@ function gamuform_recup_valeurs($objet, $id_objet = 0):array {
if (gamuform_objet_autoriser($objet)) { if (gamuform_objet_autoriser($objet)) {
$table = table_objet_sql($objet); $table = table_objet_sql($objet);
$id = id_table_objet($objet); $id = id_table_objet($objet);
$s = gamuform_recup_champs_gamutable($objet); // $s = gamuform_recup_champs_gamutable($objet);
$s[] = $id; // $s[] = $id;
if (intval($id_objet)) { if (intval($id_objet)) {
$valeurs = sql_fetsel($s, $table, "$id=".intval($id_objet)); $valeurs = sql_fetsel('*', $table, "$id=".intval($id_objet));
$valeurs['id'] = $valeurs[$id]; $valeurs['id'] = $valeurs[$id];
if (!empty($valeurs)) { if (!empty($valeurs)) {
$r[0] = $valeurs; $r[0] = $valeurs;
} }
} else { } else {
$T = sql_allfetsel($s, $table, 1); $T = sql_allfetsel('*', $table, 1);
if (!empty($T)) { if (!empty($T)) {
foreach ($T as $t) { foreach ($T as $t) {
$t['id'] = $t[$id]; $t['id'] = $t[$id];

View file

@ -57,7 +57,7 @@
"id": #GET{ligne/id}, "id": #GET{ligne/id},
"edit": [(#GET{edit}|json_encode)], "edit": [(#GET{edit}|json_encode)],
<BOUCLE_champsA(DATA){source table,#GET{champs}}> <BOUCLE_champsA(DATA){source table,#GET{champs}}>
[(#VALEUR|json_encode)] : [(#ENV{objet}|gamufiltre{#VALEUR,#GET{ligne/#VALEUR}}|json_encode)], [(#VALEUR|json_encode)] : [(#ENV{objet}|gamufiltre{#VALEUR,#GET{ligne}}|json_encode)],
</BOUCLE_champsA> </BOUCLE_champsA>
"sup": [(#GET{sup}|json_encode)] "sup": [(#GET{sup}|json_encode)]
}, },
@ -65,7 +65,7 @@
"id": #GET{ligne/id}, "id": #GET{ligne/id},
"edit": "", "edit": "",
<BOUCLE_champsB(DATA){source table,#GET{champs}}> <BOUCLE_champsB(DATA){source table,#GET{champs}}>
[(#VALEUR|json_encode)] : [(#ENV{objet}|gamufiltre{#VALEUR,#GET{ligne/#VALEUR}}|textebrut|json_encode)], [(#VALEUR|json_encode)] : [(#ENV{objet}|gamufiltre{#VALEUR,#GET{ligne}}|textebrut|json_encode)],
</BOUCLE_champsB> </BOUCLE_champsB>
"sup":"" "sup":""
} }