Je me lance, sans prétention.
Vos fonctions ou améliorations sont les bienvenues.
/* * ***************************Includes********************************* */
require_once dirname(__FILE__) . '/../../core/php/core.inc.php';
class userFunction {
/* Fonction permettant de récupérer une ancienne valeur et sa date d'une commande info historisée
**
** $_cmd : commande info historisée
** $_position : de 0 à n de la première valeur vers la dernière valeur
** : de -1 à -n de la dernière valeur vers la première valeur
** $_value : valeur -> retour de valeur date -> retour de datetime
**
** Appel de la fonction --> valueDateHistory(#[Ma][Commande Info][Historisée]#,-1,date)
*/
public static function valueDateHistory($_cmd = '', $_position = 0, $_value = 'valeur') {
$_erreur = '||ERREUR||';
try {
$cmdId = cmd::byString($_cmd)->getId();
$cmdName = cmd::byString($_cmd)->getHumanName();
$all = history::all($cmdId);
if (!count($all)) {
log::add('userFunction','warning','Fonction ' . __FUNCTION__ . ' : #A Commande info non historisée');
return $_erreur;
}
log::add('userFunction','info','Fonction ' . __FUNCTION__ . ' : #1 cmd --> ' . $cmdName . ' Position --> ' . $_position . ' Valeur --> ' . $_value . ' Nb d\'enregistrement(s) --> ' . count($all));
$position = $_position + 0;
settype($position, "string");
if ($position !== $_position) {
log::add('userFunction','warning','Fonction ' . __FUNCTION__ . ' : #B Position mal définie');
return $_erreur;
}
if ($_position > count($all) - 1) {
log::add('userFunction','warning','Fonction ' . __FUNCTION__ . ' : #C Position hors limite, il n\'y a que ' . count($all) . ' enregistrement(s)');
return $_erreur;
}
if ($_position < 0) {
$_position = count($all) + $_position;
}
if ($_position < 0) {
log::add('userFunction','warning','Fonction ' . __FUNCTION__ . ' : #D Position hors limite, il n\'y a que ' . count($all) . ' enregistrement(s)');
return $_erreur;
}
$_value = strtolower($_value);
if ($_value == 'valeur') {
$value = $all[$_position]->getValue();
} else {
if ($_value == 'date') {
$value = $all[$_position]->getDatetime();
} else {
log::add('userFunction','warning','Fonction ' . __FUNCTION__ . ' : #E Type de champ mal défini --> choisir valeur ou date');
return $_erreur;
}
}
log::add('userFunction','info','Fonction ' . __FUNCTION__ . ' : #2 cmd --> ' . $cmdName . ' Position --> ' . $_position . ' Valeur --> ' . $_value . ' Nb d\'enregistrement(s) --> ' . count($all) . ' Résultat --> ' . $_value . ' = ' . $value);
return $value;
}
catch (Exception $e) {
// Commande info inexistante
log::add('userFunction','warning','Fonction ' . __FUNCTION__ . ' : #F Commande info ' . $_cmd . ' inexistante --> ' . $e);
return $_erreur;
}
}
}