Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1756 → Rev 1757

/trunk/jrest/lib/FormateurGroupeColonne.php
97,7 → 97,9
* clé: abbrev [machine-name] de la colonne (eg: "espece" ou "mot-clef")
* valeur: des données relative à cette colonne, cf GenColInfo
*
* @TODO: noms communs à part, gestion des champs étendus
* Si la colonne n'utilise pas de fonction de récupération particulière
* (ie: si le champ exportés [ou importé] correspond exactement au champ dans la base de donnée)
* Alors 'abbrev' doit avoir la même valeur que le nom de la colonne dans la table mysql `cel_obs`.
*
*/
static function nomEnsembleVersListeColonnes($groupe_de_champs = 'standard') {
119,54 → 121,136
if(isset($groupe_de_champs['standard'])) {
$colonnes += Array(
'nom_sel' => self::GenColInfo('nom_sel', 'Espèce'),
'nom_sel_nn' => self::GenColInfo('nom_sel_nn', 'Numéro nomenclatural', 0, NULL, NULL, FALSE),
'nom_ret' => self::GenColInfo('nom_ret', 'Nom retenu', 0, NULL, NULL, FALSE),
'nom_ret_nn' => self::GenColInfo('nom_ret_nn', 'Numéro nomenclatural nom retenu', 0, NULL, NULL, FALSE),
'nt' => self::GenColInfo('nt', 'Numéro taxonomique', 0, NULL, NULL, FALSE),
'famille' => self::GenColInfo('famille', 'Famille', 0, NULL, NULL, FALSE),
'nom_referentiel' => self::GenColInfo('nom_referentiel', 'Referentiel taxonomique'),
'zone_geo' => self::GenColInfo('zone_geo', 'Commune'),
'ce_zone_geo' => self::GenColInfo('ce_zone_geo', 'Identifiant Commune', 0, 'convertirCodeZoneGeoVersDepartement'),
'date_observation' => self::GenColInfo('date_observation', 'Date', 0, 'formaterDate'),
'lieudit' => self::GenColInfo('lieudit', 'Lieu-dit'),
'station' => self::GenColInfo('station', 'Station'),
'milieu' => self::GenColInfo('milieu', 'Milieu'),
'commentaire' => self::GenColInfo('commentaire', 'Notes'),
'latitude' => self::GenColInfo('latitude', 'Latitude', 1),
'longitude' => self::GenColInfo('longitude', 'Longitude', 1),
'altitude' => self::GenColInfo('altitude', 'Altitude', 1),
'geodatum' => self::GenColInfo('geodatum', 'Référentiel Géographique', 1, NULL, NULL, FALSE),
'nom_sel' => self::GenColInfo(Array('abbrev' => 'nom_sel',
'nom' => 'Espèce')),
'nom_sel_nn' => self::GenColInfo(Array('abbrev' => 'nom_sel_nn',
'nom' => 'Numéro nomenclatural',
'importable' => FALSE)),
'nom_ret' => self::GenColInfo(Array('abbrev' => 'nom_ret',
'nom' => 'Nom retenu',
'importable' => FALSE)),
'nom_ret_nn' => self::GenColInfo(Array('abbrev' => 'nom_ret_nn',
'nom' => 'Numéro nomenclatural nom retenu',
'importable' => FALSE)),
'nt' => self::GenColInfo(Array('abbrev' => 'nt',
'nom' => 'Numéro taxonomique',
'importable' => FALSE)),
'famille' => self::GenColInfo(Array('abbrev' => 'famille',
'nom' => 'Famille',
'importable' => FALSE)),
'nom_referentiel' => self::GenColInfo(Array('abbrev' => 'nom_referentiel',
'nom' => 'Referentiel taxonomique')),
'zone_geo' => self::GenColInfo(Array('abbrev' => 'zone_geo',
'nom' => 'Commune')),
'ce_zone_geo' => self::GenColInfo(Array('abbrev' => 'ce_zone_geo',
'nom' => 'Identifiant Commune',
'fonction' => 'convertirCodeZoneGeoVersDepartement')),
'date_observation' => self::GenColInfo(Array('abbrev' => 'date_observation',
'nom' => 'Date',
'fonction' => 'formaterDate')),
'lieudit' => self::GenColInfo(Array('abbrev' => 'lieudit',
'nom' => 'Lieu-dit')),
'station' => self::GenColInfo(Array('abbrev' => 'station',
'nom' => 'Station')),
'milieu' => self::GenColInfo(Array('abbrev' => 'milieu',
'nom' => 'Milieu')),
'commentaire' => self::GenColInfo(Array('abbrev' => 'commentaire',
'nom' => 'Notes')),
'latitude' => self::GenColInfo(Array('abbrev' => 'latitude',
'nom' => 'Latitude',
'extra' => 1,
'fonction' => 'trim0')),
'longitude' => self::GenColInfo(Array('abbrev' => 'longitude',
'nom' => 'Longitude',
'extra' => 1,
'fonction' => 'trim0')),
'altitude' => self::GenColInfo(Array('abbrev' => 'altitude',
'nom' => 'Altitude',
'extra' => 1,
'fonction' => 'trim0')),
'geodatum' => self::GenColInfo(Array('abbrev' => 'geodatum',
'nom' => 'Référentiel Géographique',
'extra' => 1,
'importable' => FALSE)),
);
}
if(isset($groupe_de_champs['avance'])) {
$colonnes += array(
// TODO: importable = FALSE car pas de merge de données importées
'ordre' => self::GenColInfo('ordre', 'Ordre', 1, NULL, NULL, FALSE),
'id_observation' => self::GenColInfo('id_observation', 'Identifiant', 1, NULL, NULL, FALSE),
// TODO: importable = FALSE car pas de merge de données importées
'ordre' => self::GenColInfo(Array('abbrev' => 'ordre',
'nom' => 'Ordre',
'extra' => 1,
'importable' => FALSE)),
'id_observation' => self::GenColInfo(Array('abbrev' => 'id_observation',
'nom' => 'Identifiant',
'extra' => 1,
'importable' => FALSE)),
 
'mots_cles_texte' => self::GenColInfo('mots_cles_texte', 'Mots Clés', 1),
'date_creation' => self::GenColInfo('date_creation', 'Date Création', 1, NULL, NULL, FALSE),
'date_modification' => self::GenColInfo('date_modification', 'Date Modification', 1, NULL, NULL, FALSE),
'mots_cles_texte' => self::GenColInfo(Array('abbrev' => 'mots_cles_texte',
'nom' => 'Mots Clés',
'extra' => 1)),
'date_creation' => self::GenColInfo(Array('abbrev' => 'date_creation',
'nom' => 'Date Création',
'extra' => 1,
'importable' => FALSE)),
'date_modification' => self::GenColInfo(Array('abbrev' => 'date_modification',
'nom' => 'Date Modification',
'extra' => 1,
'importable' => FALSE)),
 
// rappel transmission = 1, signifie simplement "public"
// des données importées peuvent être d'emblée "publiques"
// "importable" = TRUE
'transmission' => self::GenColInfo('transmission', 'Transmis', 1),
'date_transmission' => self::GenColInfo('date_transmission', 'Date Transmission', 1, NULL, NULL, FALSE),
'abondance' => self::GenColInfo('abondance', 'Abondance', 1),
'certitude' => self::GenColInfo('certitude', 'Certitude', 1),
'phenologie' => self::GenColInfo('phenologie', 'Phénologie', 1),
// rappel transmission = 1, signifie simplement "public"
// des données importées peuvent être d'emblée "publiques"
// "importable" = TRUE
'transmission' => self::GenColInfo(Array('abbrev' => 'transmission',
'nom' => 'Transmis',
'extra' => 1,
'fonction' => 'boolOuiNon')),
'date_transmission' => self::GenColInfo(Array('abbrev' => 'date_transmission',
'nom' => 'Date Transmission',
'extra' => 1,
'importable' => FALSE)),
'abondance' => self::GenColInfo(Array('abbrev' => 'abondance',
'nom' => 'Abondance',
'extra' => 1)),
'certitude' => self::GenColInfo(Array('abbrev' => 'certitude',
'nom' => 'Certitude',
'extra' => 1)),
'phenologie' => self::GenColInfo(Array('abbrev' => 'phenologie',
'nom' => 'Phénologie',
'extra' => 1)),
// XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
// cf ExportXLS::traiterLigneObservation()
'images' => self::GenColInfo(Array('abbrev' => 'images',
'nom' => 'Image(s)',
'extra' => 1,
'fonction_data' => NULL /* cas particulier 'getImages' */,
'importable' => TRUE,
//'preload' => array(__CLASS__, 'getImages_preload')//TODO
)),
 
// XXX: getImages() dépend du contexte de Cel, et doit être appelée comme cas particulier
// cf ExportXLS::traiterLigneObservation()
'images' => self::GenColInfo('images', 'Image(s)', 1, NULL, NULL /* cas particulier 'getImages' */, TRUE),
/* 'nom_commun' => self::GenColInfo(Array('abbrev' => 'nom_commun',
'nom' => 'Nom Commun',
'extra' => 1,
'fonction_data' => 'getNomCommun',
'importable' => FALSE),
 
/* 'nom_commun' => self::GenColInfo('nom_commun', 'Nom Commun', 1, NULL, 'getNomCommun', FALSE),
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2'),
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3'), */
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, NULL /* cas particu 'getNomCommun_v4' */, TRUE, array(__CLASS__, 'getNomCommun_preload')),
'nom-commun' => self::GenColInfo(Array('abbrev' => 'nom-commun',
'nom' => 'Nom Commun',
'extra' => 1,
'fonction_data' => 'getNomCommun_v2'),
 
'nom-commun' => self::GenColInfo(Array('abbrev' => 'nom-commun',
'nom' => 'Nom Commun',
'extra' => 1,
'fonction_data' => 'getNomCommun_v3'),
'importable' => FALSE), */
'nom-commun' => self::GenColInfo(Array('abbrev' => 'nom-commun',
'nom' => 'Nom Commun',
'extra' => 1,
'fonction_data' => NULL /* cas particu 'getNomCommun_v4' */,
'preload' => array(__CLASS__, 'getNomCommun_preload')))
);
}
 
173,7 → 257,12
if(isset($groupe_de_champs['baseflor'])) {
$colonnes += array(
// champ dynamique
'baseflor' => self::GenColInfo('baseflor', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'baseflor_preload'), array(__CLASS__, 'baseflor_ligne')),
'baseflor' => self::GenColInfo(Array('abbrev' => 'baseflor',
'nom' => '',
'extra' => 1,
'importable' => FALSE,
'preload' => array(__CLASS__, 'baseflor_preload'),
'dyna' => array(__CLASS__, 'baseflor_ligne'))),
);
}
 
180,10 → 269,14
if(isset($groupe_de_champs['etendu'])) {
$colonnes += array(
// champ dynamique
'etendu' => self::GenColInfo('etendu', '', 1, NULL, NULL, FALSE, array(__CLASS__, 'champsEtendus_preload'), array(__CLASS__, 'champsEtendus_ligne')),
'etendu' => self::GenColInfo(Array('abbrev' => 'etendu',
'nom' => '',
'extra' => 1,
'importable' => FALSE,
'preload' => array(__CLASS__, 'champsEtendus_preload'),
'dyna' => array(__CLASS__, 'champsEtendus_ligne'))),
);
}
 
return $colonnes;
}
 
206,7 → 299,7
}
 
public static function getLigneObservation(&$obs, &$colonnes, $cel = false) {
 
$ligne_formatee = array();
foreach($colonnes as $abbrev => $colonne) {
$valeur = null;
302,16 → 395,17
* La fonction doit TOUJOURS alterer la ligne en lui ajoutant une nombre CONSTANT d'éléments (NULL ou non)
* La fonction doit prendre comme arguments ($cel, $obs, &$ligne_formatee)
*/
static function GenColInfo($abbrev, $nom, $is_extra = 0, $fonction = NULL, $fonction_data = NULL, $importable = TRUE, $preload = NULL, $fonction_dynamique = NULL) {
return Array('abbrev' => $abbrev,
'nom' => $nom,
'extra' => $is_extra,
'fonction' => $fonction,
'fonction_data' => $fonction_data,
'importable' => $importable,
'preload' => $preload,
'dyna' => $fonction_dynamique,
);
static function GenColInfo($args) {
$default = Array('abbrev' => NULL,
'nom' => NULL,
'extra' => 0,
'fonction' => NULL,
'fonction_data' => NULL,
'importable' => TRUE,
'preload' => NULL,
'dyna' => NULL);
$ret = array_intersect_key($args, $default);
return array_merge($default, $ret);
}
static function formaterDate($date_heure_mysql) {
332,17 → 426,18
if(!$date_formatee) return "00/00/0000";
return $date_formatee;
}
 
static function getImages($obs, $id_utilisateur, $cel) {
if(! $id_utilisateur) return NULL;
$rec = $cel->requeter(
sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') FROM cel_images i"
sprintf("SELECT GROUP_CONCAT(nom_original SEPARATOR '%s') AS i FROM cel_images i"
." LEFT JOIN cel_obs_images oi ON (i.id_image = oi.id_image)"
." LEFT JOIN cel_obs o ON (oi.id_observation = o.id_observation)"
." WHERE ce_utilisateur = %d",
." WHERE o.ce_utilisateur = %d AND o.id_observation = %d LIMIT 1",
SEPARATEUR_IMAGES,
$id_utilisateur));
return $rec ? array_pop($rec) : NULL;
$id_utilisateur,
$obs['id_observation']));
return $rec ? $rec[0]['i'] : NULL;
}
public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) {
353,6 → 448,14
return $code_departement;
}
 
public static function trim0($lonlat) {
return trim(trim($lonlat, "0"), ".");
}
 
public static function boolOuiNon($transmission) {
return $transmission ? 'oui' : '';
}
public static function estUnCodeInseeDepartement($code_a_tester) {
return preg_match('/^INSEE-C:[0-9]{5}/',$code_a_tester);
514,9 → 617,12
list($referentiel) = explode(':', strtolower($obs['nom_referentiel']));
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue;
 
if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
// XXX: problème de valeurs NULL ?
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
// cache:
if(isset($cache['getNomCommun'])) {
if(isset(self::$cache['getNomCommun'][$cache_id])) return self::$cache['getNomCommun'][$cache_id];
// XXX: problème de valeurs NULL ?
if(array_key_exists($cache_id, self::$cache['getNomCommun'])) return self::$cache['getNomCommun'][$cache_id];
}
 
// pas de cache:
$nom = $cel->executerRequete(sprintf("SELECT nom_commun FROM cel_references " .