Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

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

Rev 36 Rev 80
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 $connexion;
7
    protected $connexion;
-
 
8
    protected $contexteRef;
-
 
9
    protected $contexteRefTmp;
7
    protected $contexteRef;
10
    protected $contexteSQL;
8
    protected $blockdedonneesParent;
11
    protected $blockdedonneesParent;
9
    protected $collectionblockdedonnees;
12
    protected $collectionblockdedonnees;
10
    protected $idRes;
13
    protected $idRes;
11
    
14
    
12
    function __construct($une_connexion, $un_block_données_parent, $identifiant)
15
    function __construct($une_connexion, $un_block_donnees_parent, $chemin_macro_element)
13
    {
16
    {
14
        $this->connexion = $une_connexion;
17
        $this->connexion = $une_connexion;
-
 
18
        $this->blockdedonneesParent = $un_block_donnees_parent;
-
 
19
        $tab_etape_chemin = array_reverse(explode('>', $chemin_macro_element));
15
        $this->blockdedonneesParent = $un_block_donn;
20
        $identifiant = $tab_etape_chemin[0];
-
 
21
        $this->identifiantblockdedonnees = $identifiant;
-
 
22
        if (count($tab_etape_chemin) > 1) {
-
 
23
            $this->identifiant_parent = $tab_etape_chemin[1];
-
 
24
            $this->contexteRef = $this->attribuerContexteRef($this->blockdedonneesParent);
-
 
25
        } else {
16
        $this->identifiantblockdedonnees = $identifiant;
26
            $this->identifiant_parent = NULL;
-
 
27
            $this->contexteRef = $this->blockdedonneesParent->recupererDonnees();
17
        $this->contexteRef = $this->blockdedonneesParent->recupererDonnees();
28
        }
18
    }
29
    }
-
 
30
    
-
 
31
    function attribuerContexteRef($un_block_donnees)
-
 
32
    {
-
 
33
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
-
 
34
        for($i = 0; $i < count($collection_block_fils); $i++) {
-
 
35
            $collection = $collection_block_fils[$i];
-
 
36
            if ($collection->recupererIdentifiant() == $this->identifiant_parent) {
-
 
37
                return $collection->recupererBlocksDeDonnees();
-
 
38
            } else if (is_object($un_block_donnees->recupererCollectionBlockFils())) {
-
 
39
                return $this->attribuerContexteRef($un_block_donnees->recupererCollectionBlockFils());
-
 
40
            }
-
 
41
        }
-
 
42
    }
-
 
43
    
-
 
44
    function attribuerCollectionBlockFils($un_block_donnees, $id)
-
 
45
    {
-
 
46
        $collection_block_fils = $un_block_donnees->recupererCollectionBlockFils();
-
 
47
        for($i = 0; $i < count($collection_block_fils); $i++) {
-
 
48
            $collection = $collection_block_fils[$i];
-
 
49
            if ($collection->recupererIdentifiant() == $this->identifiant_parent) {
-
 
50
                $blocks_de_donnees = $collection->recupererBlocksDeDonnees();
-
 
51
                foreach ($blocks_de_donnees as $cle => $val) {
-
 
52
                    if ($cle == $id) {
-
 
53
                        return $blocks_de_donnees[$cle]->ajouterCollectionBlockFils($this->collectionblockdedonnees);
-
 
54
                    }
-
 
55
                }
-
 
56
            } else if (is_object($this->blockdedonneesParent->recupererCollectionBlockFils())) {
-
 
57
                return $this->attribuerCollectionBlockFils($un_block_donnees->recupererCollectionBlockFils());
-
 
58
            }
-
 
59
        }
-
 
60
    }
19
    
61
    
20
    function construire() 
62
    function construire()
-
 
63
    {
21
    {
64
        if (is_null($this->identifiant_parent)) {
22
        $sql = $this->getSQL();
65
            $sql = $this->getSQL();
23
        if(!is_null($sql)) {
66
            if(!is_null($sql)) {
24
            $this->openCursor($sql);
67
                $this->openCursor($sql);
25
            while ($this->fetch());
68
                while ($this->fetch());
-
 
69
                $this->closeCursor();
-
 
70
            }
-
 
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
            }
26
            $this->closeCursor();
82
            //$this->contexteRef = $this->contexteRefTmp;
-
 
83
        }
27
        }
84
        //echo '<pre>'.print_r($this->contexteRef, true).'</pre>';
28
    }
85
    }
29
    
86
    
30
    function contruireParRecursivitePlate()
87
    function contruireParRecursivitePlate()
31
    {
88
    {
32
        construire();
89
        construire();
33
        
90
        
34
        $this->$contexteRef = $this->blockdedonnees;
91
        $this->$contexteRef = $this->blockdedonnees;
35
        
92
        
36
        construire();
93
        construire();
37
    }
94
    }
38
    
95
    
39
    function contruireParRecursivite()
96
    function contruireParRecursivite()
40
    {
97
    {
41
        
98
        
42
    }
99
    }
43
    
100
    
44
    function openCursor($sql)
101
    function openCursor($sql, $id = null)
45
    {
102
    {
46
        $res = mysql_query($sql, $this->connexion);
103
        $res = mysql_query($sql, $this->connexion);
47
        if (!$res) echo mysql_errno().': '.mysql_error()."\n";
104
        if (!$res) echo mysql_errno().': '.mysql_error()."\n";
48
        $this->idRes = $res;
105
        $this->idRes = $res;
49
        $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
106
        $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
-
 
107
        if (is_null($this->identifiant_parent)) {
50
        $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
108
            $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
-
 
109
        } else {
-
 
110
            $this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id);
-
 
111
        }
51
    }
112
    }
52
    
113
    
53
    function fetch()
114
    function fetch()
54
    {
115
    {
55
        $res = mysql_fetch_assoc($this->idRes);
116
        $res = mysql_fetch_assoc($this->idRes);
56
        if (!$res) {
117
        if (!$res) {
57
            
118
            
58
        } else {
119
        } else {
59
            //$this->blockdedonnees = new blockdedonnees($this->identifiantblockdedonnees);
120
            //$this->blockdedonnees = new blockdedonnees($this->identifiantblockdedonnees);
60
            //$this->blockdedonnees->affecterDonnees($res);
121
            //$this->blockdedonnees->affecterDonnees($res);
61
            $this->collectionblockdedonnees->ajouterDonnees($res);
122
            $this->collectionblockdedonnees->ajouterDonnees($res);
62
        }
123
        }
63
        return $res;
124
        return $res;
64
    }
125
    }
65
    
126
    
66
    function closeCursor()
127
    function closeCursor()
67
    {
128
    {
68
        mysql_free_result($this->idRes);
129
        mysql_free_result($this->idRes);
69
    }
130
    }
70
}
131
}
71
?>
132
?>