231 |
jpm |
1 |
<?php
|
|
|
2 |
class OntologieDecorateur implements OntologieResponsabilite {
|
|
|
3 |
protected $terme = null;
|
|
|
4 |
protected $termeFormate = array();
|
|
|
5 |
private $detailsHrefTpl = null;
|
|
|
6 |
private $langueDemandee = null;
|
|
|
7 |
protected $correspondances = array(
|
|
|
8 |
'id' => 'Id',
|
|
|
9 |
'nom' => 'Intitule',
|
|
|
10 |
'description' => 'Description',
|
|
|
11 |
'href' => 'Href',
|
|
|
12 |
'classe' => 'Classe',
|
|
|
13 |
'classe.id' => 'ClasseId',
|
|
|
14 |
'classe.href' => 'ClasseHref',
|
|
|
15 |
'classe.*' => 'ClasseId,Classe,ClasseHref');
|
|
|
16 |
|
|
|
17 |
public function __construct(OntologieDO $termeADecorer, $detailsHrefTpl, $langueDemandee) {
|
|
|
18 |
$this->terme = $termeADecorer;
|
|
|
19 |
$this->detailsHrefTpl = $detailsHrefTpl;
|
|
|
20 |
$this->langueDemandee = $langueDemandee;
|
|
|
21 |
$this->initialiserTermeFormate();
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public function traiterChampsRetour(Array $champsRetour) {
|
|
|
25 |
foreach ($champsRetour as $champ) {
|
|
|
26 |
if (array_key_exists($champ, $this->correspondances)) {
|
|
|
27 |
$methodesAExecuter = explode(',', $this->correspondances[$champ]);
|
|
|
28 |
foreach ($methodesAExecuter as $methodeNom) {
|
|
|
29 |
$methodeAjouter = 'ajouter'.$methodeNom;
|
|
|
30 |
if (method_exists($this, $methodeAjouter)) {
|
|
|
31 |
$this->$methodeAjouter();
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public function ajouterId() {
|
|
|
39 |
$this->termeFormate['id'] = (int) $this->terme->getTag('id_terme');
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public function ajouterIntitule() {
|
|
|
43 |
if ($this->langueDemandee == 'en') {
|
|
|
44 |
$this->termeFormate['nom'] = $this->terme->getTag('nom_en');
|
|
|
45 |
} else {
|
|
|
46 |
$this->termeFormate['nom'] = $this->terme->getTag('nom');
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function ajouterDescription() {
|
|
|
51 |
if ($this->langueDemandee == 'en') {
|
|
|
52 |
if ($this->terme->verifierTag('description_en')) {
|
|
|
53 |
$this->termeFormate['description'] = $this->terme->getTag('description_en');
|
|
|
54 |
}
|
|
|
55 |
} else {
|
|
|
56 |
if ($this->terme->verifierTag('description')) {
|
|
|
57 |
$this->termeFormate['description'] = $this->terme->getTag('description');
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function ajouterHref() {
|
|
|
63 |
if ($this->terme->verifierTag('id_terme')) {
|
|
|
64 |
$href = sprintf($this->detailsHrefTpl, $this->terme->getTag('id_terme'));
|
|
|
65 |
$this->termeFormate['href'] = $href;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public function ajouterClasseId() {
|
|
|
70 |
$this->termeFormate['classe.id'] = (int) $this->terme->getTag('ce_type');
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public function ajouterClasse() {
|
|
|
74 |
$this->termeFormate['classe'] = (string) $this->terme->getTag('type');
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
public function ajouterClasseHref() {
|
|
|
78 |
if ($this->terme->verifierTag('ce_type')) {
|
|
|
79 |
$href = sprintf($this->detailsHrefTpl, $this->terme->getTag('ce_type'));
|
|
|
80 |
$this->termeFormate['classe.href'] = $href;
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public function initialiserTermeFormate() {
|
|
|
85 |
$this->termeFormate = array();
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public function getTermeFormate() {
|
|
|
89 |
return $this->termeFormate;
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
?>
|