| /branches/refact/initialiserBdd.sh |
|---|
| New file |
| 0,0 → 1,66 |
| #!/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$ |
| ############################################################################################################## |
| # 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..."; |
| 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 "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 "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 "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 "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 "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 "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 |
| /branches/refact/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 |
| /branches/refact/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 |
| /branches/refact/services/modules/0.1/insee-d/ZoneGeo.php |
|---|
| New file |
| 0,0 → 1,405 |
| <?php |
| /** |
| * Description : |
| * Classe ZoneGeo.php fournit des informations sur ensemble structuré des termes et concepts représentant les éléments |
| * d'un domaine de connaissances . |
| * 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 region et |
| * éventuellement une relation hiérarchique avec un autre terme (=classe). |
| * Si l'url finit par /zone-geo on retourne une liste de termes (seulement les 100 premières par défaut). |
| * L'url peut contenir des paramètres optionnels passés après le ? : /observations?param1=val1¶m2=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 ZoneGeo extends Commun { |
| protected $service = 'zone-geo'; |
| /** |
| * Permet de stocker la requete formulée : /zone-geo | /zone-geo/#id | /zone-geo/#id/champ | /zone-geo/#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 = 'zone-geo'; |
| /** Variables constituant les parametres de la requete SQL (champ, condition, group by, limit) remplie |
| * selon ressources et paramètres */ |
| protected $requete_champ = ' * '; |
| protected $requete_condition = ''; |
| protected $limite_requete = array( |
| 'depart' => 0, |
| 'limite' => 100 |
| ); |
| /** Stockage des ressources et paramétres */ |
| protected $table_ressources = array(); |
| protected $table_param = 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; |
| // +-----------------------------------------------------------------------------------------------------+ |
| public function traiterParametres() { |
| if (isset($this->parametres) && !empty($this->parametres)) { |
| $this->table_param = $this->parametres; |
| // masque : filtre la liste en fonction d'un masque de recherche portant sur le code, le nom ou la region. |
| // masque.code : filtre uniquement sur le code. masque.nom : filtre uniquement sur le nom. |
| // masque.region : filtre uniquement sur la region. |
| if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') { |
| $this->recherche = $this->parametres['recherche']; |
| } |
| foreach ($this->parametres as $param => $valeur) { |
| switch ($param) { |
| case 'masque' : |
| $this->ajouterLeFiltreMasque('masque', $valeur); |
| break; |
| case 'masque.code' : |
| $this->ajouterLeFiltreMasque('dep', $valeur); |
| break; |
| case 'masque.nom' : |
| $this->ajouterLeFiltreMasque('nccenr', $valeur); |
| break; |
| case 'masque.region' : |
| $this->ajouterLeFiltreMasque('region', $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 'recherche' : |
| 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 ajouterLeFiltreMasque($nom_champ, $valeur) { |
| if ($nom_champ == 'dep' || $nom_champ == 'region') { |
| $this->requete_condition[] = $nom_champ.' = '.$this->getBdd()->proteger($valeur); |
| } else { |
| if ($this->recherche == 'floue') { |
| if ($nom_champ == 'masque') { |
| $this->requete_condition[] = '( dep = '.$this->getBdd()->proteger($valeur) |
| .' OR region = '.$this->getBdd()->proteger($valeur) |
| .' OR ( SOUNDEX(nccenr) = SOUNDEX(\''.$valeur.'\')' |
| .' OR SOUNDEX(REVERSE(nccenr)) = SOUNDEX(REVERSE(\''.$valeur.'\')) ' |
| .')) '; |
| } else { |
| $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 .= '%'; |
| } |
| if ($nom_champ == 'masque') { |
| $this->requete_condition[] = ' (dep = '.$this->getBdd()->proteger($valeur) |
| .' OR nccenr LIKE '.$this->getBdd()->proteger($valeur) |
| .' OR region = '.$this->getBdd()->proteger($valeur).')'; |
| } else { |
| $this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur); |
| } |
| } |
| } |
| } |
| //+------------------------------------------------------------------------------------------------------+ |
| public function traiterRessources() { |
| if (isset($this->ressources) && !empty($this->ressources)) { |
| $this->table_ressources = $this->ressources; |
| if (isset($this->table_ressources[0]) && !empty($this->table_ressources[0])) { |
| //requete = /zone-geo/#id |
| $this->traiterRessourceId(); |
| if (isset($this->table_ressources[1]) && !empty($this->table_ressources[1])) { |
| //dans le cas /zone-geo/#id/#champ ou /zone-geo/#id/relations |
| $this->traiterRessourceChampOuRelations(); |
| } |
| } |
| } |
| } |
| //requete : /zone-geo/#id (ex : /zone-geo/7) |
| public function traiterRessourceId() { |
| if (is_numeric($this->table_ressources[0])) { |
| $this->requete_condition[] = ' dep = '.$this->getBdd()->proteger($this->table_ressources[0]); |
| $this->format_reponse .= '/id'; |
| } else { |
| $r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->table_ressources[0]. |
| ' " n\'existe pas.'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r); |
| } |
| } |
| public function traiterRessourceChampOuRelations() { |
| //requete = /zone-geo/#id/relations : |
| if ($this->table_ressources[1] == 'relations') { |
| $this->format_reponse .= '/relations'; |
| $this->requete_condition[] = 'region = (SELECT region FROM '.$this->table.' WHERE ' |
| .implode(' AND ', $this->requete_condition).')'; |
| //requete = /zone-geo/#id/#champ : |
| } else { |
| $this->format_reponse .= '/champ'; |
| } |
| } |
| //+------------------------------------------------------------------------------------------------------+ |
| public function assemblerLaRequete() { |
| //assemblage de la requete : |
| $requete = ' SELECT '.$this->requete_champ. |
| ' FROM '.$this->table |
| .$this->formerRequeteCondition() |
| .$this->formerRequeteLimite(); |
| return $requete; |
| } |
| 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 : /zone-geo et /zone-geo/#id/relations) |
| public function formerRequeteLimite() { |
| if ($this->format_reponse != 'zone-geo' && $this->format_reponse != 'zone-geo/id/relations') { |
| $this->requete_limite = ''; |
| } elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) { |
| //cas où la requete presente un navigation.depart supérieur au nb total de resultats. |
| $this->limite_requete['depart'] = |
| (($nb - $this->limite_requete['limite']) < 0) ? 0 : ($nb - $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; |
| } |
| public function recupererTotalResultat() { |
| //on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /zone-geo) |
| $requete = 'SELECT count(*) 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'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t); |
| } |
| return $total; |
| } |
| //+------------------------------------------------------------------------------------------------------+ |
| // determine en fct du service appelé (/zone-geo | /zone-geo/#id | /zone-geo/#id/champ | |
| // /zone-geo/#id/relations) le format du tableau à retourner. |
| public function retournerResultatFormate($resultat) { |
| $this->recupererTableConfig('correspondance_champs'); |
| switch ($this->format_reponse) { |
| case 'zone-geo' : $reponse = $this->formaterZoneGeo($resultat); break; |
| case 'zone-geo/id' : $reponse = $this->formaterZoneGeoId($resultat[0]); break; |
| case 'zone-geo/id/champ' : $reponse = $this->formaterZoneGeoIdChamp($resultat[0]); break; |
| case 'zone-geo/id/relations' : $reponse = $this->formaterZoneGeoIdRelations($resultat); break; |
| default : break; |
| } |
| return $reponse; |
| } |
| public function formaterZoneGeo($resultat) { |
| //on remplit la table $table_retour_json['entete'] |
| $this->table_retour['depart'] = $this->limite_requete['depart']; |
| $this->table_retour['limite'] = $this->limite_requete['limite']; |
| $this->table_retour['total'] = $this->total_resultat; |
| $url = $this->formulerUrl($this->total_resultat, '/zone-geo'); |
| if (isset($url['precedent']) && $url['precedent'] != '') { $this->table_retour['href.precedent'] = $url['precedent']; } |
| if (isset($url['suivant']) && $url['suivant'] != '') { $this->table_retour['href.suivant'] = $url['suivant']; } |
| $table_retour_json['entete'] = $this->table_retour; |
| //on remplit la table $table_retour_json['resultat'] |
| $this->table_retour = array(); |
| if (isset($this->table_param['masque_nom'])) $resultat = $this->trierRechercheFloue($this->table_param['masque_nom'], $resultat, 'nccenr'); |
| foreach ($resultat as $tab) { |
| foreach ($tab as $key => $valeur) { |
| if ($valeur != '') { |
| switch ($key) { |
| case 'dep' : $num = $valeur; $this->table_retour['code'] = $valeur; break; |
| case 'nccenr' : $this->table_retour['nom'] = $valeur; break; |
| default : break; |
| } |
| } |
| } |
| if ($this->retour_format == 'max') { |
| $this->table_retour['href'] = $this->ajouterHref('zone-geo', $num); |
| } |
| $resultat_json[$num] = $this->table_retour; |
| $this->table_retour = array(); |
| } |
| $table_retour_json['resultat'] = $resultat_json; |
| return $table_retour_json; |
| } |
| public function formaterZoneGeoId($resultat) { |
| foreach ($resultat as $key => $valeur) { |
| if ($valeur != '') { |
| $this->afficherDonnees($key, $valeur); |
| } |
| } |
| unset($this->table_retour['href']); |
| return $this->table_retour; |
| } |
| public function formaterZoneGeoIdRelations($resultat) { |
| if ($resultat == '') { |
| $retour = null; |
| } else { |
| //on remplit la table $table_retour_json['entete'] |
| $this->table_retour['depart'] = $this->limite_requete['depart']; |
| $this->table_retour['limite'] = $this->limite_requete['limite']; |
| $this->table_retour['total'] = $this->total_resultat; |
| //formuler les urls |
| $url = $this->formulerUrl(count($resultat), '/zone-geo'); |
| if ($url['precedent'] != '') { $this->table_retour['href.precedent'] = $url['precedent']; } |
| if ($url['suivant'] != '') { $this->table_retour['href.suivant'] = $url['suivant']; } |
| $retour['entete'] = $this->table_retour; |
| $this->table_retour = array(); |
| //on remplit la table $table_retour_json['resultat'] |
| foreach ($resultat as $tab) { |
| foreach ($tab as $key => $valeur) { |
| switch ($key) { |
| case 'dep' : $num = $valeur; $this->table_retour['code'] = $valeur; break; |
| case 'nccenr' : $this->table_retour['nom'] = $valeur; break; |
| default : break; |
| } |
| } |
| if ($this->retour_format == 'max') $this->table_retour['href'] = $this->ajouterHref('zone-geo', $num); |
| $resultat_json[$num] = $this->table_retour; |
| $this->table_retour = array(); |
| } |
| $retour['resultat'] = $resultat_json; |
| } |
| return $retour; |
| } |
| public function formaterZoneGeoIdChamp($resultat) { |
| //on recupère tous les resultats possibles |
| $reponse = $this->formaterZoneGeoId($resultat); |
| $this->table_retour = array(); |
| //on recupère les résultats demandés à partir du tableau de résultat complet |
| $this->table_retour['id'] = $reponse['code']; |
| $champs = explode(' ', $this->table_ressources[1]); |
| foreach ($champs as $champ) { |
| if ($this->verifierValiditeChamp($champ)) { |
| if (strrpos($champ, '.*') !== false) { |
| $this->afficherPointEtoile($champ, $reponse); |
| } else { |
| if (isset($reponse[$champ])) { |
| $this->table_retour[$champ] = $reponse[$champ]; |
| } else { |
| $this->table_retour[$champ] = null; |
| } |
| } |
| } |
| } |
| return $this->table_retour; |
| } |
| public function verifierValiditeChamp($champ) { |
| preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match); |
| $champs_possibles = $this->correspondance_champs; |
| $champs_possibles[] = 'nom.*'; |
| if (in_array($match[1], $champs_possibles)) { |
| $validite = true; |
| } elseif (in_array($match[0], $champs_possibles)) { |
| $validite = true; |
| } else { |
| $champs_possibles = implode('</li><li>', $champs_possibles); |
| $c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '. |
| 'Les champs disponibles sont : <li>'.$champs_possibles.'</li>'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c); |
| } |
| return $validite; |
| } |
| public function afficherPointEtoile($champ, $reponse) { |
| preg_match('/^([^.]+\.)\*$/', $champ, $match); |
| foreach ($reponse as $chp => $valeur) { |
| if (strrpos($chp, $match[1]) !== false) { |
| if ($valeur != '') { |
| $this->table_retour[$chp] = $valeur; |
| } else { |
| $this->table_retour[$chp] = null; |
| } |
| } |
| } |
| } |
| public function afficherDonnees($champ, $valeur) { |
| if ($this->retour_format == 'max') { |
| if ($champ == 'region' || $champ == 'chef_lieu') { |
| $projet = 'insee-'.substr($champ, 0, 1); |
| $this->table_retour[$champ.'.code'] = $valeur; |
| $this->table_retour[$champ.'.href'] = $this->ajouterHrefAutreProjet('zone-geo', '', $valeur, $projet); |
| } elseif ($champ == 'tncc') { |
| $url = $this->ajouterHref('ontologies', $valeur); |
| $res = $this->consulterHref($url); |
| $this->table_retour['type_nom'] = $res->nom; |
| $this->table_retour['type_nom.code'] = $valeur; |
| $this->table_retour['type_nom.href'] = $url; |
| } else { |
| $this->table_retour[$this->correspondance_champs[$champ]] = $valeur; |
| } |
| } else { |
| $this->table_retour[$this->correspondance_champs[$champ]] = $valeur; |
| } |
| } |
| } |
| ?> |
| /branches/refact/services/modules/0.1/iso-3166-1/ZoneGeo.php |
|---|
| New file |
| 0,0 → 1,401 |
| <?php |
| /** |
| * Description : |
| * Classe ZoneGeo.php fournit des informations sur un ensemble de lieux à une échelle donnée. |
| * 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 region et |
| * éventuellement une relation hiérarchique avec un autre terme (=classe). |
| * Si l'url finit par /zone-geo on retourne une liste de zones (seulement les 100 premières par défaut). |
| * L'url peut contenir des paramètres optionnels passés après le ? : /zone-geo?param1=val1¶m2=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 ZoneGeo extends Commun { |
| protected $service = 'zone-geo'; |
| /** |
| * Permet de stocker la requete formulée : /zone-geo | /zone-geo/#id | /zone-geo/#id/champ | /zone-geo/#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 = 'zone-geo'; |
| /** Variables constituant les parametres de la requete SQL (champ, condition, group by, limit) remplie |
| * selon ressources et paramètres */ |
| protected $requete_champ = ' * '; |
| protected $requete_condition = ''; |
| protected $limite_requete = array( |
| 'depart' => 0, |
| 'limite' => 100 |
| ); |
| /** Stockage des ressources et paramétres */ |
| protected $table_ressources = array(); |
| protected $table_param = 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; |
| // +-----------------------------------------------------------------------------------------------------+ |
| public function traiterParametres() { |
| if (isset($this->parametres) && !empty($this->parametres)) { |
| $this->table_param = $this->parametres; |
| // masque : filtre la liste en fonction d'un masque de recherche portant sur le code, le nom ou la region. |
| // masque.code : filtre uniquement sur le code. masque.nom : filtre uniquement sur le nom. |
| // masque.region : filtre uniquement sur la region. |
| if (isset($this->parametres['recherche']) && $this->parametres['recherche'] != '') { |
| $this->recherche = $this->parametres['recherche']; |
| } |
| foreach ($this->parametres as $param => $valeur) { |
| switch ($param) { |
| case 'masque' : |
| $this->ajouterLeFiltreMasque('masque', $valeur); |
| break; |
| case 'masque.code' : |
| $this->ajouterLeFiltreMasque('codet', $valeur); |
| break; |
| case 'masque.nom' : |
| $this->ajouterLeFiltreMasque('nom', $valeur); |
| break; |
| case 'masque.statut' : |
| $this->ajouterLeFiltreMasque('codet_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 'recherche' : |
| 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); break; |
| } |
| } |
| } |
| } |
| public function ajouterLeFiltreMasque($nom_champ, $valeur) { |
| if ($nom_champ == 'codet') { |
| $this->requete_condition[] .= $nom_champ.' = '.$this->getBdd()->proteger($valeur); |
| } else { |
| if ($this->recherche == 'floue') { |
| if ($nom_champ == 'masque') { |
| $this->requete_condition[] = ' ( codet = '.$this->getBdd()->proteger($valeur) |
| .' OR (SOUNDEX(nom_francais) = SOUNDEX(\''.$valeur.'\')' |
| .' OR SOUNDEX(REVERSE(nom_francais)) = SOUNDEX(REVERSE(\''.$valeur.'\')) OR ' |
| .'SOUNDEX(nom_anglais) = SOUNDEX(\''.$valeur.'\')' |
| .' OR SOUNDEX(REVERSE(nom_anglais)) = SOUNDEX(REVERSE(\''.$valeur.'\'))) ' |
| .' OR ( SOUNDEX(codet_statut) = SOUNDEX(\''.$valeur.'\')' |
| .' OR SOUNDEX(REVERSE(codet_statut)) = SOUNDEX(REVERSE(\''.$valeur.'\')) ' |
| .')) '; |
| } elseif ($nom_champ == 'nom') { |
| $this->requete_condition[] = '(SOUNDEX(nom_francais) = SOUNDEX(\''.$valeur.'\')' |
| .' OR SOUNDEX(REVERSE(nom_francais)) = SOUNDEX(REVERSE(\''.$valeur.'\'))) OR |
| (SOUNDEX(nom_anglais) = SOUNDEX(\''.$valeur.'\')' |
| .' OR SOUNDEX(REVERSE(nom_anglais)) = SOUNDEX(REVERSE(\''.$valeur.'\'))) '; |
| } else { |
| $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 .= '%'; |
| } |
| if ($nom_champ == 'masque') { |
| $this->requete_condition[] = '(codet = '.$this->getBdd()->proteger($valeur) |
| .' OR nom_francais LIKE '.$this->getBdd()->proteger($valeur) |
| .' OR nom_anglais LIKE '.$this->getBdd()->proteger($valeur) |
| .' OR codet_statut LIKE '.$this->getBdd()->proteger($valeur).')'; |
| } elseif ($nom_champ == 'nom') { |
| $this->requete_condition[] = '(nom_francais LIKE '.$this->getBdd()->proteger($valeur).' OR ' |
| .'nom_anglais LIKE '.$this->getBdd()->proteger($valeur).') '; |
| } else { |
| $this->requete_condition[] = $nom_champ.' LIKE '.$this->getBdd()->proteger($valeur); |
| } |
| } |
| } |
| } |
| // +-----------------------------------------------------------------------------------------------------+ |
| public function traiterRessources() { |
| if (isset($this->ressources) && !empty($this->ressources)) { |
| $this->table_ressources = $this->ressources; |
| if (isset($this->table_ressources[0]) && !empty($this->table_ressources[0])) { |
| //requete = /zone-geo/#id |
| $this->traiterRessourceId(); |
| if (isset($this->table_ressources[1]) && !empty($this->table_ressources[1])) { |
| //requete = /zone-geo/#id/#champ ou /zone-geo/#id/relations |
| $this->traiterRessourceChampOuRelations(); |
| } |
| } |
| } |
| } |
| public function traiterRessourceId() { |
| //requete : /zone-geo/#id (ex : /zone-geo/7) |
| if ($this->table_ressources[0]) { |
| $this->requete_condition[] = ' codet = '.$this->getBdd()->proteger($this->table_ressources[0]); |
| $this->format_reponse .= '/id'; |
| } else { |
| $r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->table_ressources[0]. |
| ' " n\'existe pas.'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r); |
| } |
| } |
| public function traiterRessourceChampOuRelations() { |
| if ($this->table_ressources[1] == 'relations') { |
| $r = 'Erreur dans les ressources de votre requête : </br> La ressource " '.$this->table_ressources[1]. |
| ' " n\'existe pas.'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $r); |
| } else { |
| $this->format_reponse .= '/champ'; |
| } |
| } |
| // +-------------------------------------------------------------------------------------------------------------------+ |
| public function assemblerLaRequete() { |
| //assemblage de la requete : |
| $requete = ' SELECT '.$this->requete_champ. |
| ' FROM '.$this->table |
| .$this->formerRequeteCondition() |
| .$this->formerRequeteLimite(); |
| return $requete; |
| } |
| //ajout d'une limite seulement pour les listes (pas plus de 100 resultats retournés pr les requetes |
| // suivantes : /zone-geo et /zone-geo/#id/relations) |
| public function formerRequeteLimite() { |
| if ($this->format_reponse != 'zone-geo') { |
| $this->requete_limite = ''; |
| } elseif (($depart = $this->limite_requete['depart']) > ($this->total_resultat = $this->recupererTotalResultat())) { |
| //cas ou la requete presente un navigation.depart supérieur au nb total de resultats. |
| $this->limite_requete['depart'] = |
| (($nb - $this->limite_requete['limite']) < 0) ? 0 : ($nb - $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; |
| } |
| public function formerRequeteCondition() { |
| $condition = ''; |
| if ($this->requete_condition != null) { |
| $condition = ' WHERE '.implode(' AND ', $this->requete_condition); |
| } |
| return $condition; |
| } |
| public function recupererTotalResultat() { |
| //on récupère le nombre total de résultats de la requete (ex : le nombre d'id contenu dans la liste /zone-geo) |
| $requete = 'SELECT count(*) 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'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $t); |
| } |
| return $total; |
| } |
| // +-------------------------------------------------------------------------------------------------------------------+ |
| // determine en fct du service appelé (/zone-geo | /zone-geo/#id | /zone-geo/#id/champ | |
| // /zone-geo/#id/relations) le format du tableau à retourner. Encode en json |
| public function retournerResultatFormate($resultat) { |
| $this->recupererTableConfig('correspondance_champs'); |
| switch ($this->format_reponse) { |
| case 'zone-geo' : $reponse = $this->formaterZoneGeo($resultat); break; |
| case 'zone-geo/id' : $reponse = $this->formaterZoneGeoId($resultat[0]); break; |
| case 'zone-geo/id/champ' : $reponse = $this->formaterZoneGeoIdChamp($resultat[0]); break; |
| default : break; |
| } |
| return $reponse; |
| } |
| public function formaterZoneGeo($resultat) { |
| //on remplit la table $table_retour_json['entete'] |
| $this->table_retour['depart'] = $this->limite_requete['depart']; |
| $this->table_retour['limite'] = $this->limite_requete['limite']; |
| $this->table_retour['total'] = $this->total_resultat; |
| $url = $this->formulerUrl($this->total_resultat, '/zone-geo'); |
| if (isset($url['precedent']) && $url['precedent'] != '') { |
| $this->table_retour['href.precedent'] = $url['precedent']; |
| } |
| if (isset($url['suivant']) && $url['suivant'] != '') { |
| $this->table_retour['href.suivant'] = $url['suivant']; |
| } |
| $table_retour_json['entete'] = $this->table_retour; |
| //on remplit la table $table_retour_json['resultat'] |
| $this->table_retour = array(); |
| if (isset($this->table_param['masque_nom'])) $resultat = $this->trierRechercheFloue($this->table_param['masque_nom'], $resultat, 'nom_francais'); |
| foreach ($resultat as $tab) { |
| foreach ($tab as $key => $valeur) { |
| $valeur = rtrim($valeur); |
| if ($valeur != '') { |
| switch ($key) { |
| case 'codet' : $num = $valeur; $this->table_retour['code'] = $valeur; break; |
| case 'nom_francais' : $this->table_retour['nom'] = $valeur; break; |
| case 'nom_anglais' : if ($tab['nom_francais'] == '') $this->table_retour['nom'] = $valeur; break; |
| case 'codet_statut' : $this->table_retour['statut'] = $valeur; break; |
| default : break; |
| } |
| } |
| } |
| if ($this->retour_format == 'max') { |
| $this->table_retour['href'] = $this->ajouterHref('zone-geo', $num); |
| } |
| $resultat_json[$num] = $this->table_retour; |
| $this->table_retour = array(); |
| } |
| $table_retour_json['resultat'] = $resultat_json; |
| return $table_retour_json; |
| } |
| public function formaterZoneGeoId($resultat) { |
| foreach ($resultat as $key => $valeur) { |
| if ($valeur != '') { |
| $this->afficherDonnees($key, $valeur); |
| } |
| } |
| unset($this->table_retour['href']); |
| return $this->table_retour; |
| } |
| public function formaterZoneGeoIdChamp($resultat) { |
| //on recupère tous les resultats possibles |
| $reponse = $this->formaterZoneGeoId($resultat); |
| $this->table_retour = array(); |
| //on recupère les résultats demandés à partir du tableau de résultat complet |
| $this->table_retour['id'] = $reponse['code']; |
| $champs = explode(' ', $this->table_ressources[1]); |
| foreach ($champs as $champ) { |
| if ($champ == 'nom') $champ = 'nom.fr'; |
| if ($this->verifierValiditeChamp($champ)) { |
| if (strrpos($champ, '.*') !== false) { |
| $this->afficherPointEtoile($champ, $reponse); |
| } else { |
| if (isset($reponse[$champ])) { |
| $this->table_retour[$champ] = $reponse[$champ]; |
| } else { |
| $this->table_retour[$champ] = null; |
| } |
| } |
| } |
| } |
| return $this->table_retour; |
| } |
| public function verifierValiditeChamp($champ) { |
| preg_match('/^([^.]+)(\.([^.]+))?$/', $champ, $match); |
| $champs_possibles = $this->correspondance_champs; |
| $champs_possibles[] = 'nom.*'; |
| if (in_array($match[1], $champs_possibles)) { |
| $validite = true; |
| } elseif (in_array($match[0], $champs_possibles)) { |
| $validite = true; |
| } else { |
| $champs_possibles = implode('</li><li>', $champs_possibles); |
| $c = 'Erreur dans votre requête : </br> Le champ "'.$champ_possibles.'" n\'existe pas. '. |
| 'Les champs disponibles sont : <li>'.$champs_possibles.'</li>'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $c); |
| } |
| return $validite; |
| } |
| public function afficherPointEtoile($champ, $reponse) { |
| preg_match('/^([^.]+\.)\*$/', $champ, $match); |
| foreach ($reponse as $chp => $valeur) { |
| if (strrpos($chp, $match[1]) !== false) { |
| if ($valeur != '') { |
| $this->table_retour[$chp] = $valeur; |
| } else { |
| $this->table_retour[$chp] = null; |
| } |
| } |
| } |
| } |
| public function afficherDonnees($champ, $valeur) { |
| if ($this->retour_format == 'max') { |
| if ($champ == 'codet_statut') { |
| $this->table_retour[$this->correspondance_champs[$champ]] = $valeur; |
| $this->table_retour[$this->correspondance_champs[$champ].'.href'] = |
| $this->ajouterHref('ontologies', 'masque.nom=Codet '.$valeur, '?'); |
| } else { |
| $this->table_retour[$this->correspondance_champs[$champ]] = $valeur; |
| } |
| } else { |
| $this->table_retour[$this->correspondance_champs[$champ]] = $valeur; |
| } |
| } |
| // +-------------------------------------------------------------------------------------------------------------------+ |
| /** Permet de retourner l'url http://tela-botanica.org/service:eflore:0.1/[projet]/[version_projet]/[service]/[ressource]:[valeur] |
| * @param $service : correspond au nom de la ressource à laquelle on souhaite acceder |
| * @param $val : correspond au paramètre de la ressource (ex : |
| * @param $projet : est remplit dans les cas suivants : |
| * - si le projet dans lequel se trouve l'information est différent de celui du service appelé |
| * - si on souhaite rappeler le meme projet avec la meme ressource mais un parametre de ressource différent |
| */ |
| public function ajouterHref($service, $val, $separation = '/') { |
| $val = $this->encoderUrl($val); |
| if ($this->version_projet == '+') { |
| $url = Config::get('url_service_base').Config::get('nom_projet').'/'.$service.$separation.$val; |
| } else { |
| $url = Config::get('url_service_base').Config::get('nom_projet').'/'.$this->version_projet.'/'.$service.$separation.$val; |
| } |
| return $url; |
| } |
| public function encoderUrl($url) { |
| $url = str_replace(' ', '%20', $url); |
| $url = str_replace('?', urlencode('?'), $url); |
| return $url; |
| } |
| } |
| ?> |
| /branches/refact/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¶m2=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; |
| } |
| } |
| } |
| ?> |
| /branches/refact/services/modules/0.1/baseflor/GraphiquesBaseflor.php |
|---|
| New file |
| 0,0 → 1,119 |
| <?php |
| /** |
| * Classe GraphiquesBaseflor.php transforme les données écologiques de la table baseflor |
| * 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 GraphiquesBaseflor extends CommunGraphiques{ |
| public function definirTable($version){ |
| $this->table = Config::get('bdd_table')."_v".$version; |
| } |
| //+--------------------------traitement ressources ou paramètres -------------------------------------------+ |
| public function traiterReferentieletNum(){ |
| if (!empty($this->ressources[1])) { |
| if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[1], $retour) == 1){ |
| switch ($retour[1]) { |
| case 'bdtfx' : |
| $this->requete_condition[]= "num_nomen = ".$retour[2]." AND bdnt = 'bdtfx' "; |
| break; |
| case 'bdafx' : |
| $this->requete_condition[] = "num_nomen = ".$retour[2]." AND bdnt = 'bdafx' "; |
| break; |
| case 'bdbfx' : |
| $this->requete_condition[] = "num_nomen = ".$retour[2]." AND bdnt = 'bdbfx' "; |
| 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 , ve_temperature, ve_continentalite, ve_humidite_atmos' ; |
| $this->nomGraphique= 'climat'; |
| break; |
| case 'sol' : |
| $this->requete_champs = ' ve_humidite_edaph , ve_reaction_sol, ve_nutriments_sol, ve_salinite,' |
| .'ve_texture_sol, ve_mat_org_sol' ; |
| $this->nomGraphique = 'sol'; |
| break; |
| default : |
| $e = "Erreur dans l'url de votre requête :". |
| "</br> precisez 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 -------------------------------------------+ |
| /// ++++ svg +++++ /// |
| public function changerValeursSVG(){ |
| $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); |
| $element = $Dompath->query("//*[@id='".$grad_id."']")->item(0); |
| $pos_x = $element->getAttribute('x1'); |
| $curseur = $Dompath->query("//*[@id='".$cle."']")->item(0); |
| $curseur->setAttribute('cx', $pos_x); |
| $curseur->setAttribute('class', 'curseur'); |
| $this->ajouterInfoAuSurvol($curseur); |
| $changement = true; |
| } |
| $this->ajusterFormatSVG(); |
| } |
| public function ajouterInfoAuSurvol($curseur){ |
| $champs = $curseur->getAttribute('id'); |
| $valeurTexte = $this->recupererOntologies($this->valeurs_champs[$champs], $champs ); |
| $valeurTexte = $this->traiterIntermediaires($valeurTexte->nom, $champs, $champs); |
| $curseur->setAttribute('title',$this->valeurs_champs[$champs].": ".$valeurTexte ); |
| } |
| } |
| ?> |
| /branches/refact/services/modules/0.1/baseflor/InformationsBaseflor.php |
|---|
| New file |
| 0,0 → 1,520 |
| <?php |
| /** |
| * Classe InformationsBaseflor.php permet de faire des requetes de baseflor en fonction d'un référentiel |
| *( BDTFX, BDAFX, BDBFX ) et d'un numéro nomenclatural ( différent de 0 ). |
| * fin d'url possibles : |
| * /informations/#bdnt.nn:#num_nomen --> retourne tous les champs pour un BDNT et un num_nomen |
| * /informations/#bdnt.nn:#num_nomen?champs=description --> retourne champs description pour un BDNT et un num_nomen |
| * /informations/#bdnt.nn:#num_nomen?champs=ecologie --> retourne champs ecologiques pour un BDNT et un num_nomen |
| * /informations/#bdnt.nn:#num_nomen/relations/catminat --> donne les num nomen et les bdnt pour tous |
| * les taxons qui ont le même code catminat ( code milieu ) que celui entré |
| * |
| * 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-2012 Tela Botanica (accueil@tela-botanica.org) |
| */ |
| class InformationsBaseflor extends Commun{ |
| protected $table = ""; |
| private $format_reponse = 'informations'; |
| private $retour_format = 'max'; |
| private $champs_ontologiques = array(); |
| protected $serviceNom = 'informations'; |
| private $Bdd; |
| private $requete_condition = ""; |
| private $champs_recherches = '*'; |
| private $resultat_json; |
| private $nb_ressources; |
| protected $limite_requete = array( 'depart' => 0, 'limite' => 10); |
| public function consulter($ressources, $parametres) { |
| $this->ressources = $ressources; |
| $this->parametres = $parametres; |
| $this->nb_ressources = count($ressources); |
| $this->traiterParametres(); |
| $this->definirTables(); |
| $this->traiterRessources(); |
| $resultats = null; |
| 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 __construct(Conteneur $Conteneur) { |
| $this->Bdd = $Conteneur->getBdd(); |
| } |
| 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; |
| } |
| //+--------------------------traitement ressources ou paramètres -------------------------------------------+ |
| public function traiterParametres() { |
| if (isset($this->parametres) && !empty($this->parametres)) { |
| foreach ($this->parametres as $param => $valeur) { |
| switch ($param) { |
| case 'categorie' : |
| if ($valeur == "description" && $this->nb_ressources == 1 ) { |
| $this->champs_recherches = "num_nomen, BDNT, chorologie, inflorescence," |
| ." sexualite, ordre_maturation, " |
| ."pollinisation, fruit, dissemination, couleur_fleur, macule, floraison, type_bio, " |
| ."form_vegetale "; |
| $this->requete_condition[] = "( chorologie != '' OR inflorescence != '' ". |
| "OR sexualite != '' OR ordre_maturation != '' OR pollinisation != '' ". |
| "OR fruit != '' OR dissemination != '' OR couleur_fleur != '' OR macule != '' ". |
| "OR floraison != '' OR type_bio != '' OR form_vegetale != '' )"; |
| }elseif ($valeur == "ecologie" && $this->nb_ressources == 1) { |
| $this->champs_recherches = " num_nomen, BDNT, ve_lumiere , ve_temperature," |
| ." ve_continentalite, ve_humidite_atmos, ve_humidite_edaph, ve_reaction_sol," |
| ." ve_nutriments_sol, ve_salinite, ve_texture_sol, ve_mat_org_sol, " |
| ." vi_lumiere, vi_temperature, vi_continentalite, vi_humidite_edaph," |
| ." vi_reaction_sol, vi_nutriments_sol, vi_salinite "; |
| $this->requete_condition[] = "( ve_lumiere != '' OR ve_temperature != '' ". |
| "OR ve_continentalite != '' OR ve_humidite_atmos != '' ". |
| "OR ve_humidite_edaph != '' OR ve_reaction_sol != '' ". |
| "OR ve_nutriments_sol != '' OR ve_salinite != '' ". |
| "OR ve_texture_sol != '' OR ve_mat_org_sol != '' )"; |
| } else { |
| $e = "Valeur de paramètre inconnue pour 'categorie'. Ce paramètre n'est pas autorisé pour informations/#id/relations/catminat"; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| break; |
| case 'retour.format' : |
| if ($valeur == 'min' || $valeur == 'max' && $this->nb_ressources == 1) { |
| $this->retour_format = $valeur; |
| } else { |
| $e = "Valeur de paramètre inconnue pour 'retour.format'. Ce paramètre n'est pas autorisé pour informations/#id/relations/catminat"; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| break; |
| 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; |
| } |
| } |
| } |
| } |
| public function traiterRessources() { |
| if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){ |
| $id = $retour[2]; |
| $ref = $retour[1]; |
| if ($ref == 'bdtfx' || $ref == 'bdafx' || $ref == 'bdbfx') { |
| if($this->nb_ressources == 1) { |
| $this->requete_condition[] = "num_nomen = ".$id." AND BDNT = '".strtoupper($ref)."' "; |
| } else { |
| $this->definirParametresRequeteRelations($ref, $id); |
| } |
| } else { |
| $e = 'Erreur dans l\'url de votre requête : </br> Le référentiel " ' |
| .$ref.' " n\'existe pas.'; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| } else { |
| $e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.'; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| } |
| function definirParametresRequeteRelations($ref, $id){ |
| if ($this->ressources[1] == 'relations'){ |
| switch ($this->ressources[2]) { |
| case 'catminat' : |
| $this->requete_condition[] = "catminat_code = ( SELECT catminat_code from ".$this->table_version[0]." WHERE " |
| ." num_nomen = ".$id." AND BDNT = '".$ref. "' ) AND num_nomen != ".$id." "; |
| $this->champs_recherches = " catminat_code, num_nomen, BDNT, idiotaxon "; |
| break; |
| default : |
| $e = 'Erreur dans l\'url de votre requête : </br> Le type de relation " ' |
| .$this->ressources[2].' " n\'existe pas.'; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| break; |
| } |
| } else { |
| $e = 'Erreur dans l\'url de votre requête : </br> Le type de ressources " ' |
| .$this->ressources[1].' " n\'existe pas.'; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| } |
| //+++------------------------------traitement des versions----------------------------------------++ |
| public function traiterVersion($valeur) { |
| if (preg_match('/^[0-9]+(?:[._][0-9]+)*$/', $valeur) || $valeur == '+') { |
| $this->version_projet = $valeur; |
| } elseif ($valeur == '*') { |
| $this->version_projet = ($this->nb_ressources == 1) ? $valeur : '+' ; |
| } else { |
| $e = "Erreur : La version est inconnue."; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| } |
| public function definirTables() { |
| $table_num_version = $this->recupererVersionDisponible(); |
| $prefixe_table = config::get('bdd_table'); |
| 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) { |
| $resultat_json = $resultat[0]; |
| if ($this->retour_format == 'max'){ |
| if ($this->nb_ressources == 1) { |
| if ($this->parametres['categorie'] == 'ecologie') { |
| $this->formaterResultatsChampsEcologie($resultat_json); |
| } elseif ($this->parametres['categorie'] == 'description') { |
| $this->formaterResultatsChampsDescription($resultat_json); |
| }else { |
| $this->formaterResultatsTousChamps($resultat_json); |
| } |
| } else { |
| $this->formaterResultatsRelations($resultat); |
| } |
| } else { |
| $this->resultat_json = $resultat_json; |
| } |
| return $this->resultat_json; |
| } |
| public function formaterResultatsRelations($resultat) { |
| $this->resultat_json['entete'] = $this->ajouterEnteteResultat(); |
| $resultat_json = array(); |
| foreach ($resultat as $cle => $res){ |
| $resultat_json[$cle] = $res ; |
| $resultat_json[$cle]['href'] = $this->ajouterHref('informations',strtolower($res['BDNT']).".nn:".$res['num_nomen']); |
| } |
| $this->resultat_json['resultat'] = $resultat_json; |
| } |
| public function ajouterEnteteResultat() { |
| $entete['depart'] = $this->limite_requete['depart']; |
| $entete['limite'] = $this->limite_requete['limite']; |
| $entete['total'] = $this->total_resultat; |
| $entete['version'] = $this->version_projet; |
| if ($this->limite_requete['limite'] != '*') { |
| $url = $this->formulerUrl($this->total_resultat, '/informations/'.$this->ressources[0].'/relations/catminat'); |
| if (isset($url['precedent']) && $url['precedent'] != '') { |
| $entete['href.precedent'] = $url['precedent']; |
| } |
| if (isset($url['suivant']) && $url['suivant'] != '') { |
| $entete['href.suivant'] = $url['suivant']; |
| } |
| } |
| return $entete; |
| } |
| public function formaterResultatsTousChamps($resultat) { |
| $this->resultat_json = $resultat; |
| $this->traiterTypeBio(); |
| $graphique_presence = $this->traiterEcologie() ; |
| if ($graphique_presence) { |
| $graphique = $this->ajouterLiensGraphique($graphique_presence); |
| } |
| } |
| public function formaterResultatsChampsEcologie($resultat) { |
| $this->resultat_json = $resultat; |
| $graphique_presence = $this->traiterEcologie() ; |
| if ($graphique_presence) { |
| $graphique = $this->ajouterLiensGraphique($graphique_presence); |
| } |
| } |
| public function formaterResultatsChampsDescription($resultat) { |
| $this->resultat_json = $resultat; |
| $this->traiterTypeBio(); |
| } |
| //vérifie la présence de données écologiques pour les graphiques et récupère leur ontologie |
| public function traiterEcologie() { |
| $donnees_presence = false; |
| $this->champs_ontologiques = $this->recupererTableauConfig('champs_ontologiques'); |
| foreach ($this->champs_ontologiques as $cle => $valeur){ |
| if ($this->resultat_json[$cle] != ""){ |
| $donnees_presence[$this->getNomGraphique($valeur)] = true; |
| $this->recupererOntologies($this->resultat_json[$cle], $cle); |
| unset($this->resultat_json[$cle]); |
| } |
| } |
| 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 traiterTypeBio() { |
| if ($this->resultat_json['type_bio'] != ""){ |
| $tab_ontologie = $this->recupererOntologiePrTypeBio($this->resultat_json['type_bio']); |
| unset($this->resultat_json['type_bio']); |
| $this->resultat_json= array_merge($this->resultat_json,$tab_ontologie); |
| } |
| } |
| 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){ |
| $url = Config::get('url_service_base').Config::get('nom_projet'). |
| '/ontologies/'.$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)); |
| $val = $this->consulterHref($url); |
| $this->resultat_json[$champs.'.libelle'] = $val->nom; |
| $this->resultat_json[$champs.'.code'] = $valeur; |
| $this->resultat_json[$champs.'.href'] = $url; |
| } |
| //+-------------ontologie pour le champs type biologique (lire le .txt)---+ |
| public function recupererOntologiePrTypeBio($type_a_traiter){ |
| $resultat_typeBio = ""; |
| if ($type_a_traiter != "") { |
| $types_prim_sec = $this->separerTypesPrimairesSecondaires($type_a_traiter); |
| $types_sstypes = $this->classerPrimSecEnTypesSsTypes($types_prim_sec); |
| $resultat_typeBio = $this->formaterJsonTypeBio($types_sstypes, $type_a_traiter ); |
| } |
| return $resultat_typeBio; |
| } |
| public function classerPrimSecEnTypesSsTypes($types_prim_sec) { |
| $types_sstypes = ''; |
| foreach ($types_prim_sec as $cle => $tb) { |
| $types_sstypes[$cle]= $this->separerTypes_SousTypes($tb, $cle); |
| } |
| switch (count($types_sstypes)) { |
| case 1 : |
| $types_sstypes = $types_sstypes['principal']; |
| break; |
| case 2 : |
| $types_sstypes = array_merge($types_sstypes['principal'],$types_sstypes['secondaire']); |
| break; |
| } |
| return $types_sstypes; |
| } |
| public function formaterJsonTypeBio( $types_sstypes, $type_a_traiter) { |
| $resultat_typeBio['type_bio.code'] = $type_a_traiter; |
| foreach ($types_sstypes as $cle => $tb) { |
| if (($cle == 'type.principal') || ($cle == 'type.secondaire')) { |
| $i = 0; |
| foreach ($tb as $types) { |
| $url = Config::get('url_service_base').Config::get('nom_projet'). |
| '/ontologies/TB:'.urlencode(urlencode($types)); |
| $val = $this->consulterHref($url); |
| $libelle[$cle][$i]= $val->nom; |
| $detail[$cle][$i]['libelle'] = $val->nom; |
| $detail[$cle][$i]['code'] = $val->code; |
| $detail[$cle][$i]['href'] = $url; |
| $i++; |
| } |
| } |
| if ($cle == 'sous_type.principal' || $cle == 'sous_type.secondaire' ) { |
| $i = 0; |
| foreach ($tb as $sstypes) { |
| $url = Config::get('url_service_base').Config::get('nom_projet'). |
| '/ontologies/ssTT:'.urlencode(urlencode($sstypes)); |
| $val = $this->consulterHref($url); |
| $libelle[$cle][$i]=$val->nom; |
| $detail[$cle][$i]['libelle'] = $val->nom; |
| $detail[$cle][$i]['code'] = $val->code; |
| $detail[$cle][$i]['href'] = $url; |
| $i++; |
| } |
| } |
| } |
| //var_dump($libelle); exit; |
| $resultat_typeBio['type_bio.libelle']= $this->formaterTypeBioPrLibelle($libelle); |
| $resultat_typeBio['type_bio.detail'] = $detail; |
| return $resultat_typeBio; |
| } |
| public function formaterTypeBioPrLibelle($info) { |
| $libelle = implode(', ',$info['type.principal'])." "; |
| $libelle .= isset($info['sous_type.principal']) ? " (".implode(', ',$info['sous_type.principal']).") " : ""; |
| $libelle .= isset($info['type.secondaire']) ? ", ".implode(', ',$info['type.secondaire'])." " : ""; |
| $libelle .= isset($info['sous_type.secondaire']) ? "(".implode(', ',$info['sous_type.secondaire']).") " : ""; |
| return $libelle; |
| } |
| //séparation des principaux et des secondaires |
| public function separerTypesPrimairesSecondaires($type) { |
| $types = array(); |
| if (preg_match("/(.+)\((.+)\)\-{0,1}(.+){0,1}/", $type,$retour)) { |
| $types['principal'] = isset($retour[3]) ? $retour[1].'-'. $retour[3] : $retour[1] ; |
| $types['secondaire'] = $retour[2]; |
| } else { |
| $types['principal'] = $type; |
| } |
| return $types; |
| } |
| public function separerTypes_SousTypes($type_a_traiter, $typePrimOuSec) { |
| $types = array(); |
| if (preg_match("/^([a-zA-Zé]+)\-(.+)$|^([a-zA-Zé,]+[^\-])$/", $type_a_traiter, $retour)) { |
| //type |
| $type = array(); |
| $type[0] = (isset($retour[3])) ? $retour[3] : $retour[1] ; |
| $type = explode(",", $type[0]); |
| for ($i = 0 ; $i < count($type); $i++) { |
| $types['type.'.$typePrimOuSec][$i] = $type[$i]; |
| } |
| //sous types |
| $ss_types = array(); |
| if (isset($retour[2]) && $retour[2] != '') { |
| $ss_types[0] = $retour[2] ; |
| $ss_types = explode("-", $ss_types[0]); |
| for ($i = 0 ; $i < count($ss_types); $i++) { |
| $types['sous_type.'.$typePrimOuSec][$i] = $ss_types[$i]; |
| } |
| } |
| } |
| return $types; |
| } |
| //+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+ |
| public function assemblerLaRequete() { |
| $requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->table.' ' |
| .$this->retournerRequeteCondition().' '; |
| if ($this->nb_ressources != 1 ) { |
| $requete .= $this->delimiterResultatsRequete(); |
| } |
| return $requete; |
| } |
| public function calculerTotalResultat() { |
| $requete = 'SELECT count(*) as nombre FROM '.$this->table.' '.$this->retournerRequeteCondition(); |
| $res = $this->getBdd()->recuperer($requete); |
| if ($res) { |
| $this->total_resultat = $res['nombre']; |
| } else { |
| $this->total_resultat = 0; |
| $e = 'Données introuvables dans la base'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e); |
| } |
| } |
| public function delimiterResultatsRequete() { |
| $this->calculerTotalResultat(); |
| $requete_limite = ''; |
| if ($this->limite_requete['limite'] != '*') { |
| if ( ($this->limite_requete['depart'] <= $this->total_resultat)){ |
| if (($this->limite_requete['limite'] + $this->limite_requete['depart'] ) |
| < $this->total_resultat ){ |
| $requete_limite = 'LIMIT '.$this->limite_requete['depart'].', ' |
| .$this->limite_requete['limite']; |
| } |
| } else { |
| $e = "Erreur : la valeur pour le paramètre navigation.départ est supérieure". |
| " au nombre total de résultats."; |
| throw new Exception($e, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE); |
| } |
| } |
| return $requete_limite; |
| } |
| public function retournerRequeteCondition() { |
| $condition = ''; |
| if (empty($this->requete_condition) == false) { |
| $condition = ' WHERE '.implode(' AND ', $this->requete_condition); |
| } |
| return $condition; |
| } |
| } |
| ?> |
| /branches/refact/services/modules/0.1/baseflor/CommunGraphiques.php |
|---|
| New file |
| 0,0 → 1,391 |
| <?php |
| /** |
| * Classe CommunGraphiques.php regroupement de fonctions pour les graphiques |
| * 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) |
| */ |
| abstract class CommunGraphiques extends Commun{ |
| protected $parametres = array(); |
| protected $ressources = array(); |
| protected $Bdd; |
| protected $config; |
| protected $cache; |
| protected $metadonnees; |
| protected $version; |
| protected $serviceNom = 'Graphiques'; |
| protected $graduations_id = array(); |
| protected $champs_ontologiques = array(); |
| protected $nomGraphique = array(); |
| protected $table = ''; |
| protected $requete_condition = ""; |
| protected $requete_champs; |
| protected $convertisseur; |
| protected $cheminGraphBase; |
| protected $valeurs_en_pourcentage = array(); |
| protected $dom; |
| protected $largeurSVG = "500"; |
| protected $hauteurSVG; |
| protected $valeurs_champs; |
| public function consulter($ressources, $parametres) { |
| $this->ressources = $ressources; |
| $this->parametres = $parametres; |
| $this->verifierParametres(); |
| $this->initialiserConfiguration(); |
| $resultats = ''; |
| $this->traiterRessources(); |
| $requete = $this->assemblerLaRequete(); |
| $resultat = $this->resultat = $this->Bdd->recupererTous($requete); |
| $versionResultat = $this->obtenirResultat($resultat); |
| return $versionResultat; |
| } |
| //+--------------------------initialisation de paramètres -------------------------------------------+ |
| private function initialiserConfiguration() { |
| $conteneur = new Conteneur(); |
| $this->Bdd = $conteneur->getBdd(); |
| $this->config = $conteneur->getParametre('Graphiques'); |
| $this->convertisseur = $this->config['convertisseur']; |
| $this->graduations_id = $this->getParametreTableau('graduations_id'); |
| $this->champs_ontologiques = $this->getParametreTableau('champs_ontologiques'); |
| $this->cheminGraphBase = $this->config['chemin']; |
| $cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'], |
| 'stockage_chemin' => $this->config['cache']['stockageChemin'], |
| 'duree_de_vie' => $this->config['cache']['dureeDeVie']); |
| $this->cache = $conteneur->getCacheSimple($cacheOptions); |
| $this->definirVersion(); |
| $this->definirFormat(); |
| $this->definirTable($this->version); |
| } |
| abstract function definirTable($version); |
| private function getParametreTableau($cle) { |
| $tableau = array(); |
| $parametre = Config::get($cle); |
| if (empty($parametre) === false) { |
| $tableauPartiel = explode(',', $parametre); |
| $tableauPartiel = array_map('trim', $tableauPartiel); |
| foreach ($tableauPartiel as $champ) { |
| if (strpos($champ, '=') !== false && strlen($champ) >= 3) { |
| list($cle, $val) = explode('=', $champ); |
| $tableau[trim($cle)] = trim($val); |
| } else { |
| $tableau[] = trim($champ); |
| } |
| } |
| } |
| return $tableau; |
| } |
| //+--------------------------traitement ressources ou paramètres -------------------------------------------+ |
| //+---- paramètres ----+ |
| private function verifierParametres() { |
| if (isset($this->parametres)) { |
| $parametres_dispo = array('retour', 'retour.format', 'version.projet'); |
| $parametres = array_keys($this->parametres); |
| foreach ($parametres as $param) { |
| if (!in_array($param, $parametres_dispo)) { |
| $erreur = "Erreur : Le paramètre $param est inconnu."; |
| $code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
| throw new Exception($erreur, $code); |
| } |
| } |
| } |
| } |
| //on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée ) |
| private function definirVersion() { |
| $this->chargerVersions(); |
| if (!isset($this->parametres['version.projet']) ) { |
| $this->version = $this->metadonnees[0]['version']; |
| } elseif ($this->parametres['version.projet'] == '+') { |
| $this->version = $this->metadonnees[0]['version']; |
| } else { |
| if($this->verifierVersion($this->parametres['version.projet'])) { |
| $this->version = $this->parametres['version.projet']; |
| }else { |
| $erreur = "Erreur : La version est inconnue."; |
| $code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
| throw new Exception($erreur, $code); |
| } |
| } |
| } |
| private function verifierVersion($version){ |
| $retour = false; |
| foreach ($this->metadonnees as $vers) { |
| if ($vers['version'] == $version ) { |
| $retour = true; |
| } |
| } |
| return $retour; |
| } |
| private function definirFormat() { |
| if (isset($this->parametres['retour.format']) ){ |
| if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){ |
| if ($this->parametres['retour.format'] > 0) { |
| $this->largeurSVG = $this->parametres['retour.format']; |
| } else { |
| $erreur = "Erreur : valeur pour retour.format négative ou égale à 0."; |
| $code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
| throw new Exception($erreur, $code); |
| } |
| }else { |
| $erreur = "Erreur : valeur inconnue. Entrez la largeur voulue (en pixels) pour le paramètre retour.format."; |
| $code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
| throw new Exception($erreur, $code); |
| } |
| } |
| if (!isset($this->parametres['retour']) ){ |
| $this->parametres['retour'] = 'image/svg+xml'; |
| }else { |
| if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){ |
| $erreur = "Erreur : valeur inconnue. Choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png."; |
| $code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE; |
| throw new Exception($erreur, $code); |
| } |
| } |
| } |
| private function chargerVersions() { |
| $requete = "SELECT version ". |
| "FROM ".Config::get('bdd_table_meta')." ". |
| "ORDER BY date_creation DESC "; |
| $resultats = $this->Bdd->recupererTous($requete); |
| if (!is_array($resultats) || count($resultats) <= 0) { |
| $message = "Les méta-données n'ont pu être chargée pour la ressource demandée"; |
| $code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
| throw new Exception($message, $code); |
| } |
| $this->metadonnees = $resultats; |
| } |
| //+----- ressources -----+ |
| public function traiterRessources() { |
| if(isset($this->ressources)) { |
| $this->traiterTypeGraphique(); |
| $this->traiterReferentielEtNum(); |
| } else { |
| $e = 'Erreur dans l\'url de votre requête : </br> ressources insuffisantes.'; |
| throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| } |
| abstract function traiterReferentielEtNum(); |
| abstract function traiterTypeGraphique(); |
| //+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+ |
| public function assemblerLaRequete() { |
| $requete = ' SELECT '.$this->requete_champs.' FROM '.$this->table.' '.$this->retournerRequeteCondition(); |
| return $requete; |
| } |
| public function retournerRequeteCondition() { |
| $condition = ''; |
| if ($this->requete_condition !== "") { |
| $condition = ' WHERE '.implode(' AND ', $this->requete_condition); |
| } |
| return $condition; |
| } |
| //+-------------------------- formatage du résultat -------------------------------------------+ |
| public function obtenirResultat($resultat) { |
| 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) { |
| if ((count($this->ressources)) != 0) { |
| //$Atraiter = array_filter($resultat[0],function($var){return ($var != '');}); |
| foreach ($resultat[0] as $champs => $valeur) { |
| if ($valeur !== '') { |
| $Atraiter[$champs] = $valeur; |
| } |
| } |
| if (!empty($Atraiter)) { |
| $this->traiterValeursEcologiques($Atraiter); |
| $svg = $this->genererSVG(); |
| $resultat = new ResultatService(); |
| $resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg; |
| $resultat->mime = $this->parametres['retour']; |
| } else { |
| $resultat = null; |
| } |
| } |
| } else { |
| $resultat = null; |
| } |
| return $resultat; |
| } |
| //+----- modification svg -----+ |
| public function traiterValeursEcologiques($valeur){ |
| $this->valeurs_champs = $valeur; |
| foreach($this->valeurs_champs as $cle => $val){ |
| if (preg_match("/ve_humidite_edaph/", $cle)) { |
| $this->valeurs_en_pourcentage[$cle] = round($val/13,1); |
| } elseif (preg_match("/ve_salinite/", $cle)) { |
| $this->valeurs_en_pourcentage[$cle] = round(($val+1)/11,1); |
| } else { |
| $this->valeurs_en_pourcentage[$cle] = round($val/10,1); |
| } |
| } |
| } |
| public function donnerHauteur($ancienne_largeur, $ancienne_hauteur) { |
| $nouvelle_largeur = $this->largeurSVG; |
| $ancienne_largeur = str_replace('px','',$ancienne_largeur); |
| $ancienne_hauteur = str_replace('px','',$ancienne_hauteur); |
| $rapport = $nouvelle_largeur / $ancienne_largeur ; |
| $nouvelle_hauteur = $ancienne_hauteur * $rapport; |
| $this->hauteurSVG = $nouvelle_hauteur; |
| } |
| public function ajusterFormatSVG(){ |
| $svg = $this->dom->getElementsByTagName("svg")->item(0); |
| $largeur = $svg->getAttribute('width'); |
| $hauteur = $svg->getAttribute('height'); |
| $this->donnerHauteur($largeur , $hauteur); |
| $svg->setAttribute('width',round($this->largeurSVG).'px'); |
| $svg->setAttribute('height',round($this->hauteurSVG).'px'); |
| } |
| public function genererSVG(){ |
| $svg = null; |
| $this->dom = new DOMDocument('1.0', 'UTF-8'); |
| $this->dom->validateOnParse = true; |
| $fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg"; |
| $this->dom->load($fichierSvg); |
| $this->changerValeursSVG(); |
| $svg = $this->dom->saveXML(); |
| return $svg; |
| } |
| abstract function changerValeursSVG(); |
| public function recupererOntologies($valeur, $champs){ |
| $url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur))); |
| $val = $this->consulterHref($url); |
| return $val; |
| } |
| public function traiterIntermediaires($valeurTexte,$champsOntologie, $champsTable){ |
| if (preg_match("/(?:I|i)nterm(?:é|e)diaire(?:s)*/", $valeurTexte )) { |
| $prec = $this->recupererOntologies(($this->valeurs_champs[$champsTable]-1), $champsOntologie ); |
| $suiv = $this->recupererOntologies(($this->valeurs_champs[$champsTable]+1), $champsOntologie ); |
| $valeurTexte = "Intermédiaires entre $prec->nom et $suiv->nom "; |
| } |
| return $valeurTexte; |
| } |
| /// +---- convertir png ----+ |
| public function convertirEnPNG($svg) { |
| $png = null; |
| if (isset($this->convertisseur)) { |
| if ($this->convertisseur == 'imagick') { |
| if (extension_loaded('imagick')) { |
| $png = $this->convertirEnPNGAvecImageMagick($svg); |
| } else { |
| $message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente."; |
| $code = RestServeur::HTTP_CODE_ERREUR; |
| throw new Exception($message, $code); |
| } |
| } else if ($this->convertisseur == 'rsvg') { |
| $png = $this->convertirEnPNGAvecRsvg($svg); |
| } else { |
| $message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ". |
| "des convertisseurs disponibles : imagick, rsvg."; |
| $code = RestServeur::HTTP_CODE_ERREUR; |
| throw new Exception($message, $code); |
| } |
| } else { |
| $message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service."; |
| $code = RestServeur::HTTP_CODE_ERREUR; |
| throw new Exception($message, $code); |
| } |
| return $png; |
| } |
| public function convertirEnPNGAvecImageMagick($svg) { |
| $convertisseur = new Imagick(); |
| $convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8')); |
| $convertisseur->readImageBlob($svg); |
| $convertisseur->setImageFormat('png32'); |
| $convertisseur->resizeImage($this->largeurSVG,$this->hauteurSVG, imagick::FILTER_LANCZOS, 0, true); |
| $png = $convertisseur->getImageBlob(); |
| $convertisseur->clear(); |
| $convertisseur->destroy(); |
| return $png; |
| } |
| public function convertirEnPNGAvecRsvg($svg) { |
| $idFichier = $this->getIdFichier(); |
| $fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png'; |
| $fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg'; |
| file_put_contents($fichierSvg, $svg); |
| $commande = "rsvg-convert $fichierSvg -w ".$this->largeurSVG ." -h ".$this->hauteurSVG ." -o $fichierPng"; |
| //echo $commande; exit; |
| $rsvg = exec($commande); |
| $this->indexerFichierPng($fichierPng); |
| $png = file_get_contents($fichierPng); |
| return $png; |
| } |
| public function indexerFichierPng($fichierPng) { |
| $img = imagecreatefrompng($fichierPng); |
| imagetruecolortopalette($img, false, 32); |
| imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS); |
| } |
| public function getIdFichier(){ |
| $idfichier = str_replace(".","-",$this->ressources[1]); |
| $idfichier = str_replace(':','-',$idfichier); |
| $idfichier .= "-".$this->ressources[0]; |
| return $idfichier; |
| } |
| } |
| ?> |
| /branches/refact/services/modules/0.1/baseflor/Graphiques.php |
|---|
| New file |
| 0,0 → 1,42 |
| <?php |
| /** |
| * Classe Graphiques.php détermine le type de graphiques à afficher en fonction des données des tables |
| * baseflor et baseflor_rang_sup_ecologie |
| * fin d'url possibles : |
| * graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie une 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 Graphiques extends Commun{ |
| private $Graph_tables = array('GraphiquesBaseflor', 'GraphiquesTaxonsSup'); |
| public function consulter($ressources, $parametres) { |
| $versionResultat = null; |
| foreach ($this->Graph_tables as $graph_tab) { |
| $Graph = new $graph_tab(); |
| $versionResultat = $Graph->consulter($ressources, $parametres); |
| if($versionResultat != null) {break;} |
| } |
| if ($versionResultat == null) { |
| $message = 'Les données recherchées sont introuvables.'; |
| $code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
| throw new Exception($message, $code); |
| } |
| return $versionResultat; |
| } |
| } |
| ?> |
| /branches/refact/services/modules/0.1/baseflor/Informations.php |
|---|
| New file |
| 0,0 → 1,282 |
| <?php |
| /** |
| * Classe Informations.php interroge la table Index |
| * et redirige vers une autre classe si besoin |
| * d'interroger une autre table (comme baseflor ou baseflor_rang_sup) |
| * elle traite également le retour du web service : /informations |
| * |
| * Encodage en entrée : utf8 |
| * Encodage en sortie : utf8 |
| * @package eflore-projets |
| * @author Mathilde SALTHUN-LASSALLE <mathilde@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-2012 Tela Botanica (accueil@tela-botanica.org) |
| * |
| * |
| */ |
| class Informations extends Commun { |
| protected $limite_requete = array( 'depart' => 0, 'limite' => 10); |
| private $tables; |
| private $champs_recherches = '*'; |
| private $requete_jointure = ""; |
| private $requete_condition = ""; |
| private $total_resultat; |
| protected $serviceNom = 'informations'; |
| private $masque; |
| public function consulter($ressources, $parametres) { |
| $this->ressources = $ressources; |
| $this->parametres = $parametres; |
| $versionResultat = null; |
| if (empty($this->ressources)){ |
| $this->traiterParametres(); |
| } |
| $this->definirTables(array ('index' => config::get('bdd_table_index'), |
| 'baseflor' => config::get('bdd_table'), |
| 'rangSup' => config::get('bdd_table_rang_sup') |
| ) |
| ); |
| $this->traiterRessources(); |
| $requete = $this->assemblerLaRequete(); |
| $resultat = $this->Bdd->recupererTous($requete); |
| $versionResultat = $this->renvoyerResultat($resultat); |
| if ($versionResultat == null) { |
| $message = 'Les données recherchées sont introuvables.'; |
| $code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE; |
| throw new Exception($message, $code); |
| } |
| return $versionResultat; |
| } |
| public function __construct() { |
| $Conteneur = new Conteneur(); |
| $this->Bdd = $Conteneur ->getBdd(); |
| } |
| public function renvoyerResultat($resultat) { |
| $res_formate = array(); |
| if (empty($this->ressources)) { |
| $res_formate = $this->retournerResultatFormate($resultat); |
| } else { |
| $classe = empty($resultat[0]['baseflor']) ? 'InformationsTaxonsSup' : 'InformationsBaseflor'; |
| $info = new $classe(new Conteneur()); |
| $res_formate = $info->consulter($this->ressources, $this->parametres); |
| } |
| return $res_formate; |
| } |
| //+--------------------------traitement ressources ou paramètres -------------------------------------+ |
| public function traiterRessources() { |
| if (empty($this->ressources)) { |
| $this->requete_jointure = array( |
| 'LEFT JOIN '. $this->tables['baseflor'].' ON ' |
| .$this->tables['baseflor'].".cle =".$this->tables['index'].".baseflor", |
| 'LEFT JOIN '. $this->tables['rangSup'].' ON ' |
| .$this->tables['rangSup'].".cle = ".$this->tables['index'].".RangSup"); |
| $this->champs_recherches = " {$this->tables['baseflor']}.num_nomen as 'baseflor.nn', |
| {$this->tables['baseflor']}.BDNT as 'baseflor.bdnt', |
| {$this->tables['baseflor']}.catminat_code, |
| {$this->tables['baseflor']}.num_taxon , |
| {$this->tables['baseflor']}.idiotaxon , |
| {$this->tables['rangSup']}.num_nomen as 'rangSup.nn', |
| {$this->tables['rangSup']}.bdnt as 'rangSup.bdnt', |
| {$this->tables['index']}.cle as 'index.cle' "; |
| } else { |
| if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[0], $retour)){ |
| $this->champs_recherches = " baseflor, rangSup "; |
| $this->requete_condition[] = " `bdnt.nn` = '{$retour[0]}' "; |
| } else { |
| $e = 'Erreur dans l\'url de votre requête : </br> La ressource demandée n\'existe pas.'; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| break; |
| } |
| } |
| } |
| public function traiterParametres() { |
| if (isset($this->parametres) && !empty($this->parametres) ) { |
| foreach ($this->parametres as $param => $valeur) { |
| switch ($param) { |
| case 'navigation.depart' : |
| $this->definirNavigationDepart($valeur); |
| break; |
| case 'navigation.limite' : |
| $this->definirNavigationLimite($valeur); |
| break; |
| case 'version.projet' : |
| $this->traiterVersion($valeur); |
| break; |
| case 'masque.cat' : |
| $this->masque = 'catminat='.str_replace('-','/',$valeur); |
| $this->requete_condition[] = " catminat_code = '".str_replace('-','/',$valeur)."' "; |
| break; |
| default : |
| $e = 'Erreur dans les parametres de votre requête : </br> Le paramètre " ' |
| .$param.' " n\'existe pas.'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_MAUVAISE_REQUETE, $e); 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 == '*' && empty($this->ressources)) { |
| $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($prefixe_table) { |
| $table_num_version = $this->recupererVersionDisponible(); |
| foreach ($prefixe_table as $nom => $prefixe ) { |
| if ( in_array($this->version_projet,$table_num_version) ) { |
| $tables[$nom] = $prefixe.'_v'.$this->version_projet; |
| } elseif ($this->version_projet == '+') { |
| $derniere_version = $table_num_version[count($table_num_version) - 1]; |
| $tables[$nom] = $prefixe.'_v'.str_replace('.', '_', $derniere_version); |
| } else { |
| $e = "Erreur : La version est inconnue."; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| } |
| $this->tables = $tables; |
| } |
| //+--------------------------formatages de resultats -------------------------------------------+ |
| public function retournerResultatFormate($resultat) { |
| $resultat_json = array(); |
| $resultat_json['entete'] = $this->ajouterEnteteResultat(); |
| $resultat_json['resultats'] = array(); |
| foreach ($resultat as $ligne => $tab) { |
| $num = $tab['index.cle']; |
| $json['resultats'][$num]['num_nomen'] = |
| (empty ($tab['baseflor.nn'])) ? $tab['rangSup.nn'] : $tab['baseflor.nn']; |
| $resultat_json['resultats'][$num]['bdnt'] = |
| (empty ($tab['baseflor.bdnt'])) ? $tab['rangSup.bdnt'] : $tab['baseflor.bdnt']; |
| $resultat_json['resultats'][$num]['catminat_code'] = |
| (empty ($tab['catminat_code'])) ? '' : $tab['catminat_code']; |
| $resultat_json['resultats'][$num]['idiotaxon'] = |
| (empty ($tab['idiotaxon'])) ? '' : $tab['idiotaxon']; |
| $resultat_json['resultats'][$num]['num_taxon'] = |
| (empty ($tab['num_taxon'])) ? '' : $tab['num_taxon']; |
| if ($resultat_json['resultats'][$num]['num_nomen'] != 0) { |
| $bdnt = strtolower($resultat_json['resultats'][$num]['bdnt']); |
| $nn = $resultat_json['resultats'][$num]['num_nomen']; |
| $resultat_json['resultats'][$num]['href'] = |
| $this->ajouterHref('informations',$bdnt.".nn:".$nn); |
| } |
| } |
| return $resultat_json; |
| } |
| public function ajouterEnteteResultat() { |
| $entete['depart'] = $this->limite_requete['depart']; |
| $entete['limite'] = $this->limite_requete['limite']; |
| $entete['total'] = $this->total_resultat; |
| if ($this->masque) { |
| $entete['masque'] = $this->masque; |
| } |
| $entete['version'] = $this->version_projet; |
| $url = $this->formulerUrl($this->total_resultat, '/informations'); |
| if (isset($url['precedent']) && $url['precedent'] != '') { |
| $entete['href.precedent'] = $url['precedent']; |
| } |
| if (isset($url['suivant']) && $url['suivant'] != '') { |
| $entete['href.suivant'] = $url['suivant']; |
| } |
| return $entete; |
| } |
| //+-------------------------------------assemblage de requête------------------------------------// |
| public function assemblerLaRequete() { |
| $requete = ' SELECT '.$this->champs_recherches.' FROM '.$this->tables['index'].' ' |
| .$this->retournerRequeteJointure().' '.$this->retournerRequeteCondition(). |
| ' '.$this->delimiterResultatsRequete(); |
| return $requete; |
| } |
| public function retournerRequeteCondition() { |
| $condition = ''; |
| if ($this->requete_condition !== "") { |
| $condition = ' WHERE '.implode(' AND ', $this->requete_condition); |
| } |
| return $condition; |
| } |
| public function calculerTotalResultat() { |
| $requete = 'SELECT count(*) as nombre FROM '.$this->tables['index'].' ' |
| .$this->retournerRequeteJointure().' '.$this->retournerRequeteCondition(); |
| $res = $this->getBdd()->recuperer($requete); |
| if ($res) { |
| $this->total_resultat = $res['nombre']; |
| } else { |
| $this->total_resultat = 0; |
| $e = 'Données introuvables dans la base'; |
| $this->renvoyerErreur(RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE, $e); |
| } |
| } |
| public function delimiterResultatsRequete() { |
| $this->calculerTotalResultat(); |
| $requete_limite = ''; |
| if (($this->limite_requete['depart'] <= $this->total_resultat) ){ |
| if ( $this->limite_requete['depart'] < $this->total_resultat ){ |
| $requete_limite = 'LIMIT '.$this->limite_requete['depart'].', ' |
| .$this->limite_requete['limite']; |
| } |
| } else { |
| $e = "Erreur : la valeur pour le paramètre navigation.départ est supérieure". |
| " au nombre total de résultats."; |
| throw new Exception($e, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE); |
| } |
| return $requete_limite; |
| } |
| public function retournerRequeteJointure() { |
| $jointure = ''; |
| if ($this->requete_jointure !== "") { |
| $jointure = implode(' ', $this->requete_jointure); |
| } |
| return $jointure; |
| } |
| } |
| /branches/refact/services/modules/0.1/baseflor/GraphiquesTaxonsSup.php |
|---|
| New file |
| 0,0 → 1,143 |
| <?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); |
| $case = $Dompath->query("//*[@id='".$grad_id."_".$champs."']")->item(0); |
| $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" ); |
| } |
| } |
| } |
| ?> |
| /branches/refact/services/modules/0.1/baseflor/InformationsTaxonsSup.php |
|---|
| New file |
| 0,0 → 1,253 |
| <?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/relations/catminat"; |
| 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/relations/catminat"; |
| throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE); |
| } |
| 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 = $this->recupererTableauConfig('champs_ontologiques'); |
| foreach ($this->champs_ontologiques as $cle => $valeur){ |
| if ($this->resultat_json[$cle.'_min'] != ""){ |
| $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->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)); |
| $val = $this->consulterHref($url); |
| $this->resultat_json[$champs.'.libelle'] = $val->nom; |
| $this->resultat_json[$champs.'.code'] = $valeur; |
| $this->resultat_json[$champs.'.href'] = $url; |
| } |
| //+--------------------------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; |
| } |
| } |
| ?> |