32,10 → 32,17 |
* |
*/ |
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(realpath(__FILE__))) . '/lib'); |
require_once('lib/PHPExcel/Classes/PHPExcel.php'); |
|
// 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');*/ |
|
class ExportXLS extends Cel { |
|
private $cache = Array(); |
|
function ExportXLS($config) { |
parent::__construct($config); |
} |
243,7 → 250,7 |
'certitude' => self::GenColInfo('certitude', 'Certitude', 1), |
'phenologie' => self::GenColInfo('phenologie', 'Phénologie', 1), |
|
//'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun') |
'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun') |
//'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v2') |
//'nom-commun' => self::GenColInfo('nom-commun', 'Nom Commun', 1, NULL, 'getNomCommun_v3') |
); |
280,4 → 287,110 |
if(!$date_formatee) return "00/00/0000"; |
return $date_formatee; |
} |
} |
|
|
// 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" ? |
function getNomCommun($obs) { |
$langue = 'fra'; |
list($referentiel) = explode(':', strtolower($obs['nom_referentiel'])); |
if($referentiel == 'bdtfx') $referentiel = 'nvjfl'; |
else return ''; |
|
$cache_id = $referentiel . '-' . $obs['nt'] . '-' . $langue; |
if(isset($this->cache['getNomCommun'][$cache_id])) { |
//debug: error_log("require url_service_nom_attribution: OK ! (pour \"{$obs['nom_ret']}\")"); |
return $this->cache['getNomCommun'][$cache_id]; |
} |
// 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 |
$url = str_replace(Array('{referentiel}', '{valeur}', '{langue}'), |
Array($referentiel, $obs['nt'], $langue), |
$this->config['eflore']['url_service_nom_attribution']) . |
"&retour.champs=num_statut"; |
$noms = @json_decode(file_get_contents($url)); |
if(! $noms) return ''; |
$noms = array_filter((array)($noms->resultat), function($item) { return ($item->num_statut == 1); }); |
$nom = array_pop($noms)->nom_vernaculaire; |
|
// cache |
$this->cache['getNomCommun'][$cache_id] = $nom; |
return $nom; |
} |
|
|
/* 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($this->cache['getNomCommun'][$cache_id])) { |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")"); |
return $this->cache['getNomCommun'][$cache_id]; |
} |
// pas de cache: |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\""); |
|
$data = Array('masque.nt' => $obs['nt'], |
'masque.lg' => $langue, |
'retour.champs' => 'num_statut'); |
$noms = $service->consulter(Array('nvjfl', 'noms-vernaculaires'), $data); |
|
if(! $noms) return ''; |
$noms = array_filter((array)($noms->resultat), function($item) { return ($item->num_statut == 1); }); |
$nom = array_pop($noms)->nom_vernaculaire; |
|
// cache |
$this->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($this->cache['getNomCommun'][$cache_id])) { |
error_log("require NomsVernaculaires.php: OK ! (pour \"{$obs['nom_ret']}\")"); |
return $this->cache['getNomCommun'][$cache_id]; |
} |
// pas de cache: |
error_log("require NomsVernaculaires.php pour \"{$obs['nom_ret']}\""); |
|
$data = Array('masque.nt' => $obs['nt'], |
'masque.lg' => $langue, |
'retour.champs' => 'conseil_emploi'); |
$this->service->initialiserRessourcesEtParametres(Array('nvjfl', 'noms-vernaculaires', 'attributions'), $data); |
try { |
$noms = $this->service->traiterRessources(); |
} catch(Exception $e) { return ''; } |
if(! $noms) return ''; |
$noms = array_filter($noms['resultat'], function($item) { return ($item['num_statut'] == 1); }); |
$nom = array_pop($noms)['nom_vernaculaire']; |
|
// cache |
$this->cache['getNomCommun'][$cache_id] = $nom; |
return $nom; |
} |
|
} |