Subversion Repositories Applications.dictionnaire

Rev

Rev 14 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 16
1
<?php
1
<?php
2
class Dictionnaire extends RestService {
2
class Dictionnaire extends RestService {
3
 
3
 
4
//+----------------------------------------------------------------------------------------------------------------+	
4
//+----------------------------------------------------------------------------------------------------------------+	
5
// Consulter
5
// Consulter
6
	public function consulter($ressources, $parametres) {
6
	public function consulter($ressources, $parametres) {
7
    	$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
7
    	$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
8
    	$corps_http = null;
8
    	$corps_http = null;
9
    	
9
    	
10
    	if (isset($ressources[0])) {
10
    	if (isset($ressources[0])) {
11
    		
11
    		
12
    		$methode = $ressources[0];
12
    		$methode = $ressources[0];
13
    		
13
    		
14
    		switch($methode) {
14
    		switch($methode) {
15
    			
15
    			
16
    			case 'mots':
16
    			case 'mots':
17
    				$retour = $this->getMots();
17
    				$retour = $this->getMots();
18
    			break;
18
    			break;
19
 
19
 
20
    			case 'zglossary':
20
    			case 'zglossary':
21
    				$retour = $this->getMotsZglossary();
21
    				$retour = $this->getMotsZglossary();
22
    			break;
22
    			break;
23
 
23
 
24
    			case 'autoabbr':
24
    			case 'autoabbr':
25
    				$retour = $this->getMotsAutoAbbr();
25
    				$retour = $this->getMotsAutoAbbr();
26
    			break;
26
    			break;
27
    			
27
    			
28
    			case 'def':
28
    			case 'def':
29
    				if(isset($ressources[1])) {
29
    				if(isset($ressources[1])) {
30
						$retour = $this->getDefinition($ressources[1]);
30
						$retour = $this->getDefinition($ressources[1]);
31
					} else {
31
					} else {
32
						$retour = $this->getToutesDefinitions();
32
						$retour = $this->getToutesDefinitions();
33
					}
33
					}
34
				break;
34
				break;
35
				case 'defs':
35
				case 'defs':
36
					$retour = $this->getToutesDefinitions();
36
					$retour = $this->getToutesDefinitions();
37
    			break;
37
    			break;
38
    			
38
    			
39
    			default:
39
    			default:
40
    				$retour = 'Le service requiert un nom de méthode';
40
    				$retour = 'Le service requiert un nom de méthode';
41
    			break;
41
    			break;
42
    		}
42
    		}
43
			
43
			
44
			$entete_http = RestServeur::HTTP_CODE_OK;
44
			$entete_http = RestServeur::HTTP_CODE_OK;
45
			$corps_http = json_encode($retour);	
45
			$corps_http = json_encode($retour);	
46
			
46
			
47
    	} else {
47
    	} else {
48
    		$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
48
    		$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
49
    	}
49
    	}
50
    	
50
    	
51
    	RestServeur::envoyerEnteteStatutHttp($entete_http);
51
    	RestServeur::envoyerEnteteStatutHttp($entete_http);
52
    	header('Content-type: application/json; charset=UTF-8');
52
    	header('Content-type: application/json; charset=UTF-8');
53
    	echo $corps_http; 
53
    	echo $corps_http; 
54
    	exit;
54
    	exit;
55
    }
55
    }
56
    
56
    
57
    private function getDefinition($mot) {
57
    private function getDefinition($mot) {
58
    	$requete_selection_definition = 'SELECT valeur FROM definitions WHERE cle = "'. self::simplifier($mot).'"';   
58
    	$requete_selection_definition = 'SELECT valeur FROM definitions WHERE cle = "'. self::simplifier($mot).'"';   
59
    	$definition = $this->bdd->recuperer($requete_selection_definition);
59
    	$definition = $this->bdd->recuperer($requete_selection_definition);
60
    	
60
    	
61
		return $definition; 
61
		return $definition; 
62
    }
62
    }
63
    
63
    
64
    private function getToutesDefinitions() {
64
    private function getToutesDefinitions() {
65
		return $this->bdd->recupererTous('SELECT valeur FROM definitions');
65
		return $this->bdd->recupererTous('SELECT valeur FROM definitions');
66
    }
66
    }
67
    
-
 
68
 
67
    
69
    private function getMots() {
68
    private function getMots() {
70
		$requete = 'SELECT TRIM(cle) as cle FROM definitions';  // certaines cles ont des espaces
69
    	$requete = 'SELECT TRIM(cle) as cle FROM definitions';  // certaines cles ont des espaces
71
		$assoc = $this->bdd->recupererTous($requete);
70
    	$assoc = $this->bdd->recupererTous($requete);
72
 
71
    
73
		array_walk($assoc, function(&$item) { $item = $item['cle']; });
72
    	array_walk($assoc, array($this,"formaterTableauDefinitions"));
-
 
73
    	return $assoc;
-
 
74
    }
-
 
75
    
-
 
76
    private function formaterTableauDefinitions(&$item) {
74
		return $assoc;
77
    	$item = $item['cle'];
75
    }
78
    }
76
 
79
 
77
    private function getMotsZglossary() {
80
    private function getMotsZglossary() {
78
		$assoc = $this->bdd->recupererTous('SELECT cle as term, 0 as type, valeur as definition FROM definitions' .
81
		$assoc = $this->bdd->recupererTous('SELECT cle as term, 0 as type, valeur as definition FROM definitions' .
79
										   ' WHERE valeur != ""');
82
										   ' WHERE valeur != ""');
80
		return $assoc;
83
		return $assoc;
81
    }
84
    }
82
 
85
 
83
    private function getMotsAutoAbbr() {
86
    private function getMotsAutoAbbr() {
84
		$assoc = $this->bdd->recupererTous("SELECT CONCAT(cle, '*') as cle FROM definitions WHERE valeur != ''");
87
		$assoc = $this->bdd->recupererTous("SELECT CONCAT(cle, '*') as cle FROM definitions WHERE valeur != ''");
85
		$assoc2 = Array();
88
		$assoc2 = Array();
86
		foreach($assoc as $v) {
89
		foreach($assoc as $v) {
87
			$assoc2[$v['cle']] = true;
90
			$assoc2[$v['cle']] = true;
88
		}
91
		}
89
		return $assoc2;
92
		return $assoc2;
90
    }
93
    }
91
    
94
    
92
    static function simplifier($chaine){
95
    static function simplifier($chaine){
93
		return trim(strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $chaine)), " \t\n\r\0\x0b*");
96
		return trim(strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $chaine)), " \t\n\r\0\x0b*");
94
	}
97
	}
95
}
98
}
96
?>
99
?>