Subversion Repositories eFlore/Applications.del

Rev

Rev 1816 | Rev 2132 | 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
			$restClient = $this->conteneur->getRestClient();
49
			$resultatJson = $restClient->consulter($url);
50
			$this->resultatsBruts =(array) json_decode($resultatJson, true);
51
		}
943 gduche 52
	}
1793 jpm 53
 
1816 jpm 54
	private function formaterResultats() {
55
		if (isset($this->resultatsBruts['resultat'])) {
1883 mathias 56
			foreach ($this->resultatsBruts['resultat'] as $info) {
57
				$this->resultats[] = array(
58
					"nn" => $info['num_nom'],
59
					"ns" => $info['nom_sci_complet'],
60
					"retenu" => ($info['retenu'] === "true" ? true : false)
61
				);
1399 aurelien 62
			}
63
		}
943 gduche 64
	}
1793 jpm 65
 
1816 jpm 66
	private function mettreAJourEnteteResultats() {
67
		$total = count($this->resultats);
68
		$this->navigation->setTotal($total);
69
		$this->navigation->setSansLimite();
943 gduche 70
	}
1794 jpm 71
}