122,7 → 122,7 |
if(!$groupe_de_champs) return NULL; |
|
$colonnes = Array(); |
|
|
if(isset($groupe_de_champs['standard'])) { |
$colonnes += Array( |
'nom_sel' => self::GenColInfo(Array('abbrev' => 'nom_sel', |
177,7 → 177,7 |
'importable' => FALSE)), |
); |
} |
|
|
if(isset($groupe_de_champs['avance'])) { |
$colonnes += array( |
// TODO: importable = FALSE car pas de merge de données importées |
222,7 → 222,7 |
'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', |
302,12 → 302,12 |
} |
return $result; |
} |
|
|
public static function getIntitulesColonnes($colonnes) { |
// array_filter pour supprimer les colonnes "dynamique" n'ayant pas défini $nom (cf GenColInfo()) |
return array_filter(array_map(array('FormateurGroupeColonne', 'retournerNomItem'), $colonnes)); |
} |
|
|
public static function retournerNomItem(&$item) { |
return $item['nom']; |
} |
317,10 → 317,10 |
foreach($colonnes as $abbrev => $colonne) { |
$valeur = null; |
if($colonne['extra'] == 2 || ! is_null($colonne['dyna'])) continue; |
|
|
// valeur directe depuis cel_obs ? |
if(isset($obs[$abbrev])) $valeur = $obs[$abbrev]; |
|
|
// pré-processeur des champs |
if(function_exists($colonne['fonction'])) { |
$valeur = $colonne['fonction']($valeur); |
336,7 → 336,7 |
elseif(method_exists(__CLASS__, $colonne['fonction_data'])) { |
$valeur = call_user_func(array(__CLASS__, $colonne['fonction_data']), $obs); |
} |
|
|
// // cette section devrait être vide: |
// // cas particuliers ingérable avec l'architecture actuelle: |
if(false && $abbrev == 'date_observation' && $valeur == "0000-00-00") { |
349,11 → 349,11 |
if($abbrev == 'nom-commun') { |
$valeur = FormateurGroupeColonne::getNomCommun_v4($obs); |
} |
|
|
if($valeur == null) { |
$valeur = ""; |
} |
|
|
// // fin de section "cas particuliers" |
$ligne_formatee[] = $valeur; |
} |
369,20 → 369,20 |
|
return $ligne_formatee; |
} |
|
|
/* |
* Wrapper générant un tableau associatif: |
* Ne pas changer les valeurs par défaut du prototype sans réflexion sur l'implication pour nomEnsembleVersListeColonnes() |
|
|
* @param $abbrev (obligatoire): nom court de colonne, largement utilisé lors de l'import. |
* En effet chaque ligne importée est accessible à l'aide du `define` de $abbrev en majuscule, préfixé de "C_" |
* Exemple: $ligne[C_LONGITUDE] pour "longitude". |
* cf: ImportXLS::detectionEntete() |
|
|
* @param $nom (obligatoire): nom complet de colonne (utilisé pour la ligne d'en-tête) |
* Les définition de champs dynamique (correspondant à de multiples colonnes) doivent laisser cette valeur |
* vide afin de ne pas créer une colonne supplémentaire erronée. |
|
|
* @param $is_extra: |
* Si 0, la colonne est une colonne standard |
* Si 1, la colonne est extra [le plus souvent générée automatiquement] |
389,14 → 389,14 |
* (auquel cas une bordure bleue entoure son nom dans la ligne d'entête) |
* Si 2, la colonne n'est pas traité à l'export, mais une définition peut lui être donnée |
* qui pourra être utilisée à l'import, exemple: "image" |
|
|
* @param $fonction (optionnel): un nom d'un fonction de préprocessing |
* $fonction doit prendre comme seul argument la valeur d'origine et retourner la valeur transformée |
|
|
* @param $fonction_data (optionnel): une *méthode* d'obtention de donnée |
* $fonction_data doit prendre comme premier argument le tableau des champs de l'enregistrement existant |
* $fonction_data doit retourner une valeur |
|
|
* @param $importable (optionnel): défini si la colonne est traitée (ou absolument ignorée par PHPExcel) lors de |
* l'import. |
|
420,7 → 420,7 |
$ret = array_intersect_key($args, $default); |
return array_merge($default, $ret); |
} |
|
|
static function formaterDate($date_heure_mysql) { |
//return ""; |
if (!$date_heure_mysql || $date_heure_mysql == "0000-00-00 00:00:00") return NULL; |
480,13 → 480,13 |
$obs['id_observation'])); |
return $rec ? $rec[0]['i'] : NULL; |
} |
|
public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) { |
|
public static function convertirCodeZoneGeoVersDepartement($code_zone_geo) { |
$code_departement = ''; |
if(self::estUnCodeInseeDepartement($code_zone_geo)) { |
$code_departement = substr(ltrim($code_zone_geo,'INSEE-C:'),0,2); |
} |
|
|
return $code_departement; |
} |
|
497,12 → 497,12 |
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); |
} |
|
|
|
|
// TODO: référentiel ne devrait pas être généré au moment d'un Config::get, |
// comme dans Config::get('nomsVernaRechercheLimiteeTpl') |
// Par exemple, la variable pour "nva" ? |
511,7 → 511,7 |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel'])); |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl'; |
else return ''; |
|
|
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue; |
if(isset(self::$cache['getNomCommun'][$cache_id])) { |
//debug: error_log("require url_service_nom_attribution: OK ! (pour \"{$obs['nom_ret']}\")"); |
519,7 → 519,7 |
} |
// pas de cache: |
//debug: error_log("require url_service_nom_attribution pour \"{$obs['nom_ret']}\""); |
|
|
// pour bdtfx: |
// /service:eflore:0.1/nvjfl/noms-vernaculaires/attributions?masque.nt=X&masque.lg=fra&retour.champs=num_statut |
// /projet/services/modules/0.1/nvjfl/NomsVernaculaires.php |
531,12 → 531,12 |
if(! $noms) return ''; |
$noms = array_filter((array)($noms->resultat), array($this, retournerNumStatutUn)); // XXX: php 5.3 |
$nom = array_pop($noms)->nom_vernaculaire; |
|
|
// cache |
self::$cache['getNomCommun'][$cache_id] = $nom; |
return $nom; |
} |
|
|
private function retournerNumStatutUn(&$item) { |
return ($item->num_statut == 1); |
} |
544,24 → 544,24 |
private function retournerNumStatutUnArr(&$item) { |
return ($item['num_statut'] == 1); |
} |
|
|
// si getNomCommun_v2 ou getNomCommun_v3 sont utilisés |
/* require_once('/home/raphael/eflore/framework/framework/Framework.php'); |
Framework::setCheminAppli("/home/raphael/eflore/projets/services/index.php"); |
Framework::setInfoAppli(Config::get('info')); |
require_once('/home/raphael/eflore/projets/services/modules/0.1/Projets.php');*/ |
|
|
/* Tente de bootstraper le framework au plus court et d'initialiser une instance de |
NomsVernaculaires pour obtenir le nom commun */ |
function getNomCommun_v2($obs) { |
static $service; |
$service = new Projets(); |
|
|
$langue = 'fra'; |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel'])); |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl'; |
else return ''; |
|
|
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue; |
if(isset(self::$cache['getNomCommun'][$cache_id])) { |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")"); |
569,33 → 569,33 |
} |
// pas de cache: |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\""); |
|
|
$donnees = Array('masque.nt' => $obs['nt'], |
'masque.lg' => $langue, |
'retour.champs' => 'num_statut'); |
$noms = $service->consulter(Array('nvjfl', 'noms-vernaculaires'), $donnees); |
|
|
if(! $noms) return ''; |
$noms = array_filter((array)($noms->resultat), array($this, retournerNumStatutUn)); // XXX: php 5.3 |
$nom = array_pop($noms)->nom_vernaculaire; |
|
|
// cache |
self::$cache['getNomCommun'][$cache_id] = $nom; |
return $nom; |
} |
|
|
|
|
/* Effectue un bootstraping plus sage que ci-dessus, mais le gain d'efficacité |
n'est pas aussi retentissant qu'espéré */ |
static $service; |
function getNomCommun_v3($obs) { |
if(! $this->service) $this->service = new Projets(); |
|
|
$langue = 'fra'; |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel'])); |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl'; |
else return ''; |
|
|
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue; |
if(isset(self::$cache['getNomCommun'][$cache_id])) { |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")"); |
603,7 → 603,7 |
} |
// pas de cache: |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\""); |
|
|
$donnees = Array('masque.nt' => $obs['nt'], |
'masque.lg' => $langue, |
'retour.champs' => 'conseil_emploi'); |
610,7 → 610,7 |
$this->service->initialiserRessourcesEtParametres(Array('nvjfl', 'noms-vernaculaires', 'attributions'), $donnees); |
try { |
$noms = $this->service->traiterRessources(); |
} catch(Exception $e) { |
} catch(Exception $e) { |
return ''; |
} |
if(! $noms) return ''; |
617,7 → 617,7 |
$noms = array_filter($noms['resultat'], array($this, retournerNumStatutUnArr)); // XXX: php 5.3 |
$premier_nom = array_pop($noms); |
$nom = $premier_nom['nom_vernaculaire']; |
|
|
// cache |
self::$cache['getNomCommun'][$cache_id] = $nom; |
return $nom; |
642,14 → 642,14 |
} |
|
static function referenceTableExiste() { |
if(!self::$is_table) { |
if (!self::$is_table) { |
// une seule fois |
if(! Cel::db()->executerRequete("SHOW TABLES LIKE 'cel_references'", Cel::SQL_RETOUR_LIGNE)) return FALSE; |
if (! Cel::db()->requeterLigne("SHOW TABLES LIKE 'cel_references'")) return FALSE; |
self::$is_table = TRUE; |
} |
return TRUE; |
} |
|
|
static function getNomCommun_v4($obs) { |
if(! $obs['nt']) return NULL; |
if(! self::referenceTableExiste()) return NULL; |
666,11 → 666,10 |
} |
|
// pas de cache: |
$nom = Cel::db()->executerRequete(sprintf("SELECT nom_commun FROM cel_references " . |
$nom = Cel::db()->requeterLigne(sprintf("SELECT nom_commun FROM cel_references " . |
"WHERE referentiel = '%s' AND num_taxon = %d LIMIT 1", |
$referentiel, |
$obs['nt']), |
Cel::SQL_RETOUR_LIGNE); |
$obs['nt'])); |
|
if(! $nom) return NULL; |
$nom = $nom["nom_commun"]; |
705,8 → 704,8 |
|
return NULL; |
} |
|
|
|
static function baseflor_ligne($obs, &$ligne) { |
if(! $obs['nom_ret_nn']) { |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL)); |
729,12 → 728,11 |
} |
|
// pas de cache: |
$data = Cel::db()->executerRequete(sprintf("SELECT %s FROM cel_references " . |
$data = Cel::db()->requeterLigne(sprintf("SELECT %s FROM cel_references " . |
"WHERE referentiel = '%s' AND num_nom_retenu = %d LIMIT 1", |
implode(', ', array_keys(self::$baseflor_col)), |
$referentiel, |
$obs['nom_ret_nn']), |
Cel::SQL_RETOUR_LIGNE); |
$obs['nom_ret_nn'])); |
|
if(! $data) { |
$ligne = array_merge($ligne, array_fill(0, count(self::$baseflor_col), NULL)); |
808,7 → 806,7 |
|
foreach(self::$cache['champsEtendus']['header'] as $colonne) { |
if(!isset($ligne_etendue_aplatie[$colonne])) { |
$ligne_etendue_fmt[$colonne] = ''; |
$ligne_etendue_fmt[$colonne] = ''; |
} else { |
$ligne_etendue_fmt[$colonne] = $ligne_etendue_aplatie[$colonne]; |
} |