Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

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

Rev 87 Rev 139
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
                return $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 ) {
-
 
47
            return $un_block_donnees->ajouterCollectionBlockFils($this->collectionblockdedonnees);
-
 
48
        } else if (is_array($un_block_donnees->recupererCollectionBlockFils()) AND count($un_block_donnees->recupererCollectionBlockFils()) > 0) {
-
 
49
            $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
-
 
50
            for($i = 0; $i < count($collection_block_fils); $i++) {
-
 
51
                $blocks_de_donnees = $collection_block_fils[$i]->recupererBlocksDeDonnees();
-
 
52
                for ($i = 0; $i < count($blocks_de_donnees); $i++) {
-
 
53
                    $this->attribuerCollectionBlockFils($blocks_de_donnees[$i], $id);
-
 
54
                }
-
 
55
            }
-
 
56
        }
-
 
57
    }
-
 
58
    
-
 
59
    function recupererCollectionBlockFils($un_block_donnees, $id)
-
 
60
    {
46
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
61
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
47
        for($i = 0; $i < count($collection_block_fils); $i++) {
62
        for($i = 0; $i < count($collection_block_fils); $i++) {
48
            $collection = $collection_block_fils[$i];
63
            $une_collection = $collection_block_fils[$i];
49
            if ($collection->recupererIdentifiant() == $this->identifiant_parent) {
64
            if ($une_collection->recupererIdentifiant() == $id ) {
-
 
65
                return $une_collection->recupererBlocksDeDonnees();
-
 
66
            } else {
50
                $blocks_de_donnees = $collection->recupererBlocksDeDonnees();
67
                $blocks_de_donnees = $une_collection->recupererBlocksDeDonnees();
51
                foreach ($blocks_de_donnees as $cle => $val) {
68
                for ($i = 0; $i < count($blocks_de_donnees); $i++) {
52
                    if ($cle == $id) {
69
                    $block = $blocks_de_donnees[$i];
-
 
70
                    if (is_array($block->recupererCollectionBlockFils()) AND count($block->recupererCollectionBlockFils()) > 0) {
53
                        return $blocks_de_donnees[$cle]->ajouterCollectionBlockFils($this->collectionblockdedonnees);
71
                        return $this->recupererCollectionBlockFils($block, $id);
54
                    }
72
                    }
55
                }
73
                }
56
            } else if (is_object($this->blockdedonneesParent->recupererCollectionBlockFils())) {
-
 
57
                return $this->attribuerCollectionBlockFils($un_block_donnees->recupererCollectionBlockFils());
-
 
58
            }
74
            }
59
        }
75
        }
-
 
76
        return null;
60
    }
77
    }
61
    
78
    
62
    function construire()
79
    function construire()
63
    {
80
    {
64
        if (is_null($this->identifiant_parent)) {
81
        if (is_null($this->identifiant_parent)) {
65
            $sql = $this->getSQL();
82
            $sql = $this->getSQL();
66
            if(!is_null($sql)) {
83
            if (!is_null($sql)) {
67
                $this->openCursor($sql);
84
                $this->openCursor($sql);
68
                while ($this->fetch());
85
                while ($this->fetch());
69
                $this->closeCursor();
86
                $this->closeCursor();
70
            }
87
            }
71
        } else {
-
 
72
            $this->contexteRefTmp = $this->contexteRef;
-
 
73
            for($i = 0; $i < count($this->contexteRefTmp); $i++) {
-
 
74
                $this->contexteRef = $this->contexteRefTmp[$i]->recupererDonnees();
-
 
75
                $sql = $this->getSQL();
-
 
76
                if(!is_null($sql)) {
-
 
77
                    $this->openCursor($sql, $i);
-
 
78
                    while ($this->fetch());
-
 
79
                    $this->closeCursor();
-
 
80
                }
-
 
81
            }
-
 
82
            //$this->contexteRef = $this->contexteRefTmp;
-
 
83
        }
88
        }
84
        //echo '<pre>'.print_r($this->contexteRef, true).'</pre>';
-
 
85
    }
89
    }
86
    
90
    
87
    function contruireParRecursivitePlate()
91
    function contruireParRecursivitePlate()
88
    {
92
    {
89
        construire();
93
        construire();
90
        
94
        
91
        $this->$contexteRef = $this->blockdedonnees;
95
        $this->$contexteRef = $this->blockdedonnees;
92
        
96
        
93
        construire();
97
        construire();
94
    }
98
    }
95
    
99
    
96
    function contruireParRecursivite()
100
    function construireParRecursivite($niveau_max, $aso_contexte = null, $id = null)
-
 
101
    {
-
 
102
        static $niveau_courant = 0;
-
 
103
        if ($niveau_courant > $niveau_max) {
-
 
104
            return null;
-
 
105
        }
-
 
106
        
-
 
107
        if (!is_null($aso_contexte)) {
-
 
108
            $this->contexteRef = $aso_contexte;
-
 
109
        }
-
 
110
        if (is_null($id)) {
-
 
111
            $id = $this->identifiantblockdedonnees;
-
 
112
            $this->identifiant_parent = $this->blockdedonneesParent->recupererIdentifiant();
-
 
113
        } else {
-
 
114
            $this->identifiant_parent = $id;
-
 
115
        }
-
 
116
        
-
 
117
        $sql = $this->getSQL();
-
 
118
        //echo '<pre>'.print_r($sql, true).'</pre>';
-
 
119
        if (!is_null($sql)) {
-
 
120
            $this->openCursor($sql, $id);
-
 
121
            for ($i = 0; $this->fetch($id.'-'.$i); $i++);
97
    {
122
            $this->closeCursor($this->identifiant_parent);
-
 
123
            
-
 
124
            $blocks_de_donnees = $this->recupererCollectionBlockFils($this->blockdedonneesParent, $id);
-
 
125
            if (count($blocks_de_donnees) > 0) {
-
 
126
                $niveau_courant++;
-
 
127
            }
-
 
128
            for ($i = 0; $i < count($blocks_de_donnees); $i++) {
-
 
129
                $block = $blocks_de_donnees[$i];
-
 
130
                $this->construireParRecursivite($niveau_max, $block->recupererDonnees(), $block->recupererIdentifiant());
-
 
131
            }
98
        
132
        }
99
    }
133
    }
100
    
134
    
101
    function openCursor($sql, $id = null)
135
    function openCursor($sql, $id = null)
102
    {
136
    {
103
        $res = mysql_query($sql, $this->connexion);
137
        $resultat = mysql_query($sql, $this->connexion);
-
 
138
        if (!$resultat) {
-
 
139
            echo 'Numéro erreur Mysql : '.mysql_errno().'<br />'."\n";
104
        if (!$res) echo mysql_errno().': '.mysql_error()."\n";
140
            echo 'Erreur Mysql : '.mysql_error().'<br />'."\n";
-
 
141
            echo 'Requête : '.'<pre>'.$sql.'</pre>';
-
 
142
        }
105
        $this->idRes = $res;
143
        $this->idRes = $resultat;
106
        $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
-
 
107
        if (is_null($this->identifiant_parent)) {
144
        if (is_null($id)) {
108
            $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
145
            $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
109
        } else {
146
        } else {
110
            $this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id);
147
            $this->collectionblockdedonnees = new collectionblockdedonnees($id);
111
        }
148
        }
112
    }
149
    }
113
    
150
    
114
    function fetch()
151
    function fetch($identifiant = null)
115
    {
152
    {
116
        $res = mysql_fetch_assoc($this->idRes);
153
        $resultat = mysql_fetch_assoc($this->idRes);
117
        if (!$res) {
-
 
-
 
154
        if (!$resultat) {
118
            
155
            // Nous ne faisons rien car aucune donnée n'est collectée.
119
        } else {
-
 
120
            //$this->blockdedonnees = new blockdedonnees($this->identifiantblockdedonnees);
-
 
121
            //$this->blockdedonnees->affecterDonnees($res);
156
        } else {
122
            $this->collectionblockdedonnees->ajouterDonnees($res);
157
            $this->collectionblockdedonnees->ajouterDonnees($resultat, $identifiant);
123
        }
158
        }
124
        return $res;
159
        return $resultat;
125
    }
160
    }
126
    
161
    
127
    function closeCursor()
162
    function closeCursor($id = null)
-
 
163
    {
-
 
164
        mysql_free_result($this->idRes);
-
 
165
        // 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) {
-
 
167
            if (is_null($id)) {
-
 
168
                $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
-
 
169
            } else {
-
 
170
                $this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id);
128
    {
171
            }
129
        mysql_free_result($this->idRes);
172
        }
130
    }
173
    }
131
}
174
}
132
?>
175
?>