Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

No changes between revisions

Ignore whitespace Rev 850 → Rev 914

/tags/v5.0-agropyraie-20130830-1/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:eol-style
+native
\ No newline at end of property
Added: svn:executable
+*
\ No newline at end of property
/tags/v5.0-agropyraie-20130830-1/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:eol-style
+native
\ No newline at end of property
Added: svn:executable
+*
\ No newline at end of property
/tags/v5.0-agropyraie-20130830-1/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:eol-style
+native
\ No newline at end of property
Added: svn:executable
+*
\ No newline at end of property
/tags/v5.0-agropyraie-20130830-1/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:eol-style
+native
\ No newline at end of property
Added: svn:executable
+*
\ No newline at end of property
/tags/v5.0-agropyraie-20130830-1/services/modules/0.1/nvps/NomsVernaculaires.php
New file
0,0 → 1,652
<?php
/**
* Description :
* Classe NomsVernaculaires.php fournit une liste de noms vernaculaires et leur liaison à la bdtfx
* Le but étant de fournir un ensemble minimal d'information comprenant :
* un identifiant (numérique ou alphanumérique sous forme de ChatMot si possible), un nom, une langue et
* une relation avec un taxon de la bdtfx.
* Si l'url finit par /noms-vernaculaires on retourne une liste de noms (seulement les 100 premières par défaut).
* L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1&param2=val2&...
*
* Les paramètres de requête disponibles sont : masque, masque.code, masque.nom, masque.region , recherche,
* distinct, retour.format, navigation.depart et navigation.limite.
*
* Encodage en entrée : utf8
* Encodage en sortie : utf8
* @package framework-v3
* @author Delphine Cauquil <delphine@tela-botanica.org>
* @author Jennifer Dhé <jennifer.dhe@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-${year} Tela Botanica (accueil@tela-botanica.org)
*/
class NomsVernaculaires extends Commun {
protected $champ_infos = array(
'taxon' => array('service' => 'taxons', 'ressource' => 'nt:', 'projet' => 'bdtfx', 'nom' => 'nom_sci'));
 
protected $service = 'noms-vernaculaires';
 
/**
* Permet de stocker la requete formulée : /noms-vernaculaires | /noms-vernaculaires/#id |
* /noms-vernaculaires/#id/champ | /noms-vernaculaires/#id/relations
* Est remplit au cours de l'analyse des ressources (traiterRessources()), par défaut, a la valeur du service.
* Est utilisée principalement pr déterminer le format du tableau à retourner. */
protected $format_reponse = 'noms-vernaculaires';
 
/** Variables constituant les parametres de la requete SQL (champ, condition, limit) remplie
* selon ressources et paramètres */
protected $requete_champ = array(' * ');
protected $requete_condition = '';
protected $limite_requete = array(
'depart' => 0,
'limite' => 100
);
protected $champ_tri = 'code_langue';
protected $direction_tri = 'asc';
/**
* Indique les champs supplémentaires à retourner
* - conseil_emploi = conseil d'emploi du nom vernaculaire
* - genre = genre et nombre du nom
* - taxon = nom retenu associé à ce nom
*/
protected $champs_supp = array();
 
/**
* Precise la contenance plus ou moins précise du tableau à retourner :
* - min = les données présentes dans la table
* - max = les données de la table + les informations complémentaires (pour les identifiants et les codes)
* - oss = la liste des nom_sci (uniquement pour noms et taxons) */
protected $retour_format = 'max';
/** Valeur du paramètre de requete recherche :
* - stricte : le masque est passé tel quel à l'opérateur LIKE.
* - etendue : ajout automatique du signe % à la place des espaces et en fin de masque avec utilisation de LIKE.
* - floue : recherche tolérante vis-à-vis d'approximations ou d'erreurs (fautes d'orthographe par exemple) */
protected $recherche;
/** Permet de stocker le tableau de résultat (non encodé en json) */
protected $table_retour = array();
/** Stocke le nombre total de résultats de la requete principale. Est calculée lors de l'assemblage de la requete */
protected $total_resultat;
private $config;
public function __construct($config) {
$this->config = is_null($config) ? Config::get('NomsVernaculaires') : $config;
}
 
//+------------------------------------------------------------------------------------------------------+
// créer une condition en fonction du paramétre
public function traiterParametres() {
if (isset($this->parametres) && !empty($this->parametres)) {
 
if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') {
$this->recherche = $this->parametres['recherche'];
}
foreach ($this->parametres as $param => $valeur) {
switch ($param) {
case 'masque' :
$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
break;
case 'masque.nt' :
$this->ajouterFiltreMasque('num_taxon', $valeur);
break;
case 'masque.nv' :
$this->ajouterFiltreMasque('nom_vernaculaire', $valeur);
break;
case 'masque.lg' :
$this->ajouterFiltreMasque('code_langue', $valeur);
break;
case 'masque.cce' :
$this->ajouterFiltreMasque('num_statut', $valeur);
break;
case 'retour.format' :
$this->retour_format = $valeur;
break;
case 'navigation.depart' :
$this->limite_requete['depart'] = $valeur;
break;
case 'navigation.limite' :
$this->limite_requete['limite'] = $valeur;
break;
case 'retour.champs' :
$this->champs_supp = explode(',',$valeur);
break;
case 'recherche' :
break;
case 'version.projet' :
break;
default :
$p = 'Erreur dans les paramètres de recherche de votre requête : '.
'</br> Le paramètre " '.$param.' " n\'existe pas.';
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $p);
}
}
}
}
 
public function ajouterFiltreMasque($nom_champ, $valeur) {
if ($nom_champ == 'num_taxon') { // si il s'agit d'un chiffre
$this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur);
} else {
if ($this->recherche == 'floue') {
$this->requete_condition[] = '(SOUNDEX('.$nom_champ.') = SOUNDEX(\''.$valeur.'\')'
.' OR SOUNDEX(REVERSE('.$nom_champ.')) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ';
} else {
if ($this->recherche == 'etendue') {
$valeur = '%'.str_replace(' ','% ', $valeur);
$valeur .= '%';
}
$this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur);
}
}
}
 
//+------------------------------------------------------------------------------------------------------+
// en fonction de la présence des ressources modifie requete_champ et requete_condition
public function traiterRessources() {
if (isset($this->ressources) && !empty($this->ressources)) {
if (isset($this->ressources[0]) && !empty($this->ressources[0])) {
$this->traiterRessourceId(); // ajoute condition id=#valeur
if (isset($this->ressources[1]) && !empty($this->ressources[1])) {
$this->traiterRessourceChamp(); //modifie requete_champ ou requete_condition
}
}
} else { //rajoute distinct pour ne pas avoir plusieurs fois le même nom
$this->requete_champ = array('distinct(id)', 'nom_vernaculaire ');
}
}
 
//requete : /noms-vernaculaires/#id (ex : /noms-vernaculaires/7)
public function traiterRessourceId() {
if (is_numeric($this->ressources[0])) {
$this->requete_condition[] = ' id = '.$this->getBdd()->proteger($this->ressources[0]);
$this->format_reponse .= '/id';
} elseif ($this->ressources[0] == 'attributions') {
$this->format_reponse .= '/attributions';
} else {
$r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->ressources[0].
' " n\'existe pas.';
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r);
}
}
 
 
public function traiterRessourceChamp() {
$this->format_reponse .= '/champ';
$this->analyserChamp();
}
 
public function analyserChamp() {
$this->requete_champ = array();
$this->recupererTableConfig('champs_possibles');// s'il y a plusieurs champs correspondant au champ demandé ils sont séparé par des |
$champs = explode(' ', $this->ressources[1]);
foreach ($champs as $champ) {
preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match);
if (isset($this->champs_possibles[$match[1]])) {
$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[1]]);
} elseif (isset($this->champs_possibles[$match[0]])) {
$this->requete_champ[] = str_replace('|', ', ', $this->champs_possibles[$match[0]]);
} else {
$champs_possibles = implode('</li><li>', array_keys($this->champs_possibles));
$c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '.
'Les champs disponibles sont : <li>'.$champs_possibles.'</li> et leurs déclinaisons (ex. ".code").';
$this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c);
}
}
}
 
//+------------------------------------------------------------------------------------------------------+
public function assemblerLaRequete() {
$requete = ' SELECT '.$this->formerRequeteChamp().
' FROM '.$this->table
.$this->formerRequeteCondition()
.$this->formerRequeteLimite();
return $requete;
}
 
public function formerRequeteChamp() {
if (in_array('*', $this->requete_champ)) {
$champ = ' * ';
} else {
$champ = implode(', ', $this->requete_champ);
}
return $champ;
}
 
public function formerRequeteCondition() {
$condition = '';
if ($this->requete_condition != null) {
$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
}
return $condition;
}
 
//ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes
// suivantes : /noms-vernaculaires et /noms-vernaculaires/#id/relations)
public function formerRequeteLimite() {
if (in_array($this->format_reponse , array($this->service.'/id', $this->service.'/id/champs'))) {
$this->requete_limite = '';
} elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) {
$this->limite_requete['depart'] =
(($this->total_resultat - $this->limite_requete['limite']) < 0) ? 0 : ($this->total_resultat - $this->limite_requete['limite']);
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
} else {
$this->requete_limite = ' LIMIT '.$this->limite_requete['depart'].', '.$this->limite_requete['limite'];
}
return $this->requete_limite;
}
 
//on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /noms-vernaculaires)
public function recupererTotalResultat() {
$distinct = ($this->format_reponse == 'noms-vernaculaires/attributions') ? 'id' : 'distinct(id)';
$requete = 'SELECT count('.$distinct.') as nombre FROM '
.$this->table
.$this->formerRequeteCondition();
$res = $this->getBdd()->recuperer($requete);
 
if ($res) {
$total = $res['nombre'];
} else {
$t = 'Fonction recupererTotalResultat() : <br/>Données introuvables dans la base '.$requete;
$this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t);
}
return $total;
}
 
//+------------------------------------------------------------------------------------------------------+
// determine en fct du service appelé (/noms-vernaculaires | /noms-vernaculaires/#id | /noms-vernaculaires/#id/champ |
// /noms-vernaculaires/#id/relations) le format du tableau à retourner.
public function retournerResultatFormate($resultat) {
$this->recupererTableConfig('correspondance_champs');
switch ($this->format_reponse) {
case 'noms-vernaculaires' :
$reponse = ($this->retour_format == 'oss') ? $this->formaterEnOss($resultat) : $this->formaterNomsVernaculaires($resultat); break;
case 'noms-vernaculaires/attributions' : $reponse = $this->formaterNomsVernaculairesAttributions($resultat); break;
case 'noms-vernaculaires/id' : $reponse = $this->formaterNomsVernaculairesId($resultat); break;
case 'noms-vernaculaires/id/champ' : $reponse = $this->formaterNomsVernaculairesIdChamp($resultat); break;
default : break;
}
return $reponse;
}
public function ajouterJsonEnTeteNV() {
$table_retour_json['masque'] = $this->recupererMasque();
$table_retour_json['depart'] = $this->limite_requete['depart'];
$table_retour_json['limite'] = $this->limite_requete['limite'];
$table_retour_json['total'] = $this->total_resultat;
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires');
if (isset($url['precedent']) && $url['precedent'] != '') {
$table_retour_json['href.precedent'] = $url['precedent'];
}
if (isset($url['suivant']) && $url['suivant'] != '') {
$table_retour_json['href.suivant'] = $url['suivant'];
}
return $table_retour_json;
}
public function ajouterJsonResultatNV($resultat) {
foreach ($resultat as $tab) {
foreach ($tab as $key => $valeur) {
if ($valeur != '') {
switch ($key) {
case 'id' : $num = $valeur; break;
case 'nom_vernaculaire' : $this->table_retour['nom'] = $valeur; break;
default : break;
}
}
}
if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('noms-vernaculaires', $num);
$resultat_json[$num] = $this->table_retour;
$this->table_retour = array();
}
return $resultat_json;
}
 
public function formaterNomsVernaculaires($resultat) {
$table_retour_json['entete'] = $this->ajouterJsonEnTeteNV();
$resultat = $this->hierarchiserResultat($resultat);
$table_retour_json['resultat'] = $this->ajouterJsonResultatNV($resultat);
return $table_retour_json;
}
public function hierarchiserResultat($resultat) {
//tri recherche floue
if (isset($this->parametres['masque.nv'])) {
$resultat = $this->trierRechercheFloue($this->parametres['masque.nv'], $resultat, 'nom_vernaculaire');
}
if (isset($this->parametres['masque'])) {
$resultat = $this->trierRechercheFloue($this->parametres['masque'], $resultat, 'nom_vernaculaire');
}
return $resultat;
}
public function recupererMasque() {
$tab_masque = array();
foreach ($this->parametres as $param=>$valeur) {
if (strstr($param, 'masque') != false) {
$tab_masque[] = $param.'='.$valeur;
}
}
$masque = implode('&', $tab_masque);
return $masque;
}
public function formaterEnOss($resultat) {
$table_nom = array();
$oss = '';
foreach ($resultat as $tab) {
if (isset($tab['nom_vernaculaire']) ) {
if (!in_array($tab['nom_vernaculaire'], $table_nom)) {
$table_nom[] = $tab['nom_vernaculaire'];
$oss [] = $tab['nom_vernaculaire'];
}
}
}
if (isset($this->masque)) $masque = implode('&', $this->masque);
else $masque = 'Pas de masque';
$table_retour_oss = array($masque, $oss);
return $table_retour_oss;
}
public function formaterNomsVernaculairesAttributions($resultat) {
//on remplie la table $table_retour_json['entete']
$table_retour_json['entete']['masque'] = $this->recupererMasque();
$table_retour_json['entete']['depart'] = $this->limite_requete['depart'];
$table_retour_json['entete']['limite'] = $this->limite_requete['limite'];
$table_retour_json['entete']['total'] = $this->total_resultat;
$url = $this->formulerUrl($this->total_resultat, '/noms-vernaculaires/attributions');
if (isset($url['precedent']) && $url['precedent'] != '') {
$table_retour_json['entete']['href.precedent'] = $url['precedent'];
}
if (isset($url['suivant']) && $url['suivant'] != '') {
$table_retour_json['entete']['href.suivant'] = $url['suivant'];
}
foreach ($resultat as &$tab) {
$resultat_json[$tab['id']]['id'] = $tab['id'];
$resultat_json[$tab['id']]['nom_vernaculaire'] = $tab['nom_vernaculaire'];
$resultat_json[$tab['id']]['code_langue'] = $tab['code_langue'];
$resultat_json[$tab['id']]['taxon.code'] = 'bdtfx.nt:'.$tab['num_taxon'];
if ($this->retour_format == 'max') {
$resultat_json[$tab['id']]['num_taxon'] = $tab['num_taxon'];
$resultat_json[$tab['id']]['nom_retenu.code'] = $tab['num_taxon'];
$resultat_json[$tab['id']]['taxon'] = $tab['num_taxon'];
$this->taxons[] = $tab['num_taxon']; // utilisé pour chercher les noms latins plus bas
$resultat_json[$tab['id']]['href'] = $this->ajouterHref('noms-vernaculaires', $tab['id']);
if($this->champs_supp != array()) {
$resultat_json[$tab['id']] = $this->ajouterChampsOntologieLigneResultat($tab);
}
}
}
if ($this->retour_format == 'max') {
// On est obligé de faire un deuxième boucle pour demander tous les taxons présents en une
// fois et les attribuer aux noms car c'est beaucoup plus rapide
$noms_sci = $this->recupererNomTaxons();
foreach ($resultat_json as $num_nom => &$tab) {
$tab = $this->ajouterTaxonsAttributionsLigneResultat($tab, $noms_sci);
if($tab == null) {
unset($resultat_json[$num_nom]);
}
}
}
uasort($resultat_json, array($this,'trierLigneTableau'));
$table_retour_json['resultat'] = $resultat_json;
return $table_retour_json;
}
/**
* Ajoute les champs d'ontologie supplémentaires si necéssaire
* en faisant appels aux web services associés
* @param array $ligne_resultat
*
* @return array la ligne modifiée
*/
public function ajouterChampsOntologieLigneResultat($ligne_resultat) {
$intitule = '';
foreach($this->champ_infos as $cle => $champs_supplementaires) {
if(in_array($cle, $this->champs_supp)) {
extract($champs_supplementaires);
$valeur_recherche = '';
switch($cle) {
case 'taxon':
$valeur_recherche = $ligne_resultat['num_taxon'];
$intitule = 'taxon.code';
break;
}
$code_valeur = '';
if(trim($valeur_recherche) != '') {
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur_recherche, $projet);
$code_valeur = $this->chercherSignificationCode($url, $nom);
}
$ligne_resultat[$intitule] = $code_valeur;
}
}
return $ligne_resultat;
}
/**
* Fonction qui ajoute les attributions à une ligne de résultats
*
* @param array $ligne_tableau_resultat
* @param array $nom_sci
*/
public function ajouterTaxonsAttributionsLigneResultat(&$ligne_tableau_resultat, &$noms_sci) {
if (isset($noms_sci[$ligne_tableau_resultat['num_taxon']])) {
$ligne_tableau_resultat['nom_retenu.code'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['id'];
$ligne_tableau_resultat['taxon'] = $noms_sci[$ligne_tableau_resultat['num_taxon']]['nom_sci'];
} else {
$ligne_tableau_resultat = null;
}
return $ligne_tableau_resultat;
}
private function trierLigneTableau($a, $b) {
$retour = 0;
if ($a[$this->champ_tri] == $b[$this->champ_tri]) {
$retour = 0;
}
if($this->champ_tri == 'code_langue') {
if ($a[$this->champ_tri] == 'fra' && $b[$this->champ_tri] != 'fra') {
$retour = ($this->direction_tri == 'asc') ? -1 : 1;
} else if ($a[$this->champ_tri] != 'fra' && $b[$this->champ_tri] == 'fra') {
$retour = ($this->direction_tri == 'asc') ? 1 : -1;
} else {
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
}
} else {
$retour = $this->comparerChaineSelonDirectionTri($a[$this->champ_tri], $b[$this->champ_tri]);
}
return $retour;
}
private function comparerChaineSelonDirectionTri($a, $b) {
if($this->direction_tri == 'asc') {
return ($a < $b) ? -1 : 1;
} else {
return ($a > $b) ? -1 : 1;
}
}
// formatage de la reponse /id ss la forme
// id, nom_vernaculaire, attributions
// langue
// num_nom (correspond à un taxon bdtfx)
public function formaterNomsVernaculairesId($resultat) {
foreach ($resultat as $taxon) { // pour chaque attribution à un taxon bdtfx
// on crée les variables qui serviront de clés et on les enléves du tableau
$num_nom = $taxon['id']; // unique pour un trinôme id, langue, taxon
$langue = $taxon['code_langue'];
unset($taxon['code_langue']);
 
foreach ($this->correspondance_champs as $key => $correspondance) { // ordonne les infos pour affichage
if (isset($taxon[$key]) && $taxon[$key] != "") {
$this->afficherDonnees($correspondance, $taxon[$key], $langue, $num_nom);
}
}
foreach ($taxon as $key => $valeur) { // rajoute les champs non prévus dans l'api
if (!isset($this->correspondance_champs[$key]) && $valeur != "") {
$this->afficherDonnees($key, $valeur, $langue, $num_nom);
}
}
}
if ($this->retour_format == 'max') $this->afficherTaxons(); // va chercher les noms de tous les taxons
unset($this->table_retour['href']);
return $this->table_retour;
}
 
public function afficherDonnees($champ, $valeur, $langue = '', $num_nom = '') {
if ($champ == 'id' || $champ == 'nom_vernaculaire') {
$this->table_retour[$champ] = $valeur;
} elseif (preg_match('/^(.*)\.code$/', $champ, $match)) {
switch ($match[1]) {
case 'taxon' : if ($this->retour_format == 'max') {$this->taxons[$num_nom] = $valeur;}
$this->afficherPointCode($match[1], $langue, $num_nom, $valeur); break;
case 'langue' : //$this->afficherPointCode($match[1], 'iso-639-3', 'langues', $valeur);
break;
default : break;
}
 
} elseif ($langue != '') {
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $valeur;
} else {
$this->table_retour[$champ] = $valeur;
}
}
 
public function afficherPointCode($nomChamp, $langue, $num_nom, $valeur) {
if (isset($this->champ_infos[$nomChamp])) {
extract($this->champ_infos[$nomChamp]);
}
 
if ($this->retour_format == 'max') {
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
if ($service == 'taxons') {
$code_valeur = '';
$this->table_retour['attributions'][$langue][$num_nom]['nom_retenu.code'] = $code_valeur;
} else {
$code_valeur = $this->chercherSignificationCode($url, $nom);
}
if ($projet != '') $projet .= '.';
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp] = $code_valeur;
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.href'] = $url;
} else {
if ($projet != '') $projet .= '.';
$this->table_retour['attributions'][$langue][$num_nom][$nomChamp.'.code'] = $projet.$ressource.$valeur;
}
}
 
public function chercherSignificationCode($url, $nom) {
if (isset($this->signification_code[$url])) {
$valeur = $this->signification_code[$url];
} else {
$res = $this->consulterHref($url);
$valeur = $res->$nom;
$this->signification_code[$url] = $valeur;
}
return $valeur;
}
 
public function afficherTaxons() {
$resultat = $this->recupererNomTaxons();
foreach ($this->table_retour['attributions'] as $code_langue=>$langue) {
foreach ($langue as $num_nom=>$taxon) {
$num_tax = ltrim($taxon['taxon.code'], 'bdtfx.nt:');
if (isset($resultat[$num_tax])) {
$this->table_retour['attributions'][$code_langue][$num_nom]['nom_retenu.code'] = $resultat[$num_tax]['id'];
$this->table_retour['attributions'][$code_langue][$num_nom]['taxon'] = $resultat[$num_tax]['nom_sci'];
}
}
}
}
public function recupererNomTaxons() {
$taxons = array_unique($this->taxons);
$url = Config::get('url_service_base').'bdtfx/taxons?navigation.limite=500&ns.structure=au&masque.nt='.implode(',', $taxons);
$res = $this->consulterHref($url);
foreach ($res->resultat as $id=>$taxon) {
$resultat[$taxon->num_taxonomique]['id'] = 'bdtfx.nn:'.$id;
$resultat[$taxon->num_taxonomique]['nom_sci'] = $taxon->nom_sci_complet;
}
return $resultat;
}
 
public function formaterNomsVernaculairesIdChamp($resultat) {
$this->table_retour['id'] = $this->ressources[0];
$champs = explode(' ', $this->ressources[1]);
if (in_array('attributions', $champs) != false) {
$this->formaterNomsVernaculairesId($resultat);
unset($this->table_retour['nom_vernaculaire']);
} else {
$champ_attributions = array('num_taxon', 'genre', 'notes');
foreach ($resultat as $taxon) {
foreach ($taxon as $key=>$valeur) {
if ($key == 'code_langue' && in_array('langue', $champs) != false) {
$this->table_retour['attributions']['langue'][] = $valeur;
} elseif (in_array($key, $champ_attributions) != false) {
$this->afficherPoint($this->correspondance_champs[$key] , $valeur, $taxon['code_langue'], $taxon['id']);
} elseif (in_array($key, $champs) != false) {
$this->table_retour[$key] = $valeur;
}
}
}
}
return $this->table_retour;
}
 
public function afficherPoint($champ, $valeur, $langue, $num_nom) {
preg_match('/^(.*)\.code$/', $champ, $match);
$champ = $match[1];
if (isset($this->champ_infos[$champ])) {
extract($this->champ_infos[$champ]);
$url = $this->ajouterHrefAutreProjet($service, $ressource, $valeur, $projet);
$projet .= '.';
}
 
$champs = explode(' ', $this->ressources[1]);
if (in_array($champ.'.*', $champs) !== false && isset($projet)) {
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
}
if (in_array($champ.'.code', $champs) !== false && isset($projet)) {
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.code'] = $projet.$ressource.$valeur;
}
if (in_array($champ.'.href', $champs) !== false && isset($projet)) {
$this->table_retour['attributions'][$langue][$num_nom][$champ.'.href'] = $url;
}
if (in_array($champ, $champs) !== false) {
if (isset($url)) {
$this->table_retour['attributions'][$langue][$num_nom][$champ] = $this->chercherSignificationCode($url, $nom);
} else {
$this->table_retour['attributions'][$langue][$champ] = $valeur;
}
}
}
 
public function afficherLangue($nomChamp, $projet, $service, $valeur, $ressource = '', $nom = 'nom') {
if ($this->retour_format == 'max') {
$this->table_retour['attributions'][$nomChamp] = $nom;
$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
$this->table_retour['attributions'][$nomChamp.'.href'] = $url;
} else {
$this->table_retour['attributions'][$nomChamp.'.code'] = $projet.$ressource.$valeur;
}
}
 
 
}
?>