Subversion Repositories Applications.dictionnaire

Rev

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