119 lines
2.3 KiB
PHP
119 lines
2.3 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;
|
|
}
|
|
|
|
/**
|
|
* recuperation du tableau des saisies d'un objet
|
|
* dans : gamuform/mon_objet.php
|
|
*
|
|
* @param string $objet
|
|
*
|
|
* @return array
|
|
*
|
|
*/
|
|
function gamuform_recup_saisies(string $objet):array {
|
|
$f = charger_fonction($objet, 'gamuform', true);
|
|
if (!$f) {
|
|
return [];
|
|
}
|
|
$T = $f();
|
|
if (empty($T)) {
|
|
$T = [];
|
|
}
|
|
$T = array_filter($T, function($d){
|
|
return !empty($d['saisie']);
|
|
});
|
|
return $T;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* recuperation des champs de l'objet que l'on veut traiter
|
|
*
|
|
* @param String $objet
|
|
* @param Bool $keys (optional) le type de sortie que l'on souhaite
|
|
*
|
|
* @return Array
|
|
*/
|
|
function gamuform_recup_champ(string $objet, bool $keys = false):array {
|
|
$c = [];
|
|
|
|
if (gamuform_objet_autoriser($objet)) {
|
|
$T = gamuform_recup_saisies($objet);
|
|
|
|
if (!empty($T)) {
|
|
foreach ($T as $s) {
|
|
if ($keys) {
|
|
$c[] = $s['options']['nom'];
|
|
} else {
|
|
$c[$s['options']['nom']] = $s['options']['libelle'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $c;
|
|
}
|
|
|
|
/**
|
|
* recuperation de(s) ligne(s) de l'objet
|
|
*
|
|
* @param String $objet
|
|
* @param String $id_objet (optional)
|
|
*
|
|
* @return array
|
|
*/
|
|
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;
|
|
}
|