Rev 6 | Rev 10 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class Dictionnaire extends RestService {
// 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;
// SELECT group_concat( distinct a.id) FROM definitions a, definitions b WHERE a.id != b.id AND INSTR(b.cle, a.cle) != 0
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);
//+----------------------------------------------------------------------------------------------------------------+
// Consulter
public function consulter($ressources, $parametres) {
$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
$corps_http = null;
if (isset($ressources[0])) {
$methode = $ressources[0];
switch($methode) {
case 'mots':
$retour = $this->getMots();
break;
case 'zglossary':
$retour = $this->getMots_zglossary();
break;
case 'autoabbr':
$retour = $this->getMots_autoabbr();
break;
case 'def':
if(isset($ressources[1])) {
$retour = $this->getDefinition($ressources[1]);
} else {
$retour = $this->getToutesDefinitions();
}
break;
case 'defs':
$retour = $this->getToutesDefinitions();
break;
default:
$retour = 'Le service requiert un nom de méthode';
break;
}
$entete_http = RestServeur::HTTP_CODE_OK;
$corps_http = json_encode($retour);
} else {
$entete_http = RestServeur::HTTP_CODE_CONTENU_REQUIS;
}
RestServeur::envoyerEnteteStatutHttp($entete_http);
header('Content-type: application/json; charset=UTF-8');
echo $corps_http;
exit;
}
private function getDefinition($mot) {
$requete_selection_definition = 'SELECT valeur FROM definitions WHERE cle = "'. self::simplifier($mot).'"';
$definition = $this->bdd->recuperer($requete_selection_definition);
return $definition;
}
private function getToutesDefinitions() {
return $this->bdd->recupererTous('SELECT valeur FROM definitions');
}
private function getMots() {
/*
$requete = sprintf('SELECT cle FROM definitions WHERE id NOT IN (%s) ORDER BY LENGTH(cle) DESC',
implode(",", self::$sous_mots));
$requete = sprintf('SELECT cle FROM definitions WHERE id NOT IN (%s)',
implode(",", self::$sous_mots));
*/
$requete = 'SELECT cle FROM definitions';
$assoc = $this->bdd->recupererTous($requete);
array_walk($assoc, function(&$item) { $item = $item['cle']; });
return $assoc;
}
private function getMots_zglossary() {
$assoc = $this->bdd->recupererTous('SELECT cle as term, 0 as type, valeur as definition FROM definitions' .
' WHERE valeur != ""');
return $assoc;
}
private function getMots_autoabbr() {
$assoc = $this->bdd->recupererTous("SELECT CONCAT(cle, '*') as cle FROM definitions WHERE valeur != ''");
$assoc2 = Array();
foreach($assoc as $v) {
$assoc2[$v['cle']] = true;
}
return $assoc2;
}
static function simplifier($chaine){
return trim(strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $chaine)), " \t\n\r\0\x0b*");
}
}
?>