Subversion Repositories eFlore/Applications.del

Rev

Rev 2132 | 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');
2134 mathias 45
 
1816 jpm 46
		if ($referentiel != 'tous') {
47
			$requete = urlencode($this->navigation->getFiltre('masque.nom'));
48
			$url = sprintf($this->conteneur->getParametre('nomstaxons.url_autocompletion_tpl'), $referentiel, $requete);
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'])) {
1883 mathias 57
			foreach ($this->resultatsBruts['resultat'] as $info) {
58
				$this->resultats[] = array(
59
					"nn" => $info['num_nom'],
60
					"ns" => $info['nom_sci_complet'],
61
					"retenu" => ($info['retenu'] === "true" ? true : false)
62
				);
1399 aurelien 63
			}
64
		}
943 gduche 65
	}
1793 jpm 66
 
1816 jpm 67
	private function mettreAJourEnteteResultats() {
68
		$total = count($this->resultats);
69
		$this->navigation->setTotal($total);
70
		$this->navigation->setSansLimite();
943 gduche 71
	}
1794 jpm 72
}