| 737 |
aurelien |
1 |
<?php
|
| 2458 |
jpm |
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Fournit une liste d'auto-complétions (=référentiel) relative à l'utilisateur sur l'un des champs demandés.
|
|
|
5 |
*
|
|
|
6 |
* @internal Mininum PHP version : 5.2
|
|
|
7 |
* @category CEL
|
|
|
8 |
* @package Services
|
|
|
9 |
* @subpackage Auto-complétions
|
|
|
10 |
* @version 0.1
|
|
|
11 |
* @author Mathias CHOUET <mathias@tela-botanica.org>
|
|
|
12 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
13 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
|
|
14 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
15 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
16 |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
|
|
|
17 |
*/
|
| 851 |
aurelien |
18 |
class SelfRefList extends Cel {
|
| 2143 |
jpm |
19 |
|
| 737 |
aurelien |
20 |
private $referentiels = array('station', 'lieudit', 'milieu');
|
|
|
21 |
|
| 851 |
aurelien |
22 |
/**
|
|
|
23 |
* Suivant le type de référentiel donné en paramètre, renvoie les liste de ses éléments
|
| 2143 |
jpm |
24 |
*
|
| 851 |
aurelien |
25 |
* uid[0] : utilisateur obligatoire
|
|
|
26 |
* uid[1] : referentiel demandé (obligatoire)
|
|
|
27 |
* $_GET["start"] et $GET_["limit"] : selection intervalle
|
| 1299 |
aurelien |
28 |
* $_GET["recherche"] : cherche les noms qui commmencent selon la valeur
|
| 2143 |
jpm |
29 |
*
|
| 851 |
aurelien |
30 |
*/
|
| 2143 |
jpm |
31 |
public function getElement($uid){
|
|
|
32 |
// Controle detournement utilisateur
|
|
|
33 |
$this->controleUtilisateur($uid[0]);
|
| 737 |
aurelien |
34 |
|
| 2143 |
jpm |
35 |
if (!$this->paramObligatoiresSontPresents($uid)) {
|
|
|
36 |
return;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
if ($_GET['recherche'] == '*') {
|
|
|
40 |
$_GET['recherche'] = '%';
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
$referentiel_demande = $uid[1];
|
| 2458 |
jpm |
44 |
$idUtilisateurP = Cel::db()->proteger($uid[0]);
|
| 2143 |
jpm |
45 |
|
| 2458 |
jpm |
46 |
$filtreSql = '';
|
| 2143 |
jpm |
47 |
if ($this->filtreRechercheEstDemande()) {
|
| 2458 |
jpm |
48 |
$rechercheP = Cel::db()->proteger($_GET['recherche'].'%');
|
| 2596 |
aurelien |
49 |
$filtreSql = "AND $referentiel_demande LIKE $rechercheP ";
|
| 2143 |
jpm |
50 |
}
|
| 2458 |
jpm |
51 |
|
|
|
52 |
$limiteSql = '';
|
| 2143 |
jpm |
53 |
if ($this->limiteEstDemandee()) {
|
| 2458 |
jpm |
54 |
$start = intval($_GET['start']);
|
|
|
55 |
$limit = intval($_GET['limit']);
|
|
|
56 |
$limite = "LIMIT $start,$limit ";
|
| 2143 |
jpm |
57 |
}
|
| 2458 |
jpm |
58 |
|
|
|
59 |
$requete = "SELECT DISTINCT $referentiel_demande " .
|
|
|
60 |
'FROM cel_obs '.
|
|
|
61 |
"WHERE ce_utilisateur = $idUtilisateurP ".
|
|
|
62 |
$filtreSql.
|
|
|
63 |
"ORDER BY $referentiel_demande ".
|
|
|
64 |
$limiteSql.
|
|
|
65 |
' -- '.__FILE__.':'.__LINE__;
|
| 2143 |
jpm |
66 |
$resultat = Cel::db()->requeter($requete);
|
|
|
67 |
|
|
|
68 |
$referentiel = array();
|
| 2385 |
mathias |
69 |
if (is_array($resultat)) {
|
|
|
70 |
foreach ($resultat as $cle => $valeur) {
|
|
|
71 |
if ($this->estUneValeurValide($valeur[$referentiel_demande])) {
|
|
|
72 |
$referentiel[] = $valeur[$referentiel_demande];
|
|
|
73 |
}
|
| 737 |
aurelien |
74 |
}
|
| 2143 |
jpm |
75 |
}
|
|
|
76 |
$this->envoyerJson($referentiel);
|
|
|
77 |
return true;
|
| 737 |
aurelien |
78 |
}
|
| 2143 |
jpm |
79 |
|
|
|
80 |
private function paramObligatoiresSontPresents($uid) {
|
|
|
81 |
return (isset($uid[1]) && in_array($uid[1], $this->referentiels) && (isset($uid[0]) && $uid[0] != ''));
|
| 737 |
aurelien |
82 |
}
|
| 2143 |
jpm |
83 |
|
|
|
84 |
private function filtreRechercheEstDemande() {
|
|
|
85 |
return (isset($_GET['recherche']) && trim($_GET['recherche']) != '');
|
| 737 |
aurelien |
86 |
}
|
| 2143 |
jpm |
87 |
|
|
|
88 |
private function limiteEstDemandee() {
|
|
|
89 |
return isset($_GET['start']) && is_numeric($_GET['start']) && isset($_GET['limit']) && is_numeric($_GET['limit']);
|
| 737 |
aurelien |
90 |
}
|
| 2143 |
jpm |
91 |
|
|
|
92 |
private function estUneValeurValide($chaine) {
|
|
|
93 |
return ($chaine != null && $chaine != '000null' && trim($chaine) != '');
|
| 737 |
aurelien |
94 |
}
|
| 2143 |
jpm |
95 |
}
|