Subversion Repositories Applications.dictionnaire

Rev

Rev 10 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 14
1
<?php
1
<?php
2
class Dictionnaire extends RestService {
2
class Dictionnaire extends RestService {
3
 
-
 
4
	// SELECT a.id, a.cle, b.id, b.cle FROM definitions a, definitions b WHERE a.id != b.id AND INSTR(b.cle, a.cle) != 0 order by a.cle;
-
 
5
	// SELECT group_concat( distinct a.id) FROM definitions a, definitions b WHERE a.id != b.id AND INSTR(b.cle, a.cle) != 0
-
 
6
	static $sous_mots = array(20,22,33,37,65,103,106,151,160,164,177,202,220,222,230,249,250,257,262,276,284,307,334,352,359,394,397,401,422,437,438,449,452,453,463,469,475,498,517,527,547,549,550,585,603,604,606,607,638,641,660);
-
 
7
 
3
 
8
//+----------------------------------------------------------------------------------------------------------------+	
4
//+----------------------------------------------------------------------------------------------------------------+	
9
// Consulter
5
// Consulter
10
	public function consulter($ressources, $parametres) {
6
	public function consulter($ressources, $parametres) {
11
    	$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
7
    	$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
12
    	$corps_http = null;
8
    	$corps_http = null;
13
    	
9
    	
14
    	if (isset($ressources[0])) {
10
    	if (isset($ressources[0])) {
15
    		
11
    		
16
    		$methode = $ressources[0];
12
    		$methode = $ressources[0];
17
    		
13
    		
18
    		switch($methode) {
14
    		switch($methode) {
19
    			
15
    			
20
    			case 'mots':
16
    			case 'mots':
21
    				$retour = $this->getMots();
17
    				$retour = $this->getMots();
22
    			break;
18
    			break;
23
 
19
 
24
    			case 'zglossary':
20
    			case 'zglossary':
25
    				$retour = $this->getMots_zglossary();
21
    				$retour = $this->getMotsZglossary();
26
    			break;
22
    			break;
27
 
23
 
28
    			case 'autoabbr':
24
    			case 'autoabbr':
29
    				$retour = $this->getMots_autoabbr();
25
    				$retour = $this->getMotsAutoAbbr();
30
    			break;
26
    			break;
31
    			
27
    			
32
    			case 'def':
28
    			case 'def':
33
    				if(isset($ressources[1])) {
29
    				if(isset($ressources[1])) {
34
						$retour = $this->getDefinition($ressources[1]);
30
						$retour = $this->getDefinition($ressources[1]);
35
					} else {
31
					} else {
36
						$retour = $this->getToutesDefinitions();
32
						$retour = $this->getToutesDefinitions();
37
					}
33
					}
38
				break;
34
				break;
39
				case 'defs':
35
				case 'defs':
40
					$retour = $this->getToutesDefinitions();
36
					$retour = $this->getToutesDefinitions();
41
    			break;
37
    			break;
42
    			
38
    			
43
    			default:
39
    			default:
44
    				$retour = 'Le service requiert un nom de méthode';
40
    				$retour = 'Le service requiert un nom de méthode';
45
    			break;
41
    			break;
46
    		}
42
    		}
47
			
43
			
48
			$entete_http = RestServeur::HTTP_CODE_OK;
44
			$entete_http = RestServeur::HTTP_CODE_OK;
49
			$corps_http = json_encode($retour);	
45
			$corps_http = json_encode($retour);	
50
			
46
			
51
    	} else {
47
    	} else {
52
    		$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
48
    		$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
53
    	}
49
    	}
54
    	
50
    	
55
    	RestServeur::envoyerEnteteStatutHttp($entete_http);
51
    	RestServeur::envoyerEnteteStatutHttp($entete_http);
56
    	header('Content-type: application/json; charset=UTF-8');
52
    	header('Content-type: application/json; charset=UTF-8');
57
    	echo $corps_http; 
53
    	echo $corps_http; 
58
    	exit;
54
    	exit;
59
    }
55
    }
60
    
56
    
61
    private function getDefinition($mot) {
57
    private function getDefinition($mot) {
62
    	$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).'"';   
63
    	$definition = $this->bdd->recuperer($requete_selection_definition);
59
    	$definition = $this->bdd->recuperer($requete_selection_definition);
64
    	
60
    	
65
		return $definition; 
61
		return $definition; 
66
    }
62
    }
67
    
63
    
68
    private function getToutesDefinitions() {
64
    private function getToutesDefinitions() {
69
		return $this->bdd->recupererTous('SELECT valeur FROM definitions');
65
		return $this->bdd->recupererTous('SELECT valeur FROM definitions');
70
    }
66
    }
71
    
67
    
72
 
68
 
73
    private function getMots() {
69
    private function getMots() {
74
		/*
-
 
75
		$requete = sprintf('SELECT cle FROM definitions WHERE id NOT IN (%s) ORDER BY LENGTH(cle) DESC',
-
 
76
						   implode(",", self::$sous_mots));
-
 
77
		$requete = sprintf('SELECT cle FROM definitions WHERE id NOT IN (%s)',
-
 
78
						   implode(",", self::$sous_mots));
-
 
79
		*/
-
 
80
		$requete = 'SELECT TRIM(cle) as cle FROM definitions';  // certaines cles ont des espaces
70
		$requete = 'SELECT TRIM(cle) as cle FROM definitions';  // certaines cles ont des espaces
81
		$assoc = $this->bdd->recupererTous($requete);
71
		$assoc = $this->bdd->recupererTous($requete);
82
 
72
 
83
		array_walk($assoc, function(&$item) { $item = $item['cle']; });
73
		array_walk($assoc, function(&$item) { $item = $item['cle']; });
84
		return $assoc;
74
		return $assoc;
85
    }
75
    }
86
 
76
 
87
    private function getMots_zglossary() {
77
    private function getMotsZglossary() {
88
		$assoc = $this->bdd->recupererTous('SELECT cle as term, 0 as type, valeur as definition FROM definitions' .
78
		$assoc = $this->bdd->recupererTous('SELECT cle as term, 0 as type, valeur as definition FROM definitions' .
89
										   ' WHERE valeur != ""');
79
										   ' WHERE valeur != ""');
90
		return $assoc;
80
		return $assoc;
91
    }
81
    }
92
 
82
 
93
    private function getMots_autoabbr() {
83
    private function getMotsAutoAbbr() {
94
		$assoc = $this->bdd->recupererTous("SELECT CONCAT(cle, '*') as cle FROM definitions WHERE valeur != ''");
84
		$assoc = $this->bdd->recupererTous("SELECT CONCAT(cle, '*') as cle FROM definitions WHERE valeur != ''");
95
		$assoc2 = Array();
85
		$assoc2 = Array();
96
		foreach($assoc as $v) {
86
		foreach($assoc as $v) {
97
			$assoc2[$v['cle']] = true;
87
			$assoc2[$v['cle']] = true;
98
		}
88
		}
99
		return $assoc2;
89
		return $assoc2;
100
    }
90
    }
101
    
91
    
102
    static function simplifier($chaine){
92
    static function simplifier($chaine){
103
		return trim(strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $chaine)), " \t\n\r\0\x0b*");
93
		return trim(strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $chaine)), " \t\n\r\0\x0b*");
104
	}
94
	}
105
}
95
}
106
?>
96
?>