Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 106 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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