Subversion Repositories eFlore/Applications.del

Rev

Rev 1815 | Rev 1883 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
943 gduche 1
<?php
2
// declare(encoding='UTF-8');
3
/**
1815 jpm 4
 * Web service récupèrant une liste de noms de taxons suivant un référentiel et un masque donné.
943 gduche 5
 *
1815 jpm 6
 * @category   DEL
7
 * @package    Services
8
 * @subpackage NomsTaxons
9
 * @version    0.1
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
13
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
943 gduche 16
 */
17
 
18
class ListeTaxons {
1793 jpm 19
 
943 gduche 20
	private $conteneur;
21
	private $navigation;
22
	private $bdd;
1793 jpm 23
 
1816 jpm 24
	private $resultatsBruts = array();
25
	private $resultats = array();
26
 
943 gduche 27
	public function __construct(Conteneur $conteneur = null) {
28
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
1816 jpm 29
		$this->navigation = $this->conteneur->getNavigation();
1793 jpm 30
		$this->bdd = $this->conteneur->getBdd();
943 gduche 31
	}
1793 jpm 32
 
1816 jpm 33
	public function consulter() {
34
		$this->chargerNoms();
35
		$this->formaterResultats();
36
		$this->mettreAJourEnteteResultats();
1793 jpm 37
 
943 gduche 38
		$resultat = new ResultatService();
1816 jpm 39
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $this->resultats);
943 gduche 40
		return $resultat;
41
	}
1793 jpm 42
 
1816 jpm 43
	private function chargerNoms() {
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);
48
 
49
			$restClient = $this->conteneur->getRestClient();
50
			$resultatJson = $restClient->consulter($url);
51
			$this->resultatsBruts =(array) json_decode($resultatJson, true);
52
		}
943 gduche 53
	}
1793 jpm 54
 
1816 jpm 55
	private function formaterResultats() {
56
		if (isset($this->resultatsBruts['resultat'])) {
57
			foreach ($this->resultatsBruts['resultat'] as $nn => $info) {
58
				$this->resultats[] = array($info['nom_sci_complet'], (string)$nn);
1399 aurelien 59
			}
60
		}
943 gduche 61
	}
1793 jpm 62
 
1816 jpm 63
	private function mettreAJourEnteteResultats() {
64
		$total = count($this->resultats);
65
		$this->navigation->setTotal($total);
66
		$this->navigation->setSansLimite();
943 gduche 67
	}
1794 jpm 68
}