Rev 880 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class OntologieDecorateur implements OntologieResponsabilite {
protected $terme = null;
protected $termeFormate = array();
private $detailsHrefTpl = null;
private $langueDemandee = null;
protected $correspondances = array(
'id' => 'Id',
'nom' => 'Intitule',
'description' => 'Description',
'href' => 'Href',
'classe' => 'Classe',
'classe.id' => 'ClasseId',
'classe.href' => 'ClasseHref',
'classe.*' => 'ClasseId,Classe,ClasseHref');
public function __construct(OntologieDO $termeADecorer, $detailsHrefTpl, $langueDemandee) {
$this->terme = $termeADecorer;
$this->detailsHrefTpl = $detailsHrefTpl;
$this->langueDemandee = $langueDemandee;
$this->initialiserTermeFormate();
}
public function traiterChampsRetour(Array $champsRetour) {
foreach ($champsRetour as $champ) {
if (array_key_exists($champ, $this->correspondances)) {
$methodesAExecuter = explode(',', $this->correspondances[$champ]);
foreach ($methodesAExecuter as $methodeNom) {
$methodeAjouter = 'ajouter'.$methodeNom;
if (method_exists($this, $methodeAjouter)) {
$this->$methodeAjouter();
}
}
}
}
}
public function ajouterId() {
$this->termeFormate['id'] = (int) $this->terme->getTag('id_terme');
}
public function ajouterIntitule() {
if ($this->langueDemandee == 'en') {
$this->termeFormate['nom'] = $this->terme->getTag('nom_en');
} else {
$this->termeFormate['nom'] = $this->terme->getTag('nom');
}
}
public function ajouterDescription() {
if ($this->langueDemandee == 'en') {
if ($this->terme->verifierTag('description_en')) {
$this->termeFormate['description'] = $this->terme->getTag('description_en');
}
} else {
if ($this->terme->verifierTag('description')) {
$this->termeFormate['description'] = $this->terme->getTag('description');
}
}
}
public function ajouterHref() {
if ($this->terme->verifierTag('id_terme')) {
$href = sprintf($this->detailsHrefTpl, $this->terme->getTag('id_terme'));
$this->termeFormate['href'] = $href;
}
}
public function ajouterClasseId() {
$this->termeFormate['classe.id'] = (int) $this->terme->getTag('ce_type');
}
public function ajouterClasse() {
$this->termeFormate['classe'] = (string) $this->terme->getTag('type');
}
public function ajouterClasseHref() {
if ($this->terme->verifierTag('ce_type')) {
$href = sprintf($this->detailsHrefTpl, $this->terme->getTag('ce_type'));
$this->termeFormate['classe.href'] = $href;
}
}
public function initialiserTermeFormate() {
$this->termeFormate = array();
}
public function getTermeFormate() {
return $this->termeFormate;
}
}
?>