Subversion Repositories Applications.dictionnaire

Rev

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

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