gamuform/gamuform_fonctions.php
2022-03-31 10:19:47 +02:00

80 lines
1.5 KiB
PHP

<?php
/**
* Fonctions utiles au plugin GamuForm
*
* @plugin GamuForm
* @copyright 2020
* @author tofulm
* @licence GNU/GPL
* @package SPIP\Gamuform\Fonctions
*/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function gamuform_objet_autoriser(string $objet):bool {
if (
!empty($GLOBALS['gamuform_objets'])
and !empty($objet)
and in_array($objet, array_keys($GLOBALS['gamuform_objets']))
) {
return true;
}
return false;
}
function gamuform_nom_objet($objet):string {
$nom = '';
if (gamuform_objet_autoriser($objet)) {
$nom = $GLOBALS['gamuform_objets'][$objet];
}
return $nom;
}
function gamuform_recup_champ($objet, $keys = false) {
$c = [];
if (gamuform_objet_autoriser($objet)) {
$T = $GLOBALS['gamuform_'.$objet];
if (!empty($T)) {
foreach ($T as $s) {
if ($keys) {
$c[] = $s['options']['nom'];
} else {
$c[$s['options']['nom']] = $s['options']['libelle'];
}
}
}
}
return $c;
}
function gamuform_recup_valeurs($objet, $id_objet = 0):array {
$r = [];
if (gamuform_objet_autoriser($objet)) {
$table = table_objet_sql($objet);
$id = id_table_objet($objet);
$s = gamuform_recup_champ($objet, true);
$s[] = $id;
if (intval($id_objet)) {
$valeurs = sql_fetsel($s, $table, "$id=".intval($id_objet));
$valeurs['id'] = $valeurs[$id];
if (!empty($valeurs)) {
$r[0] = $valeurs;
}
} else {
$T = sql_allfetsel($s, $table, 1);
if (!empty($T)) {
foreach ($T as $t) {
$t['id'] = $t[$id];
$r[] = $t;
}
}
}
}
return $r;
}