Subversion Repositories eFlore/Applications.del

Rev

Rev 1806 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
/**
 * Web service fournissant une liste de noms de communes correspondants au terme recherché.
 *
 * @category    DEL
 * @package             Services
 * @subpackage  Communes
 * @version             0.1
 * @author              Jean-Pascal MILCENT <jpm@tela-botanica.org>
 * @license             GPL v3 <http://www.gnu.org/licenses/gpl.txt>
 * @license             CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
 * @copyright   ©1999-2014, Tela Botanica (<accueil@tela-botanica.org>)
 */
class ListeCommunes {

        private $conteneur;
        private $navigation;

        public function __construct(Conteneur $conteneur = null) {
                $this->conteneur = $conteneur == null ? new Conteneur() : $conteneur;
                $this->navigation = $conteneur->getNavigation();
        }

        public function consulter() {
                $communes = $this->chargerCommunes();
                $total = $this->compterCommunes($communes);
                $this->navigation->setTotal($total);
                $this->navigation->setSansLimite();

                $resultat = new ResultatService();
                $resultat->corps = array('entete' => $this->navigation->getEntete(), 'resultats' => $communes);
                return $resultat;
        }

        private function chargerCommunes() {
                $urlCelTpl = $this->conteneur->getParametre('urlServiceCelCommune');
                $url = $urlCelTpl.$this->navigation->getFiltre('masque.nom');
                $restClient = $this->conteneur->getRestClient();
                $resultatJson = $restClient->consulter($url);
                $resultat = json_decode($resultatJson);
                return $resultat;
        }

        private function compterCommunes($communes) {
                return count($communes);
        }
}