Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

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

Rev 140 Rev 145
1
<?php
1
<?php
2
 
2
 
3
class macroElement implements iMacroElement{
3
class macroElement implements iMacroElement{
4
    
4
    
5
    protected $identifiantblockdedonnees;
5
    protected $identifiantblockdedonnees;
6
    protected $identifiant_parent;
6
    protected $identifiant_parent;
7
    protected $connexion;
7
    protected $connexion;
8
    protected $contexteRef;
8
    protected $contexteRef;
9
    protected $contexteRefTmp;
9
    protected $contexteRefTmp;
-
 
10
    protected $contexteChemin;
10
    protected $contexteSQL;
11
    protected $contexteSQL;
11
    protected $blockdedonneesParent;
12
    protected $blockdedonneesParent;
12
    protected $collectionblockdedonnees;
13
    protected $collectionblockdedonnees;
13
    protected $idRes;
14
    protected $idRes;
14
    
15
    
15
    function __construct($une_connexion, $un_block_donnees_parent, $chemin_macro_element)
16
    function __construct($une_connexion, $un_block_donnees_parent, $chemin_macro_element)
16
    {
17
    {
17
        $this->connexion = $une_connexion;
18
        $this->connexion = $une_connexion;
18
        $this->blockdedonneesParent = $un_block_donnees_parent;
19
        $this->blockdedonneesParent = $un_block_donnees_parent;
19
        $tab_etape_chemin = array_reverse(explode('>', $chemin_macro_element));
20
        $tab_etape_chemin = array_reverse(explode('>', $chemin_macro_element));
20
        $identifiant = $tab_etape_chemin[0];
21
        $this->identifiantblockdedonnees = $tab_etape_chemin[0];
21
        $this->identifiantblockdedonnees = $identifiant;
22
        $this->identifiant_parent = NULL;//$this->blockdedonneesParent->recupererIdentifiant();
-
 
23
        $this->contexteRef = $this->blockdedonneesParent->recupererDonnees();
-
 
24
        $this->contexteMultiple = FALSE;
22
        if (count($tab_etape_chemin) > 1) {
25
        if (count($tab_etape_chemin) > 1) {
-
 
26
            $this->contexteMultiple = TRUE;
23
            $this->identifiant_parent = $tab_etape_chemin[1];
27
            $this->identifiant_parent = $tab_etape_chemin[1];
24
            $this->contexteRef = $this->attribuerContexteRef($this->blockdedonneesParent);
-
 
25
        } else {
-
 
26
            $this->identifiant_parent = NULL;
-
 
27
            $this->contexteRef = $this->blockdedonneesParent->recupererDonnees();
-
 
28
        }
28
        }
29
    }
29
    }
30
    
30
    
31
    function attribuerContexteRef($un_block_donnees)
31
    function attribuerContexteRef($un_block_donnees, $id)
32
    {
32
    {
33
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
33
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
34
        for($i = 0; $i < count($collection_block_fils); $i++) {
34
        for($i = 0; $i < count($collection_block_fils); $i++) {
35
            $collection = $collection_block_fils[$i];
35
            $collection = $collection_block_fils[$i];
36
            if ($collection->recupererIdentifiant() == $this->identifiant_parent) {
36
            if ($collection->recupererIdentifiant() == $id) {
37
                return $collection->recupererBlocksDeDonnees();
37
                return $collection->recupererBlocksDeDonnees();
38
            } else if (is_object($un_block_donnees->recupererCollectionBlockFils())) {
38
            } else if (is_object($un_block_donnees->recupererCollectionBlockFils())) {
39
                $this->attribuerContexteRef($un_block_donnees->recupererCollectionBlockFils());
39
                $this->attribuerContexteRef($un_block_donnees->recupererCollectionBlockFils(), $id);
40
            }
40
            }
41
        }
41
        }
42
    }
42
    }
43
    
43
    
44
    function attribuerCollectionBlockFils($un_block_donnees, $id)
44
    function attribuerCollectionBlockFils($un_block_donnees, $id, $num = null, $num_courant = null)
45
    {
45
    {
-
 
46
        if ($un_block_donnees->recupererIdentifiant() == $id AND is_null($num)) {
-
 
47
            return $un_block_donnees->ajouterCollectionBlockFils($this->collectionblockdedonnees);
-
 
48
        } else if ($un_block_donnees->recupererIdentifiant() == $id AND !is_null($num) AND $num == $num_courant) {
-
 
49
            //echo '<pre>'.print_r($this->contexteRefTmp, true).'</pre>';
46
        if ($un_block_donnees->recupererIdentifiant() == $id ) {
50
            //echo $un_block_donnees->recupererIdentifiant().'----'.$num.'-'.$num_courant.'<br />';
47
            return $un_block_donnees->ajouterCollectionBlockFils($this->collectionblockdedonnees);
51
            return $un_block_donnees->ajouterCollectionBlockFils($this->collectionblockdedonnees);
48
        } else if (is_array($un_block_donnees->recupererCollectionBlockFils()) AND count($un_block_donnees->recupererCollectionBlockFils()) > 0) {
52
        } else if (is_array($un_block_donnees->recupererCollectionBlockFils()) AND count($un_block_donnees->recupererCollectionBlockFils()) > 0) {
49
            $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
53
            $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
50
            for($i = 0; $i < count($collection_block_fils); $i++) {
54
            for($i = 0; $i < count($collection_block_fils); $i++) {
51
                $blocks_de_donnees = $collection_block_fils[$i]->recupererBlocksDeDonnees();
55
                $blocks_de_donnees = $collection_block_fils[$i]->recupererBlocksDeDonnees();
52
                for ($i = 0; $i < count($blocks_de_donnees); $i++) {
56
                for ($j = 0; $j < count($blocks_de_donnees); $j++) {
-
 
57
                    //echo $blocks_de_donnees[$j]->recupererIdentifiant().'-'.$id.'----'.$num.'-'.$j.'<br />';
53
                    $this->attribuerCollectionBlockFils($blocks_de_donnees[$i], $id);
58
                    $this->attribuerCollectionBlockFils($blocks_de_donnees[$j], $id, $num, $j);
54
                }
59
                }
55
            }
60
            }
56
        }
61
        }
57
    }
62
    }
58
    
63
    
59
    function recupererCollectionBlockFils($un_block_donnees, $id)
64
    function recupererCollectionBlockFils($un_block_donnees, $id)
60
    {
65
    {
61
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
66
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
62
        for($i = 0; $i < count($collection_block_fils); $i++) {
67
        for($i = 0; $i < count($collection_block_fils); $i++) {
63
            $une_collection = $collection_block_fils[$i];
68
            $une_collection = $collection_block_fils[$i];
64
            if ($une_collection->recupererIdentifiant() == $id ) {
69
            if ($une_collection->recupererIdentifiant() == $id ) {
65
                return $une_collection->recupererBlocksDeDonnees();
70
                return $une_collection->recupererBlocksDeDonnees();
66
            } else {
71
            } else {
67
                $blocks_de_donnees = $une_collection->recupererBlocksDeDonnees();
72
                $blocks_de_donnees = $une_collection->recupererBlocksDeDonnees();
68
                for ($i = 0; $i < count($blocks_de_donnees); $i++) {
73
                for ($i = 0; $i < count($blocks_de_donnees); $i++) {
69
                    $block = $blocks_de_donnees[$i];
74
                    $block = $blocks_de_donnees[$i];
70
                    if (is_array($block->recupererCollectionBlockFils()) AND count($block->recupererCollectionBlockFils()) > 0) {
75
                    if (is_array($block->recupererCollectionBlockFils()) AND count($block->recupererCollectionBlockFils()) > 0) {
71
                        return $this->recupererCollectionBlockFils($block, $id);
76
                        return $this->recupererCollectionBlockFils($block, $id);
72
                    }
77
                    }
73
                }
78
                }
74
            }
79
            }
75
        }
80
        }
76
        return null;
81
        return null;
77
    }
82
    }
78
    
83
    
79
    function construire()
84
    function construire()
80
    {
85
    {
-
 
86
        if ($this->contexteMultiple == FALSE) {
81
        $sql = $this->getSQL();
87
            $sql = $this->getSQL();
82
        if (!is_null($sql)) {
88
            if (!is_null($sql)) {
83
            $this->openCursor($sql);
89
                $this->openCursor($sql);
84
            while ($this->fetch());
90
                while ($this->fetch());
85
            $this->closeCursor();
91
                $this->closeCursor();
-
 
92
            }
-
 
93
        } else {
-
 
94
            $this->contexteRefTmp = $this->attribuerContexteRef($this->blockdedonneesParent, $this->identifiant_parent);
-
 
95
            //echo '<pre>'.print_r($this->contexteRefTmp, true).'</pre>';
-
 
96
            for($i = 0; $i < count($this->contexteRefTmp); $i++) {
-
 
97
                $this->contexteRef = $this->contexteRefTmp[$i]->recupererDonnees();
-
 
98
                $sql = $this->getSQL();
-
 
99
                if (!is_null($sql)) {
-
 
100
                    $this->openCursor($sql);
-
 
101
                    while ($this->fetch());
-
 
102
                    $this->closeCursor($this->identifiant_parent, $i);
-
 
103
                }
-
 
104
            }
86
        }
105
        }
87
    }
106
    }
88
    
107
    
89
    function construireParRecursivite($niveau_max, $aso_contexte = null, $id = null)
108
    function construireParRecursivite($niveau_max, $aso_contexte = null, $id = null)
90
    {
109
    {
91
        static $niveau_courant = 0;
110
        static $niveau_courant = 0;
92
        if ($niveau_courant > $niveau_max) {
111
        if ($niveau_courant > $niveau_max) {
93
            return null;
112
            return null;
94
        }
113
        }
95
        
114
        
96
        if (!is_null($aso_contexte)) {
115
        if (!is_null($aso_contexte)) {
97
            $this->contexteRef = $aso_contexte;
116
            $this->contexteRef = $aso_contexte;
98
        }
117
        }
99
        if (is_null($id)) {
118
        if (is_null($id)) {
100
            $id = $this->identifiantblockdedonnees;
119
            $id = $this->identifiantblockdedonnees;
101
            $this->identifiant_parent = $this->blockdedonneesParent->recupererIdentifiant();
120
            $this->identifiant_parent = $this->blockdedonneesParent->recupererIdentifiant();
102
        } else {
121
        } else {
103
            $this->identifiant_parent = $id;
122
            $this->identifiant_parent = $id;
104
        }
123
        }
105
        
124
        
106
        $sql = $this->getSQL();
125
        $sql = $this->getSQL();
107
        //echo '<pre>'.print_r($sql, true).'</pre>';
-
 
108
        if (!is_null($sql)) {
126
        if (!is_null($sql)) {
109
            $this->openCursor($sql, $id);
127
            $this->openCursor($sql, $id);
110
            for ($i = 0; $this->fetch($id.'-'.$i); $i++);
128
            for ($i = 0; $this->fetch($id.'-'.$i); $i++);
111
            $this->closeCursor($this->identifiant_parent);
129
            $this->closeCursor($this->identifiant_parent);
112
            
130
            
113
            $blocks_de_donnees = $this->recupererCollectionBlockFils($this->blockdedonneesParent, $id);
131
            $blocks_de_donnees = $this->recupererCollectionBlockFils($this->blockdedonneesParent, $id);
114
            if (count($blocks_de_donnees) > 0) {
132
            if (count($blocks_de_donnees) > 0) {
115
                $niveau_courant++;
133
                $niveau_courant++;
116
            }
134
            }
117
            for ($i = 0; $i < count($blocks_de_donnees); $i++) {
135
            for ($i = 0; $i < count($blocks_de_donnees); $i++) {
118
                $block = $blocks_de_donnees[$i];
136
                $block = $blocks_de_donnees[$i];
119
                $this->construireParRecursivite($niveau_max, $block->recupererDonnees(), $block->recupererIdentifiant());
137
                $this->construireParRecursivite($niveau_max, $block->recupererDonnees(), $block->recupererIdentifiant());
120
            }
138
            }
121
        }
139
        }
122
    }
140
    }
123
    
141
    
124
    function contruireParRecursivitePlate()
142
    function contruireParRecursivitePlate()
125
    {
143
    {
126
        construire();
144
        construire();
127
        
145
        
128
        $this->$contexteRef = $this->blockdedonnees;
146
        $this->$contexteRef = $this->blockdedonnees;
129
        
147
        
130
        construire();
148
        construire();
131
    }
149
    }
132
    
150
    
133
    function openCursor($sql, $id = null)
151
    function openCursor($sql, $id = null)
134
    {
152
    {
135
        $resultat = mysql_query($sql, $this->connexion);
153
        $resultat = mysql_query($sql, $this->connexion);
136
        if (!$resultat) {
154
        if (!$resultat) {
137
            echo 'Numéro erreur Mysql : '.mysql_errno().'<br />'."\n";
155
            echo 'Numéro erreur Mysql : '.mysql_errno().'<br />'."\n";
138
            echo 'Erreur Mysql : '.mysql_error().'<br />'."\n";
156
            echo 'Erreur Mysql : '.mysql_error().'<br />'."\n";
139
            echo 'Requête : '.'<pre>'.$sql.'</pre>';
157
            echo 'Requête : '.'<pre>'.$sql.'</pre>';
140
        }
158
        }
141
        $this->idRes = $resultat;
159
        $this->idRes = $resultat;
142
        if (is_null($id)) {
160
        if (is_null($id)) {
143
            $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
161
            $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
144
        } else {
162
        } else {
145
            $this->collectionblockdedonnees = new collectionblockdedonnees($id);
163
            $this->collectionblockdedonnees = new collectionblockdedonnees($id);
146
        }
164
        }
147
    }
165
    }
148
    
166
    
149
    function fetch($identifiant = null)
167
    function fetch($identifiant = null)
150
    {
168
    {
151
        $resultat = mysql_fetch_assoc($this->idRes);
169
        $resultat = mysql_fetch_assoc($this->idRes);
152
        if (!$resultat) {
170
        if (!$resultat) {
153
            // Nous ne faisons rien car aucune donnée n'est collectée.
171
            // Nous ne faisons rien car aucune donnée n'est collectée.
154
        } else {
172
        } else {
155
            $this->collectionblockdedonnees->ajouterDonnees($resultat, $identifiant);
173
            $this->collectionblockdedonnees->ajouterDonnees($resultat, $identifiant);
156
        }
174
        }
157
        return $resultat;
175
        return $resultat;
158
    }
176
    }
159
    
177
    
160
    function closeCursor($id = null)
178
    function closeCursor($id = null, $num = null)
161
    {
179
    {
162
        mysql_free_result($this->idRes);
180
        mysql_free_result($this->idRes);
163
        // Nous ajoutons les données de la requêtes seulement si elle a ramenée des données
181
        // Nous ajoutons les données de la requêtes seulement si elle a ramenée des données
164
        if (count($this->collectionblockdedonnees->recupererBlocksDeDonnees()) > 0) {
182
        if (count($this->collectionblockdedonnees->recupererBlocksDeDonnees()) > 0) {
165
            if (is_null($id)) {
183
            if (is_null($id)) {
166
                $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
184
                $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
167
            } else {
185
            } else {
168
                $this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id);
186
                $this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id, $num);
169
            }
187
            }
170
        }
188
        }
171
    }
189
    }
172
}
190
}
173
?>
191
?>