Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

No changes between revisions

Regard whitespace Rev 973 → Rev 974

/tags/v5.2-alpage/nettoyerBdd.sh
New file
0,0 → 1,67
#!/bin/bash
##############################################################################################################
# But : Script supprimant toutes les tables de la base de données eFlore.
# Auteur : Jean-Pascal Milcent <jpm@tela-botanica.org> (translate bat file to shell script)
# License : GPL v3
# Création : 15 avril 2013
# Version: 0.1
# 2013-04-15 - Création
# $Id$
##############################################################################################################
# Constante
APPDIR_ABSOLU=`pwd`;
#
CHEMIN_PHP="/opt/lampp/bin"
CHEMIN_TBF_CLI="$APPDIR_ABSOLU/scripts"
MEMORY_LIMIT="3500M"
echo -e "\033[31m`tput blink`ATTENTION :`tput sgr0` Nécessite la création préalable de la base de données \033[31mtb_eflore\033[00m"
echo "Nettoyage et chargement en cours...";
# BASEFLORE : doit être placé apèrs BDTFX (dépendance !)
echo "BASEVEG :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php baseveg -a supprimerTous
echo "BDNT :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdnt -a supprimerTous
echo "BDTFX :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdtfx -a supprimerTous
echo "BASEFLOR :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php baseflor -a supprimerTous
echo "BDTXA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdtxa -a supprimerTous
echo "BIBLIO_BOTA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php biblio_bota -a supprimerTous
# echo "BONNIER :";
# Pas encore utilisé !
echo "CHORODEP :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php chorodep -a supprimerTous
echo "COSTE :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php coste -a supprimerTous
echo "EFLORE :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php eflore -a supprimerTous
# echo "FOURNIER :";
# Pas encore utilisé !
echo "INSEE-D :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php insee_d -a supprimerTous
echo "ISO-3166-1 :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php iso_3166_1 -a supprimerTous
echo "ISO-639-1 :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php iso_639_1 -a supprimerTous
echo "NVJFL :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nvjfl -a supprimerTous
echo "NVPS :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nvps -a supprimerTous
echo "NVA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nva -a supprimerTous
echo "PHOTOFLORA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php photoflora -a supprimerTous
# echo "PROMETHEUS :";
# Ontologie botanique.
# Pas encore utilisé !
echo "SPTB :";
# Statut de protection Tela Botanica
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php sptb -a supprimerTous
echo "CEL :";
echo -e "\033[31m`tput blink`ATTENTION :`tput sgr0` Nécessite la création préalable de la base de données \033[31mtb_cel\033[00m"
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php cel -a supprimerTous
echo "TAPIRLINK :";
echo -e "\033[31m`tput blink`ATTENTION :`tput sgr0` Nécessite la création préalable de la base de données \033[31mtb_hit_indexation\033[00m"
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php tapirlink -a supprimerTous
Property changes:
Added: svn:executable
+*
\ No newline at end of property
Added: svn:eol-style
+native
\ No newline at end of property
/tags/v5.2-alpage/initialiserBdd.sh
New file
0,0 → 1,91
#!/bin/bash
##############################################################################################################
# But : Script permettant d'initialiser en une seule commande l'ensemble de la base de données eFlore.
# Auteur : Jean-Pascal Milcent <jpm@tela-botanica.org> (translate bat file to shell script)
# Exemple : /opt/lampp/bin/php -d memory_limit=3500M ./cli.php bdtxa -a supprimerTous
# License : GPL v3
# Création : 07 decembre 2011
# Version: 0.1
# 2011-12-07 - Création
# $Id$
##############################################################################################################
# Constante
APPDIR_ABSOLU=`pwd`;
#
CHEMIN_PHP="/opt/lampp/bin"
CHEMIN_TBF_CLI="$APPDIR_ABSOLU/scripts"
MEMORY_LIMIT="3500M"
echo -e "\033[31m`tput blink`ATTENTION :`tput sgr0` Nécessite la création préalable de la base de données \033[31mtb_eflore\033[00m"
echo "Nettoyage et chargement en cours...";
# BASEFLORE : doit être placé apèrs BDTFX (dépendance !)
echo "BASEVEG :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php baseveg -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php baseveg -a chargerTous
echo "BDNT :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdnt -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdnt -a chargerTous
echo "BDTFX :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdtfx -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdtfx -a chargerTous
echo "BASEFLOR :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php baseflor -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php baseflor -a chargerTous
echo "BDTXA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdtxa -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php bdtxa -a chargerTous
echo "BIBLIO_BOTA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php biblio_bota -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php biblio_bota -a chargerTous
# echo "BONNIER :";
# Pas encore utilisé !
echo "CHORODEP :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php chorodep -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php chorodep -a chargerTous
echo "COSTE :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php coste -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php coste -a chargerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php coste -a chargerTxt
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php coste -a chargerIndex
echo "EFLORE :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php eflore -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php eflore -a chargerTous
# echo "FOURNIER :";
# Pas encore utilisé !
echo "INSEE-D :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php insee_d -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php insee_d -a chargerTous
echo "ISO-3166-1 :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php iso_3166_1 -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php iso_3166_1 -a chargerTous
echo "ISO-639-1 :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php iso_639_1 -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php iso_639_1 -a chargerTous
echo "NVJFL :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nvjfl -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nvjfl -a chargerTous
echo "NVPS :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nvps -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nvps -a chargerTous
echo "NVA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nva -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php nva -a chargerTous
echo "PHOTOFLORA :";
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php photoflora -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php photoflora -a chargerTous
# echo "PROMETHEUS :";
# Ontologie botanique.
# Pas encore utilisé !
echo "SPTB :";
# Statut de protection Tela Botanica
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php sptb -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php sptb -a chargerTous
echo "CEL :";
echo -e "\033[31m`tput blink`ATTENTION :`tput sgr0` Nécessite la création préalable de la base de données \033[31mtb_cel\033[00m"
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php cel -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php cel -a chargerTous
echo "TAPIRLINK :";
echo -e "\033[31m`tput blink`ATTENTION :`tput sgr0` Nécessite la création préalable de la base de données \033[31mtb_hit_indexation\033[00m"
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php tapirlink -a supprimerTous
$CHEMIN_PHP/php -d memory_limit=$MEMORY_LIMIT $CHEMIN_TBF_CLI/cli.php tapirlink -a chargerTous
 
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
Added: svn:eol-style
+native
\ No newline at end of property
/tags/v5.2-alpage/livraison.sh
New file
0,0 → 1,21
#!/bin/bash
##############################################################################################################
# But : Script permettant d'initialiser en une seule commande l'ensemble de la base de données eFlore.
# Auteur : Jean-Pascal Milcent <jpm@tela-botanica.org> (translate bat file to shell script)
# License : GPL v3
# Création : 07 decembre 2011
# Version: 0.1
# 2011-12-07 - Création
# $Id$
##############################################################################################################
 
# ATTENTION NE PAS UTILISER !!!
 
# compresser les services en excluant les fichiers svn et les fichiers de config et framework
#tar cvzf services.tar.gz services/ --exclude=".svn" --exclude="*.ini" --exclude="framework.php" --exclude="*.sh"
# envoyer sur tela
#scp services.tar.gz root@tela-botanica.org:/home/telabotap/www/eflore-test/.
 
# se connecter sur tela botanica en ssh et effectuer le déploiement
#ssh root@tela-botanica.org "cd /home/telabotap/www/eflore-test/; cd services; tar cvzf ../backup/services.tar.gz .; cd ../; rm -Rf services; tar xvzf services.tar.gz; cd services; cp ../configurations/services/* . -R; chown #telabotap:users /home/telabotap/www/eflore-test/services -R; chmod 755 /home/telabotap/www/eflore-test/services -R; exit";
#echo "Done !"
Property changes:
Added: svn:executable
+*
\ No newline at end of property
Added: svn:eol-style
+native
\ No newline at end of property
/tags/v5.2-alpage/chargerDonnees.sh
New file
0,0 → 1,50
#!/bin/bash
##############################################################################################################
# But : téléchargement automatique en local des données des projets depuis le serveur de Tela Botanica par ftp
# Auteur : Jean-Pascal Milcent <jpm@tela-botanica.org> (translate bat file to shell script)
# License : GPL v3
# Création : 07 decembre 2011
# Version: 0.1
# 2011-12-07 - Création
# $Id$
##############################################################################################################
# Constante
NBREPARAM=$#
APPDIR_ABSOLU=`pwd`;
DOSSIER_LOCAL="$APPDIR_ABSOLU/donnees/"
DOSSIER_DISTANT="/www/eflore/donnees/"
# Aide
E_OPTERR=65
if [ "$1" = '--help' ]
then # Le script a besoin d'au moins un argument sur la ligne de commande
echo "Usage $0 -[parameters -u, -p ]"
echo "Paramétres : "
echo " -h: indiquer l'hote ftp"
echo " -u: indiquer le nom de l'utilisateur ftp"
echo " -p: indiquer le mot de passe de l'utilisateur ftp"
exit $E_OPTERR
fi
 
# Récupération des paramètres et des options de la ligne de commande
TEMP=`getopt -o u:p:h: -l help: -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$TEMP"
while [ ! -z "$1" ] ; do
#echo $1" # "$2
case "$1" in
-h) HOST=$2;;
-u) FTP_USER=$2;;
-p) FTP_PASSWD=$2;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
shift 2
done
 
# Transfert sur le serveur par FTP
if [ $NBREPARAM -eq 0 ]; then
echo "Pas de transfert sur le serveur. Utiliser --help pour voir les options de transfert."
else
echo "Téléchargement en cours :";
lftp ftp://$FTP_USER:$FTP_PASSWD@$HOST -e "set ftp:passive off; mirror -e --no-symlinks -x '.*cel\/images\/.*' -x '.*osm\/.*' -x '.*plantscan\/.*' -x '.*coste\/cles\/.*' -x '.*coste\/descriptions\/.*' -x '.*coste\/images\/.*' -x '.*coste\/ressources\/.*' $DOSSIER_DISTANT $DOSSIER_LOCAL ; quit"
fi;
Property changes:
Added: svn:executable
+*
\ No newline at end of property
Added: svn:eol-style
+native
\ No newline at end of property
/tags/v5.2-alpage/services/modules/0.1/baseflor/GraphiquesTaxonsSup.php
New file
0,0 → 1,146
<?php
/**
* Classe GraphiquesTaxonsSup.php transforme les données écologiques de la table baseflor_rang_sup_ecologie
* en graphique svg
* graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
*
*
* @package eflore-projets
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
* @version 1.0
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
*/
 
class GraphiquesTaxonsSup extends CommunGraphiques{
 
 
public function definirTable($version){
$this->table = Config::get('bdd_table_rang_sup')."_v".$version;
}
//+---- ressources ----+
public function traiterReferentieletNum(){
if (!empty($this->ressources[1])) {
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[1], $retour) == 1){
switch ($retour[1]) {
case 'bdtfx' : // pour le moment un seul referentiel disponible
$this->requete_condition[]= "num_nomen = ".$retour[2]." AND bdnt = 'bdtfx' ";
break;
default :
$e = "Le référentiel {$retour[1]} n'existe pas.";
throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
break;
}
}else {
$e = "Erreur dans l'url de votre requête :".
" précisez le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.";
throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
} else {
throw new Exception( "Erreur dans l'url de votre requête :".
" précisez le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.",
RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
}
public function traiterTypeGraphique(){
if (!empty($this->ressources[0])) {
switch ($this->ressources[0]) {
case 'climat' :
$this->requete_champs = ' ve_lumiere_min, ve_lumiere_max, ve_temperature_min,'.
' ve_temperature_max, ve_continentalite_min,'.
' ve_continentalite_max, ve_humidite_atmos_min,'.
' ve_humidite_atmos_max' ;
$this->nomGraphique= 'climat_min_max';
break;
case 'sol' :
$this->requete_champs = ' ve_humidite_edaph_min , ve_humidite_edaph_max,'.
' ve_reaction_sol_min, ve_reaction_sol_max, '.
' ve_nutriments_sol_min, ve_nutriments_sol_max,'.
' ve_salinite_min, ve_salinite_max,'.
' ve_texture_sol_min, ve_texture_sol_max,'.
've_mat_org_sol_min,ve_mat_org_sol_max ' ;
$this->nomGraphique = 'sol_min_max';
break;
default :
$e = "Erreur dans l'url de votre requête :".
"</br> précisez le graphique -> \"sol\" ou \"climat\".";
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
break;
}
}else {
throw new Exception("Erreur dans l'url de votre requête :".
"</br> precisez le graphique -> \"sol\" ou \"climat\".", RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
}
//+-------------------------- formatage du résultat -------------------------------------------+
public function changerValeursSVG(){
$this->ajouterValeursIntermediaires();
$Dompath = new DOMXPath($this->dom);
foreach ($this->valeurs_en_pourcentage as $cle => $val){
$val = preg_replace('/,/','.', $val);
$grad_id = array_search($val,$this->graduations_id);
$champs = preg_replace('/_min|_max|_[0-9]/','', $cle);
// dans le cas de mauvaises données, pour ne pas que tout le graphique
$case = $Dompath->query("//*[@id='".$grad_id."_".$champs."']")->item(0);
if($case != null) {
$case->setAttribute('fill','#EA6624');
$case->setAttribute('stroke','#EA6624');
$this->ajouterInfoAuSurvol($champs,$case);
}
$changement = true;
}
$this->ajusterFormatSVG();
}
public function ajouterValeursIntermediaires(){
$champs_ecolo = array_keys($this->champs_ontologiques);
foreach ($champs_ecolo as $chps ){
$min = !empty($this->valeurs_en_pourcentage[$chps.'_min']) ? $this->valeurs_en_pourcentage[$chps.'_min'] : -1;
$max = !empty($this->valeurs_en_pourcentage[$chps.'_max']) ? $this->valeurs_en_pourcentage[$chps.'_max'] : -1;
if ($min < ($max-0.1) ){
$i = $min + 0.1;
$num = 1;
for ($i ; $i < $max; $i += 0.1) {
$this->valeurs_en_pourcentage[$chps.'_'.$num] = $i;
$num++;
}
}
}
}
public function ajouterInfoAuSurvol($champs, $case){
$min = $this->valeurs_champs[$champs."_min"];
$max = $this->valeurs_champs[$champs."_max"];
if ($min != $max){
$valeurMin = $this->recupererOntologies($min, $champs );
$valeurMax = $this->recupererOntologies($max, $champs );
$valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
$valeurMax = $this->traiterIntermediaires($valeurMax->nom, $champs, $champs.'_max');
$case->setAttribute('title',"de $min: $valeurMin à $max: $valeurMax " );
} else {
$valeurMin = $this->recupererOntologies($min, $champs );
$valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
$case->setAttribute('title',"$min: $valeurMin" );
}
}
}
?>
/tags/v5.2-alpage/services/modules/0.1/baseflor/InformationsTaxonsSup.php
New file
0,0 → 1,274
<?php
 
/**
* Classe InformationsTaxonsSup.php permet de faire des requetes pour les rangs superieurs de baseflor
* du référentiel BDTFX et avec un numéro nomenclatural ( différent de 0 ).
* fin d'url possibles :
*
* /informations/#bdnt.nn:#num_nomen?champs=ecologie --> retourne champs ecologiques pour un BDNT et un num_nomen
*
*
* Encodage en entrée : utf8
* Encodage en sortie : utf8
* @package eflore-projets
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
* @version 1.0
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
*/
 
class InformationsTaxonsSup extends Commun{
protected $table = "";
private $champs_ontologiques = array();
private $format_reponse = 'informations';
protected $serviceNom = 'informations';
private $retour_format = 'max';
private $Bdd;
private $requete_condition = "";
private $champs_recherches = '*';
public function consulter($ressources, $parametres) {
$this->ressources = $ressources;
$this->parametres = $parametres;
$this->traiterParametres();
$this->definirTables();
$this->traiterRessources();
$resultats = '';
foreach ($this->table_version as $version) {
$this->table = $version;
$requete = $this->assemblerLaRequete();
$resultat = $this->Bdd->recupererTous($requete);
$versionResultat = $this->analyserResultat($resultat);
if (count($this->table_version) > 1) {
$resultats[$version] = $versionResultat;
} else {
$resultats = $versionResultat;
}
}
return $resultats;
}
public function analyserResultat($resultat) {
$versionResultat = null;
if ($resultat == '') {
$message = 'La requête SQL formée comporte une erreur!';
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
} elseif ($resultat) {
$versionResultat = $this->retournerResultatFormate($resultat);
}
return $versionResultat;
}
public function __construct(Conteneur $Conteneur) {
$this->Bdd = $Conteneur->getBdd();
}
//+--------------------------traitement ressources ou paramètres -------------------------------------------+
public function traiterRessources() {
if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)==1){
switch ($retour[1]) {
case 'bdtfx' :
$this->requete_condition[] = "num_nomen = ".$retour[2]." AND bdnt = 'bdtfx' ";
break;
default :
$e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " '
.$retour[1].' " n\'existe pas.';
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
break;
}
}
}
//+---- paramètres ----+
public function traiterParametres() {
if (isset($this->parametres) && !empty($this->parametres) ) {
foreach ($this->parametres as $param => $valeur) {
switch ($param) {
case 'categorie' :
if ($valeur == "ecologie"){
$this->champs_recherches = ' num_nomen, bdnt, ve_lumiere_min , ve_lumiere_max,'
.' ve_temperature_min, ve_temperature_max, ve_continentalite_min,'
.' ve_continentalite_max, ve_humidite_atmos_min, ve_humidite_atmos_max,'
.' ve_humidite_edaph_min, ve_humidite_edaph_max, ve_reaction_sol_min,'
.' ve_reaction_sol_max, ve_nutriments_sol_min, ve_nutriments_sol_max,'
.' ve_salinite_min, ve_salinite_max, ve_texture_sol_min,ve_texture_sol_max,'
.' ve_mat_org_sol_min, ve_mat_org_sol_max ';
} else {
$e = "Valeur de paramètre inconnue pour 'categorie'. Ce paramètre n'est pas autorisé pour informations/#id";
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
break;
case 'retour.format' :
if ($valeur == 'min' || $valeur == 'max') {
$this->retour_format = $valeur;
break;
} else {
$e = "Valeur de paramètre inconnue pour 'retour.format'. Ce paramètre n'est pas autorisé pour informations/#id";
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
case 'navigation.depart' :
$this->definirNavigationDepart($valeur);
break;
case 'navigation.limite' :
$this->definirNavigationLimite($valeur);
break;
case 'version.projet' :
$this->traiterVersion($valeur);
break;
default :
$e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " '
.$param.' " n\'existe pas.';
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); break;
}
}
}
}
 
//+++------------------------------traitement des versions----------------------------------------++
public function traiterVersion($valeur) {
if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '*' || $valeur == '+') {
$this->version_projet = $valeur;
} else {
$e = "Erreur : La version est inconnue.";
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
if ($this->version_projet == '*' && $this->ressources == array()) {
$message = "L'affichage de plusieurs versions ne fonctionne que pour les ressources de type /ressources/#id";
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($message, $code);
}
}
 
public function definirTables() {
$table_num_version = $this->recupererVersionDisponible();
$prefixe_table = config::get('bdd_table_rang_sup');
if ( in_array($this->version_projet,$table_num_version) ) {
$this->table_version[] = $prefixe_table.'_v'.$this->version_projet;
} elseif ($this->version_projet == '+') {
$derniere_version = $table_num_version[count($table_num_version) - 1];
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $derniere_version);
} elseif ($this->version_projet == '*') {
foreach ($table_num_version as $num_version) {
$this->table_version[] = $prefixe_table.'_v'.str_replace('.', '_', $num_version);
}
} else {
$e = "Erreur : La version est inconnue.";
throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
}
}
//+--------------------------formatages de resultats -------------------------------------------+
public function retournerResultatFormate($resultat) {
$this->resultat_json = $resultat[0];
if ($this->retour_format == 'max') {
$graphique_presence = $this->traiterEcologie() ;
if ($graphique_presence) {
$this->ajouterLiensGraphique($graphique_presence);
}
}
return $this->resultat_json ;
}
public function traiterEcologie() {
$donnees_presence = false;
$this->champs_ontologiques = Commun::s_recupererTableauConfig('Paramètres.champs_ontologiques');
foreach ($this->champs_ontologiques as $cle => $valeur){
/* Les deux tests commentés ci-dessous étaient présents dans eflore-test (uniquement) jusqu'à juin 2013.
La valeur 0 pose question.
cf baseflor_v2012_12_31
cf services/modules/0.1/baseflor/CommunGraphiques.php traiterValeursEcologiques() */
if ($this->resultat_json[$cle.'_min'] != "") { // && $this->resultat_json[$cle.'_min'] != 0) {
$donnees_presence[$this->getNomGraphique($valeur)] = true;
$tab_ontologie = $this->recupererOntologies($this->resultat_json[$cle.'_min'], $cle.'_min');
unset($this->resultat_json[$cle.'_min']);
}
if ($this->resultat_json[$cle.'_max'] != "") { // && $this->resultat_json[$cle.'_max'] != 0) {
$this->recupererOntologies($this->resultat_json[$cle.'_max'], $cle.'_max');
unset($this->resultat_json[$cle.'_max']);
}
}
return $donnees_presence;
}
//donne le nom du graphique correspondant à un champ écologique
public function getNomGraphique($code_ecolo) {
$graphique = null;
if (in_array($code_ecolo, explode(',',Config::get('Paramètres.climat')))) {
$graphique = 'climat';
} elseif (in_array($code_ecolo, explode(',', Config::get('Paramètres.sol')) )) {
$graphique = 'sol';
}
return $graphique;
}
public function ajouterLiensGraphique($graphique_presence) {
if ($graphique_presence['climat']) {
$this->resultat_json['graphique_climat']['libelle'] = 'climat';
$this->resultat_json['graphique_climat']['href'] = $this->ajouterHref('graphiques/climat',
strtolower($this->resultat_json['bdnt']).'.nn:'.$this->resultat_json['num_nomen']);
}
if ($graphique_presence['sol']) {
$this->resultat_json['graphique_sol']['libelle'] = 'sol';
$this->resultat_json['graphique_sol']['href'] = $this->ajouterHref('graphiques/sol',
strtolower($this->resultat_json['bdnt']).'.nn:'.$this->resultat_json['num_nomen']);
}
}
//+--------------------------traitement ontologies -------------------------------------------+
public function recupererOntologies($valeur, $champs){
$chps_sans = preg_replace("/_min|_max/", '', $champs);
$url = Config::get('url_service_base').Config::get('nom_projet').
'/ontologies/'.$this->champs_ontologiques[$chps_sans].':'.urlencode(urlencode($valeur));
try {
$val = $this->getBdd()->recuperer(sprintf(
"SELECT a.nom FROM baseflor_ontologies a LEFT JOIN baseflor_ontologies b ON a.id = b.id LEFT JOIN baseflor_ontologies c ON b.classe_id = c.id WHERE".
" b.code = BINARY '%s' AND c.code = BINARY '%s' LIMIT 0, 100",
$valeur,
$this->champs_ontologiques[$chps_sans]),
Bdd::MODE_OBJET);
$this->resultat_json[$champs.'.libelle'] = $val->nom;
$this->resultat_json[$champs.'.code'] = $valeur;
$this->resultat_json[$champs.'.href'] = $url;
} catch (Exception $e) {
$this->resultat_json[$champs.'.libelle'] = '';
$this->resultat_json[$champs.'.code'] = '';
$this->resultat_json[$champs.'.href'] = '';
}
}
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
public function assemblerLaRequete() {
$requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' '
.$this->retournerRequeteCondition();
return $requete;
}
public function retournerRequeteCondition() {
$condition = '';
if (empty($this->requete_condition) == false) {
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
}
return $condition;
}
}
?>