Subversion Repositories eFlore/Applications.del

Rev

Rev 1806 | Go to most recent revision | 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
 *
1707 jpm 6
 * @category	DEL
7
 * @package		Services
8
 * @subpackage	Communes
9
 * @version		0.1
935 gduche 10
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
1707 jpm 11
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
12
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
13
 * @copyright	©1999-2014, Tela Botanica (<accueil@tela-botanica.org>)
935 gduche 14
 */
15
class ListeCommunes {
1700 jpm 16
 
935 gduche 17
	private $conteneur;
18
	private $navigation;
1700 jpm 19
 
935 gduche 20
	public function __construct(Conteneur $conteneur = null) {
21
		$this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
22
		$this->navigation = $conteneur->getNavigation();
23
	}
1700 jpm 24
 
1808 jpm 25
	public function consulter() {
1806 jpm 26
		$communes = $this->chargerCommunes();
935 gduche 27
		$total = $this->compterCommunes($communes);
28
		$this->navigation->setTotal($total);
1794 jpm 29
		$this->navigation->setSansLimite();
1707 jpm 30
 
935 gduche 31
		$resultat = new ResultatService();
1794 jpm 32
		$resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $communes);
935 gduche 33
		return $resultat;
34
	}
1700 jpm 35
 
1806 jpm 36
	private function chargerCommunes() {
1707 jpm 37
		$urlCelTpl = $this->conteneur->getParametre('urlServiceCelCommune');
1806 jpm 38
		$url = $urlCelTpl.$this->navigation->getFiltre('masque.nom');
1707 jpm 39
		$restClient = $this->conteneur->getRestClient();
40
		$resultatJson = $restClient->consulter($url);
41
		$resultat = json_decode($resultatJson);
42
		return $resultat;
935 gduche 43
	}
1700 jpm 44
 
935 gduche 45
	private function compterCommunes($communes) {
1707 jpm 46
		return count($communes);
935 gduche 47
	}
1808 jpm 48
}