Subversion Repositories eFlore/Applications.del

Rev

Rev 1863 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
/**
 * Récupère tous les protocoles avec id, nom et descriptif
 *
 * @category   DEL
 * @package    Services
 * @subpackage Protocoles
 * @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 ListeProtocoles {

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

        private $mapping = array();

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

        public function consulter() {
                // Gestion des configuration du script
                $this->mapping = $this->conteneur->getParametreTableau('protocoles.mapping');

                $protocoles = $this->chargerProtocoles();
                $protocoles = $this->formaterProtocoles($protocoles);
                $this->navigation->setTotal(count($protocoles));

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

        private function chargerProtocoles() {
                $requete = 'SELECT * FROM del_image_protocole -- '.__FILE__.' : '.__LINE__;
                return $this->bdd->recupererTous($requete);
        }

        private function formaterProtocoles($protocoles) {
                $protocolesRetour = array();
                foreach ($protocoles as $protocole) {
                        $protocoleFormate = array();
                        $idProtocole = $protocole['id_protocole'];
                        foreach($protocole as $champProtocole => $valeur) {
                                if (isset($this->mapping[$champProtocole])) {
                                        $protocoleFormate[$this->mapping[$champProtocole]] = $valeur;
                                }
                        }
                        $protocolesRetour[$idProtocole] = $protocoleFormate;
                }
                return $protocolesRetour;
        }
}