Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3424 → Rev 3425

/trunk/widget/modules/saisie2/Saisie2.php
27,10 → 27,15
const WS_SAISIE = 'CelWidgetSaisie';
const WS_UPLOAD = 'CelWidgetUploadImageTemp';
const WS_OBS = 'CelObs';
const WS_COORD = 'CoordSearch';
const LANGUE_DEFAUT = 'fr';
const PROJET_DEFAUT = 'base';
const WS_NOM = 'noms';
const EFLORE_API_VERSION = '0.1';
const WIDGETS_SPECIAUX = ['tb_aupresdemonarbre','tb_streets','tb_lichensgo'];
const SQUELETTES_SPECIAUX = ['arbres','plantes','lichens'];
const WS_OBS_LIST = 'InventoryObservationList';
const WS_IMG_LIST = 'celImage';
private $cel_url_tpl = null;
/** Si spécifié, on ajoute une barre de navigation inter-applications */
private $bar;
104,10 → 109,22
$retour['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
$retour['donnees']['authTpl'] = $this->config['manager']['authTpl']. $projet_dans_url;
$retour['donnees']['mode'] = $mode;
if( isset( $this->parametres['squelette'] ) ) {
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS. $this->parametres['squelette'].'.tpl.html';
} else {
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
$retour['donnees']['langue'] = $langue;
$retour['donnees']['widgets_url'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'],'');
$retour['donnees']['url_ws_obs_list'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS_LIST);
$retour['donnees']['url_ws_cel_imgs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_IMG_LIST) . '/liste-ids?obsId=';
$retour['donnees']['url_ws_cel_img_url'] = str_replace ( '%s.jpg', '{id}XS', $this->config['chemins']['celImgUrlTpl'] );
$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
switch ( $retour['squelette'] ) {
case 'apa':
$retour['donnees']['squelette'] = $this->parametres['projet'];
break;
case 'apaforms':
$retour['donnees']['squelette'] = $this->parametres['squelette'];
break;
default:
$retour['donnees']['squelette'] = $retour['squelette'];
break;
}
$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
} else {
120,14 → 137,22
 
private function executerSaisie() {
$retour = array();
$retour['squelette'] = 'saisie';
$retour['donnees']['general'] = I18n::get('General');
$retour['donnees']['aide'] = I18n::get('Aide');
$retour['donnees']['observateur'] = I18n::get('Observateur');
$retour['donnees']['observation'] = I18n::get('Observation');
$retour['donnees']['image'] = I18n::get('Image');
$retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
$retour['donnees']['resume'] = I18n::get('Resume');
if (in_array($this->parametres['projet'], self::WIDGETS_SPECIAUX) ) {
if (isset($this->parametres['squelette']) && in_array($this->parametres['squelette'], self::SQUELETTES_SPECIAUX) ) {
$retour['squelette'] = 'apaforms';
} else {
$retour['squelette'] = 'apa';
}
} else {
$retour['squelette'] = 'saisie';
$retour['donnees']['general'] = I18n::get('General');
$retour['donnees']['aide'] = I18n::get('Aide');
$retour['donnees']['observateur'] = I18n::get('Observateur');
$retour['donnees']['observation'] = I18n::get('Observation');
$retour['donnees']['image'] = I18n::get('Image');
$retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
$retour['donnees']['resume'] = I18n::get('Resume');
}
$retour['donnees']['widget'] = $this->rechercherProjet();
return $retour;
}
139,16 → 164,26
$tab = array();
$url = $this->config['manager']['celUrlTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
$json = $this->getDao()->consulter($url);
 
if ( $json !== "[]" ) {
$tab = $this->rechercherChampsSupp();
} else {
$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
$json = $this->getDao()->consulter($url);
$estProjetDefini = false;
if (!in_array($this->parametres['projet'], self::WIDGETS_SPECIAUX)){
if ( $json !== "[]") {
$tab = $this->rechercherChampsSupp();
} else {
$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
$json = $this->getDao()->consulter($url);
$estProjetDefini = false;
}
}
$tableau = json_decode($json, true);
$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
if (
isset($this->parametres['squelette']) &&
($this->parametres['squelette'] === 'plantes' || $this->parametres['squelette'] === 'lichens')
) {
$tableau['type_especes'] = 'liste';
if ( $this->parametres['squelette'] === 'lichens' ) {
$tableau['referentiel'] = 'taxref';
}
}
$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
if (isset($tableau['type_especes']) && 'fixe' === $tableau['type_especes']) {
// si on trouve ":" dans referentiel, referentiel = première partie
155,6 → 190,14
$tableau['referentiel'] = (strstr($tableau['referentiel'],':',true)) ?: $tableau['referentiel'];
}
$tableau['milieux'] = ($tableau['milieux'] != '') ? explode(';', $tableau['milieux']) : [];
if(!isset($this->parametres['id-obs'])) {
if (isset($this->parametres['dept']) || isset($this->parametres['commune'],$this->parametres['dept']) || isset($this->parametres['code_insee'])) {
$localisation = $this->traiterParamsLocalisation($this->parametres);
// les paramètres dans l'url peuvent surcharger les données de localisation de la bdd
if ($localisation) $tableau['localisation'] = $localisation;
}
if (isset($tableau['localisation'])) $tableau['localisation'] = $this->traiterLocalisation($tableau['localisation']);
}
if (isset($tableau['motscles'])) {
$tableau['tag-obs'] = $tableau['tag-img'] = $tableau['motscles'];
}
170,7 → 213,7
$projet = $this->parametres['projet'];
$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
$json = $this->getDao()->consulter($url);
$retour = (array) json_decode($json, true);
$retour = json_decode($json, true);
 
foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
 
207,8 → 250,46
return $tableau;
}
 
private function rechercherInfosEspeces( $infos_projets ) { //print_r($infos_projets);exit;
private function traiterLocalisation( $infos_localisation ) {
$infos = explode(';', $infos_localisation);
$tableauTmp = array();
$retour = array();
foreach ($infos as $info) {
$tableauTmp = explode(':', $info);
$retour[$tableauTmp[0]] = $tableauTmp[1];
}
return $retour;
}
 
private function traiterParamsLocalisation( $params ) {
$infos = array();
$tableauTmp = array();
$zoom = '12';
if (isset($params['commune'])) {
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_COORD). '?zone='.$params['commune'].'&code='.$params['dept'];
} else if (isset($params['dept'])) {
// pas trouvé de manière simple de déterminer le centroïde du département
// du coup on retrouve le code insee du chef lieu
$params['code_insee'] = $this->recupererChefLieuDept($params['dept']);
$zoom = '9';
}
// quoi qu'il arrive, s'il est défini, on donne la priorité au code insee (plus précis)
if (isset($params['code_insee'])) {
$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_COORD). '?code='.$params['code_insee'];
}
if(!empty($url)) $json = $this->getDao()->consulter($url);
if(!empty($json)) $infos = json_decode($json, true);
if(!empty($infos)) {
$infos['lat'] = str_replace(',','.',strval(round($infos['lat'],5)));
$infos['lng'] = str_replace(',','.',strval(round($infos['lng'],5)));
return 'latitude:'.$infos['lat'].';longitude:'.$infos['lng'].';zoom:'.$zoom;
} else {
return false;
}
}
 
private function rechercherInfosEspeces( $infos_projets ) {
$retour = array();
$referentiel = $infos_projets['referentiel'];
$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
$retour['url_ws_autocompletion_ns'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );;
343,7 → 424,8
$taxons = array();
$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
$chemin_images = dirname(__FILE__) . self::DS . '..' . self::DS . 'manager' . self::DS . 'squelettes' . self::DS . 'img' . self::DS . 'images_projets' . self::DS;
$chemin_taxon = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . 'especes.';
$nom_fichier = ($this->parametres['squelette'] === 'lichens') ? 'lichens_taxons' : 'especes';
$chemin_taxon = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . $nom_fichier. '.';
 
if ( file_exists( $chemin_taxon . 'csv' ) && is_readable( $chemin_taxon . 'csv' ) ) {
$taxons = $this->decomposerFichierCsv( $chemin_taxon . 'csv' );
350,12 → 432,34
} else if ( file_exists( $chemin_taxon . 'tsv' ) && is_readable( $chemin_taxon . 'tsv' ) ) {
$taxons = $this->decomposerFichierCsv( $chemin_taxon . 'tsv' );
} else {
$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_taxon'.";
$this->debug[] = "Impossible d'ouvrir le fichier '$nom_fichier'.";
}
return $taxons;
}
 
/**
* Lit une liste de taxons depuis un fichier csv ou tsv fourni
*/
protected function recupererChefLieuDept($dept) {
$infosDepts = array();
$code_insee = '';
$chemin_fichier = dirname(__FILE__).self::DS.'squelettes'.self::DS.'dept.csv';
 
if (file_exists($chemin_fichier ) && is_readable($chemin_fichier)) {
$infosDepts = $this->decomposerFichierCsv( $chemin_fichier,"," );
if(!empty($infosDepts) && is_array($infosDepts)) {
foreach ($infosDepts as $key => $infosDept) {
if($dept == $infosDept['dep']) {
return $code_insee = $infosDept['cheflieu'];
}
}
}
} else {
$this->debug[] = "Impossible d'ouvrir le fichier '$nom_fichier'.";
}
}
 
/**
* Découpe un fihcier csv/tsv
*/
protected function decomposerFichierCsv($fichier, $delimiter = "\t"){