Rev 845 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpclass Utilisateurs {const TPL_URL_WS_ANNUAIRE = 'http://www.tela-botanica.org/service:annuaire:utilisateur/identite-par-courriel/%s';private $courriels = array();private $clientRest = null;/*** Prend en paramêtre un tableau de courriels.** @param array $courriels un tableau de courriels pour lesquels il faut rechercher les infos d'identité*/public function __construct(Array $courriels = array(), RestClient $clientRest = null) {$this->courriels = $courriels;$this->clientRest = is_null($clientRest) ? new RestClient() : $clientRest;}public function setCourriels($courriels) {$this->courriels = $courriels;}/*** Retourne, avoir interrogé un service de l'annuaire, les intitulés correspondant aux* courriels des utilisateurs.** @return mixed tableau avec en clé le courriel et en valeur l'intitulé de la personne à* afficher, false en cas d'erreur ou de résultat vide.*/public function getIntitules() {$intitules = false;if ($identites = $this->getIdentites()) {$intitules = array();foreach ($identites as $courriel => $infos) {$intitules[$courriel] = $infos['intitule'];}}return $intitules;}private function getIdentites() {$utilisateursInfos = $this->consulterServiceAnnuaire();$identites = $this->extraireIdentites($utilisateursInfos);return $identites;}private function consulterServiceAnnuaire() {$url = sprintf(self::TPL_URL_WS_ANNUAIRE, implode(',', $this->courriels));$json = $this->clientRest->consulter($url);$utilisateurs = json_decode($json, true);return $utilisateurs;}private function extraireIdentites($utilisateursInfos) {$identites = array();foreach ($this->courriels as $courriel) {$info = array('id' => null, 'intitule' => '');if (isset($utilisateursInfos[$courriel])) {$info['intitule'] = $utilisateursInfos[$courriel]['intitule'];$info['id'] = $utilisateursInfos[$courriel]['id'];} else {$info['intitule'] = $this->tronquerCourriel($courriel);}$identites[$courriel] = $info;}return $identites;}private function tronquerCourriel($courriel) {$courriel = str_replace(substr($courriel, strpos($courriel, '@')), '@...', $courriel);return $courriel;}}?>