Subversion Repositories eFlore/Archives.eflore-consultation-v2

Rev

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

Rev Author Line No. Line
32 jpm 1
<?php
2
 
27 jpm 3
class macroElement implements iMacroElement{
4
 
80 jpm 5
    protected $identifiantblockdedonnees;
6
    protected $identifiant_parent;
27 jpm 7
    protected $connexion;
80 jpm 8
    protected $contexteRef;
9
    protected $contexteRefTmp;
10
    protected $contexteSQL;
27 jpm 11
    protected $blockdedonneesParent;
12
    protected $collectionblockdedonnees;
13
    protected $idRes;
14
 
80 jpm 15
    function __construct($une_connexion, $un_block_donnees_parent, $chemin_macro_element)
32 jpm 16
    {
36 jpm 17
        $this->connexion = $une_connexion;
80 jpm 18
        $this->blockdedonneesParent = $un_block_donnees_parent;
19
        $tab_etape_chemin = array_reverse(explode('>', $chemin_macro_element));
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 {
26
            $this->identifiant_parent = NULL;
27
            $this->contexteRef = $this->blockdedonneesParent->recupererDonnees();
28
        }
32 jpm 29
    }
80 jpm 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
    }
32 jpm 61
 
80 jpm 62
    function construire()
63
    {
64
        if (is_null($this->identifiant_parent)) {
65
            $sql = $this->getSQL();
66
            if(!is_null($sql)) {
67
                $this->openCursor($sql);
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
            }
82
            //$this->contexteRef = $this->contexteRefTmp;
83
        }
84
        //echo '<pre>'.print_r($this->contexteRef, true).'</pre>';
27 jpm 85
    }
86
 
36 jpm 87
    function contruireParRecursivitePlate()
27 jpm 88
    {
89
        construire();
90
 
91
        $this->$contexteRef = $this->blockdedonnees;
92
 
93
        construire();
94
    }
95
 
36 jpm 96
    function contruireParRecursivite()
27 jpm 97
    {
32 jpm 98
 
27 jpm 99
    }
100
 
80 jpm 101
    function openCursor($sql, $id = null)
27 jpm 102
    {
32 jpm 103
        $res = mysql_query($sql, $this->connexion);
104
        if (!$res) echo mysql_errno().': '.mysql_error()."\n";
105
        $this->idRes = $res;
80 jpm 106
        $this->collectionblockdedonnees = new collectionblockdedonnees($this->identifiantblockdedonnees);
107
        if (is_null($this->identifiant_parent)) {
108
            $this->blockdedonneesParent->ajouterCollectionBlockFils($this->collectionblockdedonnees);
109
        } else {
110
            $this->attribuerCollectionBlockFils($this->blockdedonneesParent, $id);
111
        }
27 jpm 112
    }
113
 
114
    function fetch()
32 jpm 115
    {
36 jpm 116
        $res = mysql_fetch_assoc($this->idRes);
32 jpm 117
        if (!$res) {
118
 
119
        } else {
27 jpm 120
            //$this->blockdedonnees = new blockdedonnees($this->identifiantblockdedonnees);
121
            //$this->blockdedonnees->affecterDonnees($res);
32 jpm 122
            $this->collectionblockdedonnees->ajouterDonnees($res);
27 jpm 123
        }
124
        return $res;
125
    }
126
 
127
    function closeCursor()
128
    {
129
        mysql_free_result($this->idRes);
130
    }
131
}
132
?>