Subversion Repositories eFlore/Applications.del

Rev

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

<?php
// declare(encoding='UTF-8');
/**
 * Web service récupèrant une liste de noms de taxons suivant un référentiel et un masque donné.
 *
 * @category   DEL
 * @package    Services
 * @subpackage NomsTaxons
 * @version    0.1
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
 * @author     Aurelien PERONNET <aurelien@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 ListeTaxons {

        private $conteneur;
        private $navigation;
        private $bdd;

        private $resultatsBruts = array();
        private $resultats = array();

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

        public function consulter() {
                $this->chargerNoms();
                $this->formaterResultats();
                $this->mettreAJourEnteteResultats();

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

        private function chargerNoms() {
                $referentiel = $this->navigation->getFiltre('masque.referentiel');
                if ($referentiel != 'tous') {
                        $requete = urlencode($this->navigation->getFiltre('masque.nom'));
                        $url = sprintf($this->conteneur->getParametre('nomstaxons.url_autocompletion_tpl'), $referentiel, $requete);
                        $restClient = $this->conteneur->getRestClient();
                        $resultatJson = $restClient->consulter($url);
                        $this->resultatsBruts =(array) json_decode($resultatJson, true);
                }
        }

        private function formaterResultats() {
                if (isset($this->resultatsBruts['resultat'])) {
                        foreach ($this->resultatsBruts['resultat'] as $info) {
                                $this->resultats[] = array(
                                        "nn" => $info['num_nom'],
                                        "ns" => $info['nom_sci_complet'],
                                        "retenu" => ($info['retenu'] === "true" ? true : false)
                                );
                        }
                }
        }

        private function mettreAJourEnteteResultats() {
                $total = count($this->resultats);
                $this->navigation->setTotal($total);
                $this->navigation->setSansLimite();
        }
}