Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 87 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
62
    function ajouterDonnee($clef, $valeur)
63
    {
64
        $this->donnees[$clef] = $valeur;
65
    }
66
 
67
    function recupererDonnee($clef)
68
    {
69
        return $this->donnees[$clef];
70
    }
71
 
72
    function recupererErreur()
73
    {
74
        return $this->erreur;
75
    }
76
 
77
    function ajouterCollectionBlockFils($collection_block)
78
    {
79
        array_push($this->collectionBlocksfils, $collection_block);
80
    }
81
 
82
    function recupererCollectionBlockFils()
83
    {
84
        return $this->collectionBlocksfils;
85
    }
86
 
106 jpm 87
    function afficherPattern($chemin, $nom_fonction, $aso_parametres = array(), $recuperer_ascendance = FALSE, &$aso_donnees = array())
87 jpm 88
    {
89
        $retour = '';
106 jpm 90
        if ($recuperer_ascendance == TRUE) {
91
            $aso_donnees[$this->recupererIdentifiant()] = $this->recupererDonnees();
92
        }
93
 
94
        if ($chemin == $this->recupererIdentifiant() && $recuperer_ascendance == TRUE) {
95
            $retour .= call_user_func($nom_fonction, $aso_donnees, $aso_parametres);
96
        } else if ($chemin == $this->recupererIdentifiant()) {
97
            $retour .= call_user_func($nom_fonction, $this->recupererDonnees(), $aso_parametres);
87 jpm 98
        } else {
106 jpm 99
            $tab_etape_chemin = explode('>', $chemin);
100
            if($this->recupererIdentifiant() == $tab_etape_chemin[0]) {
87 jpm 101
                $collection_block_fils = $this->recupererCollectionBlockFils();
102
                for($i = 0; $i < count($collection_block_fils); $i++) {
103
                    $collection = $collection_block_fils[$i];
106 jpm 104
                    if ($collection->recupererIdentifiant() == $tab_etape_chemin[1]) {
105
                        array_shift($tab_etape_chemin);
106
                        if ($recuperer_ascendance == TRUE) {
107
                            $retour .= $collection->afficherPattern(implode('>', $tab_etape_chemin), $nom_fonction, $aso_parametres, $recuperer_ascendance, $aso_donnees);
108
                        } else {
109
                            $retour .= $collection->afficherPattern(implode('>', $tab_etape_chemin), $nom_fonction, $aso_parametres);
110
                        }
87 jpm 111
                    }
112
                }
113
            }
114
        }
115
        return $retour;
116
    }
117
 
106 jpm 118
    function attribuerContexteSql($chemin, $cle_contexte, $cle_donnee)
87 jpm 119
    {
120
        if ($chemin == $this->recupererIdentifiant()) {
121
            $donnees = $this->recupererDonnees();
122
            return $donnees;
123
        } else {
124
            $etape_chemin = explode('>', $chemin);
125
            if($this->identifiant == $etape_chemin[0]) {
126
                $collection_block_fils = $this->recupererCollectionBlockFils();
127
                for($i = 0; $i < count($collection_block_fils); $i++) {
128
                    $collection = $collection_block_fils[$i];
129
                    if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
130
                        array_shift($etape_chemin);
131
                        $donnees = null;
106 jpm 132
                        $donnees = $collection->attribuerContexteSql(implode('>', $etape_chemin), $cle_contexte, $cle_donnee);
87 jpm 133
                        if (isset($donnees)) {
134
                            $i = count($collection_block_fils);
135
                        }
136
                    }
137
                }
138
            }
139
        }
140
        $this->ajouterDonnee($cle_contexte, $donnees[$cle_donnee]);
141
        return null;
142
    }
143
 
106 jpm 144
    function attribuerContexteValeur($chemin, $cle_contexte, $valeur = null)
145
    {
146
        if ($chemin == $this->recupererIdentifiant()) {
147
            $this->ajouterDonnee($cle_contexte, $valeur);
148
            return null;
149
        } else {
150
            $etape_chemin = explode('>', $chemin);
151
            if($this->identifiant == $etape_chemin[0]) {
152
                $collection_block_fils = $this->recupererCollectionBlockFils();
153
                for($i = 0; $i < count($collection_block_fils); $i++) {
154
                    $collection = $collection_block_fils[$i];
155
                    if ($collection->recupererIdentifiant() == $etape_chemin[1]) {
156
                        array_shift($etape_chemin);
157
                        $donnees = null;
158
                        $donnees = $collection->attribuerContexteValeur(implode('>', $etape_chemin), $cle_contexte, $valeur);
159
                        if (isset($donnees)) {
160
                            $i = count($collection_block_fils);
161
                        }
162
                    }
163
                }
164
            }
165
        }
166
        return null;
167
    }
168
 
87 jpm 169
    function afficher()
170
    {
171
        echo '<ol>';
172
        foreach ($this->donnees as $key => $value) {
173
            echo '<li>'.$key.' : '.$value;
174
        }
175
        echo '</ol>';
176
        for ($i = 0; $i < count($this->collectionBlocksfils); $i++) {
177
            $collection = $this->collectionBlocksfils[$i];
178
            echo '<ol>';
179
            $collection->afficher();
180
            echo '</ol>';
181
        }
182
    }
183
}
184
?>