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 |
|
106 |
jpm |
32 |
function recupererDonnees()
|
87 |
jpm |
33 |
{
|
106 |
jpm |
34 |
return $this->donnees;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
function recupererDonneesRecursivement($tab_chemin, $aso_retour = array())
|
|
|
38 |
{
|
|
|
39 |
|
|
|
40 |
if ($tab_chemin[0] == $this->recupererIdentifiant()) {
|
|
|
41 |
return $aso_retour[$this->recupererIdentifiant()] = $this->donnees;
|
|
|
42 |
|
|
|
43 |
$collection_block_fils = $this->recupererCollectionBlockFils();
|
|
|
44 |
for($i = 0; $i < count($collection_block_fils); $i++) {
|
|
|
45 |
$collection = $collection_block_fils[$i];
|
|
|
46 |
|
|
|
47 |
if ($collection->recupererIdentifiant() == $tab_chemin[1]) {
|
|
|
48 |
$blocks = $collection->recupererBlocksDeDonnees();
|
|
|
49 |
|
|
|
50 |
for($j = 0; $j < count($blocks); $j++) {
|
|
|
51 |
$block = $blocks[$j];
|
|
|
52 |
|
|
|
53 |
$block->recupererDonneesRecursivement(array_shift($tab_chemin), $aso_retour);
|
|
|
54 |
|
87 |
jpm |
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
}
|
106 |
jpm |
59 |
return $aso_retour;
|
87 |
jpm |
60 |
}
|
|
|
61 |
|
139 |
jpm |
62 |
function recupererDonneesRecursivementSsChemin($un_block)
|
|
|
63 |
{
|
|
|
64 |
$aso_donnees = array();
|
|
|
65 |
$aso_donnees = $un_block->recupererDonnees();
|
|
|
66 |
$collection_block_fils = $un_block->recupererCollectionBlockFils();
|
|
|
67 |
|
|
|
68 |
for($i = 0; $i < count($collection_block_fils); $i++) {
|
|
|
69 |
$une_collection = $collection_block_fils[$i];
|
|
|
70 |
$blocks_de_donnees = $une_collection->recupererBlocksDeDonnees();
|
|
|
71 |
for ($i = 0; $i < count($blocks_de_donnees); $i++) {
|
|
|
72 |
$block = $blocks_de_donnees[$i];
|
|
|
73 |
$aso_donnees[$block->recupererIdentifiant()] = $this->recupererDonneesRecursivementSsChemin($block);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
return $aso_donnees;
|
|
|
77 |
}
|
|
|
78 |
|
87 |
jpm |
79 |
function ajouterDonnee($clef, $valeur)
|
|
|
80 |
{
|
|
|
81 |
$this->donnees[$clef] = $valeur;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
function recupererDonnee($clef)
|
|
|
85 |
{
|
|
|
86 |
return $this->donnees[$clef];
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
function recupererErreur()
|
|
|
90 |
{
|
|
|
91 |
return $this->erreur;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
function ajouterCollectionBlockFils($collection_block)
|
|
|
95 |
{
|
|
|
96 |
array_push($this->collectionBlocksfils, $collection_block);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
function recupererCollectionBlockFils()
|
|
|
100 |
{
|
|
|
101 |
return $this->collectionBlocksfils;
|
|
|
102 |
}
|
|
|
103 |
|
139 |
jpm |
104 |
function afficherPatternRecursivement($nom_fonction, $aso_parametres = array())
|
|
|
105 |
{
|
|
|
106 |
$retour = '';
|
|
|
107 |
$aso_donnees = $this->recupererDonneesRecursivementSsChemin($this);
|
|
|
108 |
return call_user_func($nom_fonction, $aso_donnees, $aso_parametres);
|
|
|
109 |
}
|
|
|
110 |
|
106 |
jpm |
111 |
function afficherPattern($chemin, $nom_fonction, $aso_parametres = array(), $recuperer_ascendance = FALSE, &$aso_donnees = array())
|
87 |
jpm |
112 |
{
|
|
|
113 |
$retour = '';
|
106 |
jpm |
114 |
if ($recuperer_ascendance == TRUE) {
|
|
|
115 |
$aso_donnees[$this->recupererIdentifiant()] = $this->recupererDonnees();
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
if ($chemin == $this->recupererIdentifiant() && $recuperer_ascendance == TRUE) {
|
|
|
119 |
$retour .= call_user_func($nom_fonction, $aso_donnees, $aso_parametres);
|
|
|
120 |
} else if ($chemin == $this->recupererIdentifiant()) {
|
|
|
121 |
$retour .= call_user_func($nom_fonction, $this->recupererDonnees(), $aso_parametres);
|
87 |
jpm |
122 |
} else {
|
106 |
jpm |
123 |
$tab_etape_chemin = explode('>', $chemin);
|
|
|
124 |
if($this->recupererIdentifiant() == $tab_etape_chemin[0]) {
|
87 |
jpm |
125 |
$collection_block_fils = $this->recupererCollectionBlockFils();
|
|
|
126 |
for($i = 0; $i < count($collection_block_fils); $i++) {
|
|
|
127 |
$collection = $collection_block_fils[$i];
|
106 |
jpm |
128 |
if ($collection->recupererIdentifiant() == $tab_etape_chemin[1]) {
|
|
|
129 |
array_shift($tab_etape_chemin);
|
|
|
130 |
if ($recuperer_ascendance == TRUE) {
|
|
|
131 |
$retour .= $collection->afficherPattern(implode('>', $tab_etape_chemin), $nom_fonction, $aso_parametres, $recuperer_ascendance, $aso_donnees);
|
|
|
132 |
} else {
|
|
|
133 |
$retour .= $collection->afficherPattern(implode('>', $tab_etape_chemin), $nom_fonction, $aso_parametres);
|
|
|
134 |
}
|
87 |
jpm |
135 |
}
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
return $retour;
|
|
|
140 |
}
|
|
|
141 |
|
106 |
jpm |
142 |
function attribuerContexteSql($chemin, $cle_contexte, $cle_donnee)
|
87 |
jpm |
143 |
{
|
|
|
144 |
if ($chemin == $this->recupererIdentifiant()) {
|
|
|
145 |
$donnees = $this->recupererDonnees();
|
|
|
146 |
return $donnees;
|
|
|
147 |
} else {
|
|
|
148 |
$etape_chemin = explode('>', $chemin);
|
|
|
149 |
if($this->identifiant == $etape_chemin[0]) {
|
|
|
150 |
$collection_block_fils = $this->recupererCollectionBlockFils();
|
|
|
151 |
for($i = 0; $i < count($collection_block_fils); $i++) {
|
|
|
152 |
$collection = $collection_block_fils[$i];
|
|
|
153 |
if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
|
|
|
154 |
array_shift($etape_chemin);
|
|
|
155 |
$donnees = null;
|
106 |
jpm |
156 |
$donnees = $collection->attribuerContexteSql(implode('>', $etape_chemin), $cle_contexte, $cle_donnee);
|
87 |
jpm |
157 |
if (isset($donnees)) {
|
|
|
158 |
$i = count($collection_block_fils);
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
$this->ajouterDonnee($cle_contexte, $donnees[$cle_donnee]);
|
|
|
165 |
return null;
|
|
|
166 |
}
|
|
|
167 |
|
106 |
jpm |
168 |
function attribuerContexteValeur($chemin, $cle_contexte, $valeur = null)
|
|
|
169 |
{
|
|
|
170 |
if ($chemin == $this->recupererIdentifiant()) {
|
|
|
171 |
$this->ajouterDonnee($cle_contexte, $valeur);
|
|
|
172 |
return null;
|
|
|
173 |
} else {
|
|
|
174 |
$etape_chemin = explode('>', $chemin);
|
|
|
175 |
if($this->identifiant == $etape_chemin[0]) {
|
|
|
176 |
$collection_block_fils = $this->recupererCollectionBlockFils();
|
|
|
177 |
for($i = 0; $i < count($collection_block_fils); $i++) {
|
|
|
178 |
$collection = $collection_block_fils[$i];
|
|
|
179 |
if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
|
|
|
180 |
array_shift($etape_chemin);
|
|
|
181 |
$donnees = null;
|
|
|
182 |
$donnees = $collection->attribuerContexteValeur(implode('>', $etape_chemin), $cle_contexte, $valeur);
|
|
|
183 |
if (isset($donnees)) {
|
|
|
184 |
$i = count($collection_block_fils);
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
return null;
|
|
|
191 |
}
|
|
|
192 |
|
87 |
jpm |
193 |
function afficher()
|
|
|
194 |
{
|
|
|
195 |
echo '<ol>';
|
|
|
196 |
foreach ($this->donnees as $key => $value) {
|
|
|
197 |
echo '<li>'.$key.' : '.$value;
|
|
|
198 |
}
|
|
|
199 |
echo '</ol>';
|
|
|
200 |
for ($i = 0; $i < count($this->collectionBlocksfils); $i++) {
|
|
|
201 |
$collection = $this->collectionBlocksfils[$i];
|
|
|
202 |
echo '<ol>';
|
|
|
203 |
$collection->afficher();
|
|
|
204 |
echo '</ol>';
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
?>
|