| 87 |
jpm |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class blockdedonnees {
|
|
|
4 |
|
|
|
5 |
protected $identifiant;
|
|
|
6 |
protected $donnees;
|
|
|
7 |
protected $collectionBlocksfils;
|
|
|
8 |
protected $erreur;
|
|
|
9 |
|
|
|
10 |
function __construct($identifiant)
|
|
|
11 |
{
|
|
|
12 |
$this->identifiant = $identifiant;
|
|
|
13 |
$this->donnees = array();
|
|
|
14 |
$this->collectionBlocksfils = array();
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
function affecterIdentifiant($identifiant)
|
|
|
18 |
{
|
|
|
19 |
$this->identifiant = $identifiant;
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
function recupererIdentifiant()
|
|
|
23 |
{
|
|
|
24 |
return $this->identifiant;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
function affecterDonnees($donnees)
|
|
|
28 |
{
|
|
|
29 |
$this->donnees = $donnees;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
function recupererDonnees($bool_descendance = FALSE)
|
|
|
33 |
{
|
|
|
34 |
if ($bool_descendance == TRUE) {
|
|
|
35 |
$aso_donnees = array();
|
|
|
36 |
$aso_donnees[$this->recupererIdentifiant()] = $this->donnees;
|
|
|
37 |
$collections_blocks_fils = $this->recupererCollectionBlockFils();
|
|
|
38 |
if (is_array($collections_blocks_fils)) {
|
|
|
39 |
for($i = 0; $i < count($collections_blocks_fils); $i++) {
|
|
|
40 |
$collection = $collections_blocks_fils[$i];
|
|
|
41 |
$blocks_de_donnees = $collection->recupererBlocksDeDonnees();
|
|
|
42 |
for($j = 0; $j < count($blocks_de_donnees); $j++) {
|
|
|
43 |
$block = $blocks_de_donnees[$j];
|
|
|
44 |
$donnees = $block->recupererDonnees();
|
|
|
45 |
$aso_donnees[$this->recupererIdentifiant()][$block->recupererIdentifiant()] = $donnees;
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
return $aso_donnees;
|
|
|
50 |
} else {
|
|
|
51 |
return $this->donnees;
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
function ajouterDonnee($clef, $valeur)
|
|
|
56 |
{
|
|
|
57 |
$this->donnees[$clef] = $valeur;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
function recupererDonnee($clef)
|
|
|
61 |
{
|
|
|
62 |
return $this->donnees[$clef];
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
function recupererErreur()
|
|
|
66 |
{
|
|
|
67 |
return $this->erreur;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
function ajouterCollectionBlockFils($collection_block)
|
|
|
71 |
{
|
|
|
72 |
array_push($this->collectionBlocksfils, $collection_block);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
function recupererCollectionBlockFils()
|
|
|
76 |
{
|
|
|
77 |
return $this->collectionBlocksfils;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
function afficherPattern($chemin, $nom_fonction, $recuperer_descendance = FALSE, $aso_parametres = array())
|
|
|
81 |
{
|
|
|
82 |
$retour = '';
|
|
|
83 |
if($chemin == $this->recupererIdentifiant()) {
|
|
|
84 |
$retour .= call_user_func($nom_fonction, $this->recupererDonnees($recuperer_descendance), $aso_parametres);
|
|
|
85 |
} else {
|
|
|
86 |
$etape_chemin = explode('>', $chemin);
|
|
|
87 |
if($this->identifiant == $etape_chemin[0]) {
|
|
|
88 |
$collection_block_fils = $this->recupererCollectionBlockFils();
|
|
|
89 |
for($i = 0; $i < count($collection_block_fils); $i++) {
|
|
|
90 |
$collection = $collection_block_fils[$i];
|
|
|
91 |
if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
|
|
|
92 |
array_shift($etape_chemin);
|
|
|
93 |
$retour .= $collection->afficherPattern(implode('>', $etape_chemin), $nom_fonction, $recuperer_descendance, $aso_parametres);
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
return $retour;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
function attribuerContexte($chemin, $cle_contexte, $cle_donnee)
|
|
|
102 |
{
|
|
|
103 |
if ($chemin == $this->recupererIdentifiant()) {
|
|
|
104 |
$donnees = $this->recupererDonnees();
|
|
|
105 |
return $donnees;
|
|
|
106 |
} else {
|
|
|
107 |
$etape_chemin = explode('>', $chemin);
|
|
|
108 |
if($this->identifiant == $etape_chemin[0]) {
|
|
|
109 |
$collection_block_fils = $this->recupererCollectionBlockFils();
|
|
|
110 |
for($i = 0; $i < count($collection_block_fils); $i++) {
|
|
|
111 |
$collection = $collection_block_fils[$i];
|
|
|
112 |
if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
|
|
|
113 |
array_shift($etape_chemin);
|
|
|
114 |
$donnees = null;
|
|
|
115 |
$donnees = $collection->attribuerContexte(implode('>', $etape_chemin), $cle_contexte, $cle_donnee);
|
|
|
116 |
if (isset($donnees)) {
|
|
|
117 |
$i = count($collection_block_fils);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
$this->ajouterDonnee($cle_contexte, $donnees[$cle_donnee]);
|
|
|
124 |
return null;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
function afficher()
|
|
|
128 |
{
|
|
|
129 |
echo '<ol>';
|
|
|
130 |
foreach ($this->donnees as $key => $value) {
|
|
|
131 |
echo '<li>'.$key.' : '.$value;
|
|
|
132 |
}
|
|
|
133 |
echo '</ol>';
|
|
|
134 |
for ($i = 0; $i < count($this->collectionBlocksfils); $i++) {
|
|
|
135 |
$collection = $this->collectionBlocksfils[$i];
|
|
|
136 |
echo '<ol>';
|
|
|
137 |
$collection->afficher();
|
|
|
138 |
echo '</ol>';
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
?>
|