Subversion Repositories eFlore/Applications.del

Rev

Rev 1808 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
935 gduche 1
<?php
2
// declare(encoding='UTF-8');
3
/**
1707 jpm 4
 * Web service fournissant une liste de noms de communes correspondants au terme recherché.
935 gduche 5
 *
1814 jpm 6
 * @category   DEL
7
 * @package    Services
8
 * @subpackage Communes
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>
935 gduche 16
 */
17
class ListeCommunes {
1700 jpm 18
 
935 gduche 19
	private $conteneur;
20
	private $navigation;
1700 jpm 21
 
935 gduche 22
	public function __construct(Conteneur $conteneur = null) {
23
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
24
		$this->navigation = $conteneur->getNavigation();
25
	}
1700 jpm 26
 
1808 jpm 27
	public function consulter() {
1806 jpm 28
		$communes = $this->chargerCommunes();
935 gduche 29
		$total = $this->compterCommunes($communes);
30
		$this->navigation->setTotal($total);
1794 jpm 31
		$this->navigation->setSansLimite();
1707 jpm 32
 
935 gduche 33
		$resultat = new ResultatService();
1794 jpm 34
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $communes);
935 gduche 35
		return $resultat;
36
	}
1700 jpm 37
 
1806 jpm 38
	private function chargerCommunes() {
1707 jpm 39
		$urlCelTpl = $this->conteneur->getParametre('urlServiceCelCommune');
1806 jpm 40
		$url = $urlCelTpl.$this->navigation->getFiltre('masque.nom');
1707 jpm 41
		$restClient = $this->conteneur->getRestClient();
42
		$resultatJson = $restClient->consulter($url);
43
		$resultat = json_decode($resultatJson);
44
		return $resultat;
935 gduche 45
	}
1700 jpm 46
 
935 gduche 47
	private function compterCommunes($communes) {
1707 jpm 48
		return count($communes);
935 gduche 49
	}
1808 jpm 50
}