Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

<?php
class OntologieFormateur {

        private $termeAFormater = null;
        private $decorateurs = array();
        private $bdd = null;
        private $champsProjet = array();
        private $champsRetour = null;
        private $detailsHrefTpl = null;
        private $langueDemandee = null;

        public function setTermeAFormater(OntologieDO $ontologieDO) {
                $this->termeAFormater = $ontologieDO;
        }

        public function setChampsRetour(Array $champsRetour) {
                $this->champsRetour = $champsRetour;
        }

        public function setChampsProjet(Array $champsProjet) {
                $this->champsProjet = $champsProjet;
        }

        public function setDetailsHrefTpl($tpl) {
                $this->detailsHrefTpl = $tpl;
        }

        public function setLangueDemandee($langue) {
                $this->langueDemandee = $langue;
        }

        public function setBdd($bdd) {
                $this->bdd = $bdd;
        }

        public function formaterDetails() {
                $termeDeco = new OntologieDecorateur($this->termeAFormater, $this->detailsHrefTpl, $this->langueDemandee);
                $projetDeco = new OntologieChampsProjetDecorateur($termeDeco, $this->champsProjet);

                if ($this->avoirDemandeChampsRetour()) {
                        $this->decorateurs[] = $termeDeco;
                        $this->decorateurs[] = $projetDeco;

                        $this->traiterChampsRetour();
                } else {
                        $termeDeco->ajouterId();
                        $termeDeco->ajouterIntitule();
                        $termeDeco->ajouterDescription();
                        $termeDeco->ajouterClasseId();
                        $termeDeco->ajouterClasse();
                        $termeDeco->ajouterClasseHref();

                        $projetDeco->ajouterChampsSupplementaires();
                }

                return $termeDeco->getTermeFormate();
        }

        public function formaterListe() {
                $termeDeco = new OntologieDecorateur($this->termeAFormater, $this->detailsHrefTpl, $this->langueDemandee);
                $termeDeco->ajouterId();
                $termeDeco->ajouterIntitule();
                $termeDeco->ajouterHref();

                if ($this->avoirDemandeChampsRetour()) {
                        $this->decorateurs[] = $termeDeco;
                        $this->decorateurs[] = new OntologieChampsProjetDecorateur($termeDeco, $this->champsProjet);

                        $this->traiterChampsRetour();
                }

                return $termeDeco->getTermeFormate();
        }

        private function avoirDemandeChampsRetour() {
                $demande = true;
                if ($this->champsRetour === null || count($this->champsRetour) == 0) {
                        $demande = false;
                }
                return $demande;
        }

        private function traiterChampsRetour() {
                foreach ($this->decorateurs as $deco) {
                        $deco->traiterChampsRetour($this->champsRetour);
                }
        }
}
?>