New file |
0,0 → 1,95 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Fournit une liste d'auto-complétions (=référentiel) relative à l'utilisateur sur l'un des champs demandés. |
* |
* @internal Mininum PHP version : 5.2 |
* @category CEL |
* @package Services |
* @subpackage Auto-complétions |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @author Aurelien PERONNET <aurelien@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class SelfRefList extends Cel { |
|
private $referentiels = array('station', 'lieudit', 'milieu'); |
|
/** |
* Suivant le type de référentiel donné en paramètre, renvoie les liste de ses éléments |
* |
* uid[0] : utilisateur obligatoire |
* uid[1] : referentiel demandé (obligatoire) |
* $_GET["start"] et $GET_["limit"] : selection intervalle |
* $_GET["recherche"] : cherche les noms qui commmencent selon la valeur |
* |
*/ |
public function getElement($uid){ |
// Controle detournement utilisateur |
$this->controleUtilisateur($uid[0]); |
|
if (!$this->paramObligatoiresSontPresents($uid)) { |
return; |
} |
|
if ($_GET['recherche'] == '*') { |
$_GET['recherche'] = '%'; |
} |
|
$referentiel_demande = $uid[1]; |
$idUtilisateurP = Cel::db()->proteger($uid[0]); |
|
$filtreSql = ''; |
if ($this->filtreRechercheEstDemande()) { |
$rechercheP = Cel::db()->proteger($_GET['recherche'].'%'); |
$filtreSql = "AND $referentiel_demande LIKE $rechercheP "; |
} |
|
$limiteSql = ''; |
if ($this->limiteEstDemandee()) { |
$start = intval($_GET['start']); |
$limit = intval($_GET['limit']); |
$limite = "LIMIT $start,$limit "; |
} |
|
$requete = "SELECT DISTINCT $referentiel_demande " . |
'FROM cel_obs '. |
"WHERE ce_utilisateur = $idUtilisateurP ". |
$filtreSql. |
"ORDER BY $referentiel_demande ". |
$limiteSql. |
' -- '.__FILE__.':'.__LINE__; |
$resultat = Cel::db()->requeter($requete); |
|
$referentiel = array(); |
if (is_array($resultat)) { |
foreach ($resultat as $cle => $valeur) { |
if ($this->estUneValeurValide($valeur[$referentiel_demande])) { |
$referentiel[] = $valeur[$referentiel_demande]; |
} |
} |
} |
$this->envoyerJson($referentiel); |
return true; |
} |
|
private function paramObligatoiresSontPresents($uid) { |
return (isset($uid[1]) && in_array($uid[1], $this->referentiels) && (isset($uid[0]) && $uid[0] != '')); |
} |
|
private function filtreRechercheEstDemande() { |
return (isset($_GET['recherche']) && trim($_GET['recherche']) != ''); |
} |
|
private function limiteEstDemandee() { |
return isset($_GET['start']) && is_numeric($_GET['start']) && isset($_GET['limit']) && is_numeric($_GET['limit']); |
} |
|
private function estUneValeurValide($chaine) { |
return ($chaine != null && $chaine != '000null' && trim($chaine) != ''); |
} |
} |
Property changes: |
Added: svnkit:entry:sha1-checksum |
+3cf82d4f4dd79608a8b682a0abbc1d314fd668bb |
\ No newline at end of property |
Added: svn:executable |
+* |
\ No newline at end of property |