Subversion Repositories Applications.dictionnaire

Rev

Rev 14 | 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
    private function getMots() {
16 aurelien 69
    	$requete = 'SELECT TRIM(cle) as cle FROM definitions';  // certaines cles ont des espaces
70
    	$assoc = $this->bdd->recupererTous($requete);
71
 
72
    	array_walk($assoc, array($this,"formaterTableauDefinitions"));
73
    	return $assoc;
1 aurelien 74
    }
16 aurelien 75
 
76
    private function formaterTableauDefinitions(&$item) {
77
    	$item = $item['cle'];
78
    }
8 raphael 79
 
14 aurelien 80
    private function getMotsZglossary() {
8 raphael 81
		$assoc = $this->bdd->recupererTous('SELECT cle as term, 0 as type, valeur as definition FROM definitions' .
82
										   ' WHERE valeur != ""');
83
		return $assoc;
84
    }
85
 
14 aurelien 86
    private function getMotsAutoAbbr() {
8 raphael 87
		$assoc = $this->bdd->recupererTous("SELECT CONCAT(cle, '*') as cle FROM definitions WHERE valeur != ''");
88
		$assoc2 = Array();
89
		foreach($assoc as $v) {
90
			$assoc2[$v['cle']] = true;
91
		}
92
		return $assoc2;
93
    }
1 aurelien 94
 
6 raphael 95
    static function simplifier($chaine){
8 raphael 96
		return trim(strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $chaine)), " \t\n\r\0\x0b*");
1 aurelien 97
	}
98
}
2 aurelien 99
?>