Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

Rev 139 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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