Subversion Repositories eFlore/Applications.del

Rev

Rev 1815 | Rev 1883 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1815 Rev 1816
Line 18... Line 18...
18
class ListeTaxons {
18
class ListeTaxons {
Line 19... Line 19...
19
 
19
 
20
	private $conteneur;
20
	private $conteneur;
21
	private $navigation;
21
	private $navigation;
-
 
22
	private $bdd;
22
	private $bdd;
23
 
23
	private $parametres = array();
24
	private $resultatsBruts = array();
24
	private $ressources = array();
-
 
Line 25... Line 25...
25
	private $requete = null;
25
	private $resultats = array();
26
 
26
 
27
	public function __construct(Conteneur $conteneur = null) {
-
 
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
27
	public function __construct(Conteneur $conteneur = null) {
29
		$this->conteneur->chargerConfiguration('config_nomstaxons.ini');
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
30
		$this->navigation = $conteneur->getNavigation();
29
		$this->navigation = $this->conteneur->getNavigation();
Line 31... Line -...
31
		$this->bdd = $this->conteneur->getBdd();
-
 
32
	}
-
 
33
 
-
 
34
	/**
-
 
35
	 * Méthode principale de la classe.
-
 
36
	 * @param array $ressources les ressources situées après l'url de base (ex : http://url/ressource1/ressource2)
30
		$this->bdd = $this->conteneur->getBdd();
37
	 * @param array $parametres les paramètres situés après le ? dans l'url
-
 
38
	 * */
-
 
39
	public function consulter($ressources, $parametres) {
-
 
40
		$this->initialiserRessourcesEtParametres($ressources, $parametres);
-
 
41
 
31
	}
42
		// Lancement du service
32
 
43
		$taxons = $this->chargerNoms($this->navigation->getFiltre('masque.referentiel'), $this->navigation->getFiltre('masque.nom'));
33
	public function consulter() {
44
		$total = $this->compterNoms($taxons);
-
 
Line -... Line 34...
-
 
34
		$this->chargerNoms();
45
		$this->navigation->setTotal($total);
35
		$this->formaterResultats();
46
		$this->navigation->setSansLimite();
36
		$this->mettreAJourEnteteResultats();
47
		$resultat = new ResultatService();
37
 
Line -... Line 38...
-
 
38
		$resultat = new ResultatService();
48
 
39
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $this->resultats);
49
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $taxons);
40
		return $resultat;
-
 
41
	}
-
 
42
 
-
 
43
	private function chargerNoms() {
50
		return $resultat;
44
		$referentiel = $this->navigation->getFiltre('masque.referentiel');
-
 
45
		if ($referentiel != 'tous') {
-
 
46
			$requete = urlencode($this->navigation->getFiltre('masque.nom'));
-
 
47
			$url = sprintf($this->conteneur->getParametre('nomstaxons.url_autocompletion_tpl'), $referentiel, $requete);
51
	}
48
 
Line 52... Line -...
52
 
-
 
53
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
-
 
54
		$this->ressources = $ressources;
-
 
55
		$this->parametres = $parametres;
-
 
56
	}
-
 
57
 
-
 
58
	/*-------------------------------------------------------------------------------
49
			$restClient = $this->conteneur->getRestClient();
59
							   CHARGEMENT DES COMMENTAIRES
-
 
60
	--------------------------------------------------------------------------------*/
-
 
61
	/**
-
 
62
	* Chargement depuis le serveur de tous les noms
-
 
63
	* */
50
			$resultatJson = $restClient->consulter($url);
64
	private function chargerNoms($referentiel, $requete) {
51
			$this->resultatsBruts =(array) json_decode($resultatJson, true);
65
		$url = sprintf($this->conteneur->getParametre('url_service_completion_base'), $referentiel, urlencode($requete));
52
		}
66
		$res = json_decode(@file_get_contents($url),true);
53
	}
67
		$res = (array)$res;
54
 
68
		$res_fmt = array();
-
 
69
		if(isset($res['resultat'])) {
55
	private function formaterResultats() {
Line 70... Line -...
70
			foreach($res['resultat'] as $nn => $info_nom) {
-
 
71
				$res_fmt[] = array($info_nom['nom_sci_complet'], (string)$nn);
56
		if (isset($this->resultatsBruts['resultat'])) {
72
			}
57
			foreach ($this->resultatsBruts['resultat'] as $nn => $info) {
73
		}
58
				$this->resultats[] = array($info['nom_sci_complet'], (string)$nn);
74
		return $res_fmt;
59
			}
75
	}
60
		}
76
 
61
	}
77
	/**
62