Subversion Repositories Applications.dictionnaire

Rev

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

<?php

class Dictionnaire extends RestService {

//+----------------------------------------------------------------------------------------------------------------+    
// Consulter
        public function consulter($ressources, $parametres) {
        $entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
        $corps_http = null;
        
        if (isset($ressources[0])) {
                
                $methode = $ressources[0];
                
                switch($methode) {
                        
                        case 'mots':
                                $retour = $this->getMots();
                        break;
                        
                        case 'def':
                                if(isset($ressources[1])) {
                                                $retour = $this->getDefinition($ressources[1]);
                                        } else {
                                                $retour = $this->getToutesDefinitions();
                                        }
                                break;
                                case 'defs':
                                        $retour = $this->getToutesDefinitions();
                        break;
                        
                        default:
                                $retour = 'Le service requiert un nom de méthode';
                        break;
                }
                        
                        $entete_http = RestServeur::HTTP_CODE_OK;
                        $corps_http = json_encode($retour);     
                        
        } else {
                $entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
        }
        
        //RestServeur::envoyerEnteteStatutHttp($entete_http);
        header('Content-type : application/json; charset=UTF-8');
        echo $corps_http; 
        exit;
    }
    
    private function getDefinition($mot) {
        
        $requete_selection_definition = 'SELECT valeur FROM onto_triples WHERE cle = "'.$this->simplifier($mot).'"';   
        $definition = $this->bdd->recuperer($requete_selection_definition);
        
                return $definition; 
    }
    
    private function getToutesDefinitions() {
        
        $requete_selection_toutes_definitions = 'SELECT valeur FROM onto_triples';
        
        $definitions = $this->bdd->recupererTous($requete_selection_toutes_definitions);
        
                return $definitions; 
    }
    
    private function getMots() {
        
        $requete_selection_mots = 'SELECT cle FROM onto_triples';
        
        $mots = $this->bdd->recupererTous($requete_selection_mots);
        
                
        foreach($mots as &$mot) {
                $mot['cle'] = $mot['cle'];
        } 
        
                return $mots;   
    }
    
    function simplifier($chaine){
        
                $sans_accent = strtr($chaine,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ',
                'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
                
                $en_minuscule = strtolower($sans_accent);
                
                return $en_minuscule;
        }
}
?>