Subversion Repositories Applications.dictionnaire

Rev

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

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