Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 698 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/**
* Classe GraphiquesTaxonsSup.php transforme les données écologiques de la table baseflor_rang_sup_ecologie
* en graphique svg
*  graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
*
*
* @package eflore-projets
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
* @version 1.0
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
*/

class GraphiquesTaxonsSup extends CommunGraphiques{
        


        
        public function definirTable($version){
                $this->table = Config::get('bdd_table_rang_sup')."_v".$version;
        }
        
        //+---- ressources ----+
        public function traiterReferentieletNum(){
                if (!empty($this->ressources[1])) {
                        if(preg_match('/^(.+)\.nn:([0-9]+)$/', $this->ressources[1], $retour) == 1){
                                switch ($retour[1]) {
                                        case 'bdtfx' : // pour le moment un seul referentiel disponible
                                                $this->requete_condition[]= "num_nomen = ".$retour[2]." AND bdnt = 'bdtfx' ";
                                                break;
                                        default :
                                                $e = "Le référentiel {$retour[1]} n'existe pas.";
                                        throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
                                        break;
                                }
        
                        }else {
                                $e = "Erreur dans l'url de votre requête :".
                                " précisez le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.";
                                throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
                        }
                } else {
                        throw new Exception( "Erreur dans l'url de votre requête :".
                                                        " précisez le référentiel et le numéro nomenclatural sous la forme {bdnt}.nn:{nn}.",
                        RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
                }
        
        }
        
        
        
        public function traiterTypeGraphique(){
                if (!empty($this->ressources[0])) {
                        switch ($this->ressources[0]) {
                                case  'climat' :
                                        $this->requete_champs = ' ve_lumiere_min, ve_lumiere_max, ve_temperature_min,'.
                                                                                        ' ve_temperature_max, ve_continentalite_min,'.
                                                                                        ' ve_continentalite_max, ve_humidite_atmos_min,'.
                                                                                        ' ve_humidite_atmos_max' ;
                                        $this->nomGraphique= 'climat_min_max';
                                        break;
                                case 'sol' :
                                        $this->requete_champs = ' ve_humidite_edaph_min , ve_humidite_edaph_max,'.
                                                                                        ' ve_reaction_sol_min, ve_reaction_sol_max, '.
                                                                                        ' ve_nutriments_sol_min, ve_nutriments_sol_max,'.
                                                                                        ' ve_salinite_min, ve_salinite_max,'.
                                                                                        ' ve_texture_sol_min, ve_texture_sol_max,'.
                                                                                        've_mat_org_sol_min,ve_mat_org_sol_max ' ;
                                        $this->nomGraphique = 'sol_min_max';
                                        break;
                                default :
                                        $e = "Erreur dans l'url de votre requête :".
                                        "</br> précisez le graphique -> \"sol\" ou \"climat\".";
                                throw new Exception($e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
                                break;
                        }
                }else {
                        throw new Exception("Erreur dans l'url de votre requête :".
                                        "</br> precisez le graphique -> \"sol\" ou \"climat\".", RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
                }
        }
        
        
        
        
        //+-------------------------- formatage du résultat  -------------------------------------------+
        
        public function changerValeursSVG(){
                $this->ajouterValeursIntermediaires();
                $Dompath = new DOMXPath($this->dom);
                foreach ($this->valeurs_en_pourcentage as $cle => $val){
                                $val = preg_replace('/,/','.', $val);
                                $grad_id = array_search($val,$this->graduations_id);
                                $champs = preg_replace('/_min|_max|_[0-9]/','', $cle);
                                // dans le cas de mauvaises données, pour ne pas que tout le graphique
                                $case = $Dompath->query("//*[@id='".$grad_id."_".$champs."']")->item(0);
                                if($case != null) {
                                        $case->setAttribute('fill','#EA6624');
                                        $case->setAttribute('stroke','#EA6624');
                                        $this->ajouterInfoAuSurvol($champs,$case);
                                }
                                $changement = true;
                }
                $this->ajusterFormatSVG();
        }
        
        
        
        public function ajouterValeursIntermediaires(){
                $champs_ecolo = array_keys($this->champs_ontologiques);
                foreach ($champs_ecolo as $chps ){
                        $min = !empty($this->valeurs_en_pourcentage[$chps.'_min']) ? $this->valeurs_en_pourcentage[$chps.'_min'] : -1;
                        $max = !empty($this->valeurs_en_pourcentage[$chps.'_max']) ? $this->valeurs_en_pourcentage[$chps.'_max'] : -1;
                        if ($min < ($max-0.1) ){
                                $i = $min + 0.1;
                                $num = 1;
                                for ($i ; $i < $max; $i += 0.1) {
                                        $this->valeurs_en_pourcentage[$chps.'_'.$num] = $i;
                                        $num++;
                                }
                        }
                }
        }
        
        public function ajouterInfoAuSurvol($champs, $case){
                $min = $this->valeurs_champs[$champs."_min"];
                $max = $this->valeurs_champs[$champs."_max"];
                if ($min != $max){
                        $valeurMin = $this->recupererOntologies($min, $champs );
                        $valeurMax = $this->recupererOntologies($max, $champs );
                        $valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
                        $valeurMax = $this->traiterIntermediaires($valeurMax->nom, $champs, $champs.'_max');
                        $case->setAttribute('title',"de $min: $valeurMin à $max: $valeurMax " );
                } else {
                        $valeurMin = $this->recupererOntologies($min, $champs );
                        $valeurMin = $this->traiterIntermediaires($valeurMin->nom, $champs, $champs.'_min');
                        $case->setAttribute('title',"$min: $valeurMin" );
                }
        }
        
        
}
?>