Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 942 → Rev 943

/trunk/jrest/services/Cel.php
17,6 → 17,7
const TYPE_OBS = 'observation';
const TYPE_IMG = 'image';
const SQL_MODE_ASSOC = PDO::FETCH_ASSOC;
const SQL_MODE_OBJET = PDO::FETCH_OBJ;
const SQL_RETOUR_COMPLET = 'All';
const SQL_RETOUR_LIGNE = 'Row';
const SQL_RETOUR_COLONNE = 'Column';
276,11 → 277,13
$sortie = 'OK';
}
}
// Gestion de l'envoie du déboguage
$this->envoyerDebogage();
 
// Encodage au format et JSON et envoie sur la sortie standard
$contenu = $json ? json_encode($sortie) : $sortie;
$this->envoyerContenu($encodage, $mime, $contenu);
}
 
316,25 → 319,15
}
//+----------------------------------------------------------------------------------------------------------------+
// GESTION DU DAO
// GESTION DES CLASSES CHARGÉES À LA DEMANDE
protected function getDao() {
if (isset($this->dao)) {
return $this->dao;
} else {
$e = "Le DAO n'a pas été initialisé. Utiliser la méthode initialiserDao().";
trigger_error($e, E_USER_WARNING);
protected function getRestClient() {
if (!isset($this->restClient)) {
$this->restClient = new CelRestClient();
}
return $this->restClient;
}
protected function initialiserDao($url_services_distant) {
if (!isset($this->dao)) {
$this->dao = new CelDao($url_services_distant);
} else {
$this->dao->url_jrest = $url_services_distant;
}
}
//+----------------------------------------------------------------------------------------------------------------+
// GESTION DE L'IDENTIFICATION
419,11 → 412,11
}
public function etreUtilisateurAutorise() {
$this->initialiserDao('http://www.tela-botanica.org/client/annuaire_nouveau/actuelle/jrest/');
$identifiant = $this->getAuthIdentifiant();
$mdp = md5($this->getAuthMotDePasse());
$url = $this->getDao()->url_jrest."TestLoginMdp/$identifiant/$mdp";
$json = $this->getDao()->envoyerRequeteConsultation($url);
$service = "TestLoginMdp/$identifiant/$mdp";
$url = sprintf($this->config['settings']['baseURLServicesAnnuaireTpl'], $service);
$json = $this->getRestClient()->consulter($url);
$existe = json_decode($json);
$autorisation = (isset($existe) && $existe) ? true :false;
489,28 → 482,37
return $url;
}
protected function creerAuteur($courriel, $pourAdmin = false) {
$auteur = ($pourAdmin) ? $courriel : $this->tronquerCourriel($courriel);
return $auteur;
}
protected function creerAuteurs(array $courriels, $pourAdmin = false) {
$auteurs = ($pourAdmin) ? $courriels : $this->recupererUtilisateursNomPrenom($courriels);
/**
* Prend en paramêtre un tableau de courriels et retourne après avoir interrogé un service de l'annuaire
* une tableau avec en clé le courriel et en valeur l'intitulé de la personne à afficher.
*
* @param array $courriels un tableau de courriels pour lesquels il faut rechercher les infos d'identité
*/
protected function creerAuteurs(Array $courriels) {
$auteurs = array();
if ($identites = $this->recupererUtilisateursIdentite($courriels)) {
foreach ($identites as $courriel => $infos) {
$auteurs[$courriel] = $info['identite'];
}
}
return $auteurs;
}
protected function recupererUtilisateursNomPrenom(array $courriels) {
protected function recupererUtilisateursIdentite(Array $courriels) {
// Récupération des données au format Json
$service = "utilisateur/prenom-nom-par-courriel/".implode(',', $courriels);
$service = "utilisateur/identite-par-courriel/".implode(',', $courriels);
$url = sprintf($this->config['settings']['baseURLServicesAnnuaireTpl'], $service);
$json = file_get_contents($url);
$utilisateurs = json_decode($json);
foreach ($courriels as $courriel) {
$info = array('id' => null, 'identite' => '');
if (isset($utilisateurs->$courriel)) {
$noms[$courriel] = $utilisateurs->$courriel->prenom.' '.$utilisateurs->$courriel->nom;
$info['intitule'] = $utilisateurs->$courriel->intitule;
$info['id'] = $utilisateurs->$courriel->id;
} else {
$noms[$courriel] = $this->tronquerCourriel($courriel);
}
$info['intitule'] = $this->tronquerCourriel($courriel);
}
$noms[$courriel] = $info;
}
return $noms;
}
583,7 → 585,7
}
protected function encoderMotCle($mot_cle) {
return md5(mb_strtolower($mot_cle));
return md5(mb_strtolower(trim($mot_cle)));
}
protected function decoderMotsClesObs($utilisateur_id, $mots_cles) {
603,15 → 605,16
if (! $this->etreNull($mots_cles)) {
$table = ($type == self::TYPE_IMG) ? 'cel_mots_cles_images' : 'cel_mots_cles_obs' ;
$requete = 'SELECT mot_cle '.
$requete = 'SELECT cmc_mot_cle '.
"FROM $table ".
"WHERE id_mot_cle_utilisateur IN ($mots_cles) ".
"AND ce_utilisateur = $utilisateur_id ";
"WHERE cmc_id_mot_cle_utilisateur IN ($mots_cles) ".
"AND cmc_id_proprietaire = $utilisateur_id ";
$elements = $this->executerRequete($requete);
foreach ($elements as $mot) {
$mots[] = $mot['mot_cle'];
if (is_array($elements)) {
foreach ($elements as $mot) {
$mots[] = $mot['mot_cle'];
}
}
}
}